:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-alt: #f0f1f3;
  --border: #e2e3e7;
  --text: #1c1d20;
  --text-muted: #6b6f76;
  --accent: #4f6df5;
  --accent-soft: #eaeeff;
  --best: #1f9d55;
  --best-soft: #e8f9ef;
  --bar: #4f6df5;
  --danger: #e0455a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.06), 0 4px 16px rgba(20, 20, 30, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --surface: #1f2025;
    --surface-alt: #26272d;
    --border: #33343b;
    --text: #eceef2;
    --text-muted: #9a9ca4;
    --accent: #7b93ff;
    --accent-soft: #262c47;
    --best: #3ecb7e;
    --best-soft: #16321f;
    --bar: #7b93ff;
    --danger: #ff6b7f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 20px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 32px 16px 64px;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

.app {
  max-width: 640px;
  margin: 0 auto;
}

.app-header h1 {
  font-size: 1.6rem;
  margin: 0 0 4px;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 14px;
}

.option-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.option-row.is-best {
  border-color: var(--best);
  box-shadow: 0 0 0 3px var(--best-soft), var(--shadow);
}

.option-row-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.option-name {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  padding: 4px 2px;
  min-width: 0;
}
.option-name:focus { outline: none; }
.option-name::placeholder { color: var(--text-muted); font-weight: 500; }

.remove-btn {
  border: none;
  background: var(--surface-alt);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.remove-btn:hover { background: var(--danger); color: #fff; }

.option-row-fields {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}

.option-row-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.option-row-fields input {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.95rem;
  color: var(--text);
  width: 100%;
  min-width: 0;
}
.option-row-fields input:focus {
  outline: none;
  border-color: var(--accent);
}

.calc-hint {
  display: block;
  min-height: 14px;
  font-size: 0.72rem;
  color: var(--accent);
  margin-top: 2px;
}

.unit-price-display {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: right;
  min-width: 84px;
}

.unit-price-value {
  font-size: 1rem;
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.is-best .unit-price-value { color: var(--best); }

.add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 12px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.add-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.plus { font-size: 1.1rem; line-height: 1; }

.results {
  margin-top: 28px;
}

.best-banner {
  background: var(--best-soft);
  border: 1px solid var(--best);
  color: var(--best);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 20px;
}
.best-banner strong { font-weight: 800; }

.chart {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chart-row {
  display: grid;
  grid-template-columns: 100px 1fr 76px;
  align-items: center;
  gap: 10px;
}

.chart-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-track {
  background: var(--surface-alt);
  border-radius: 6px;
  height: 22px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.chart-bar {
  height: 100%;
  background: var(--bar);
  border-radius: 6px 0 0 6px;
  transition: width 0.3s ease;
}

.chart-row.is-best .chart-bar { background: var(--best); }

.chart-value {
  font-size: 0.85rem;
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

.chart-row.is-best .chart-value { color: var(--best); }

@media (max-width: 420px) {
  .option-row-fields {
    grid-template-columns: 1fr 1fr;
  }
  .unit-price-display {
    grid-column: 1 / -1;
    flex-direction: row;
    justify-content: space-between;
    text-align: left;
  }
  .chart-row {
    grid-template-columns: 76px 1fr 64px;
  }
}
