*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Design tokens ─────────────────────────────── */
:root {
  --accent:       #1d4ed8;
  --accent-hover: #1e40af;
  --accent-soft:  #eff4ff;
  --accent-text:  #ffffff;

  --bg:        #f6f7f9;
  --card:      #ffffff;
  --fill:      #f1f3f6;
  --border:    #e3e6eb;
  --border-2:  #cdd2da;
  --text:      #111827;
  --text-2:    #374151;
  --muted:     #6b7280;
  --danger:    #b91c1c;
  --danger-bg: #fef2f2;
  --good:      #15803d;

  --fs-xs: .75rem;
  --fs-s:  .8125rem;
  --fs-m:  .9375rem;
  --fs-l:  1.25rem;
  --fs-xl: 1.625rem;

  --r: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}

[data-theme="dark"] {
  --accent:       #6c9bff;
  --accent-hover: #8bb0ff;
  --accent-soft:  rgba(108, 155, 255, .12);
  --accent-text:  #0b1220;

  --bg:        #0e1117;
  --card:      #161b24;
  --fill:      #1d2330;
  --border:    #262d3a;
  --border-2:  #364055;
  --text:      #f3f4f6;
  --text-2:    #d1d5db;
  --muted:     #9ca3af;
  --danger:    #f87171;
  --danger-bg: rgba(248, 113, 113, .1);
  --good:      #4ade80;
  --shadow: none;
}
[data-theme="dark"] body { color-scheme: dark; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-m);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }

/* ── Header ────────────────────────────────────── */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 32px; height: 56px;
  background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.brand-name {
  font-weight: 700; font-size: var(--fs-m); letter-spacing: -.01em;
  color: var(--text); text-decoration: none;
}
.btn-ghost {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; font-size: var(--fs-s); color: var(--text-2);
}
.btn-ghost:hover { background: var(--fill); }

.app-main { max-width: 1280px; margin: 0 auto; padding: 32px 32px 48px; }
#stepper-wrap { max-width: 680px; margin: 0 auto; }

/* ── Buttons ───────────────────────────────────── */
.btn-primary, .btn-secondary {
  border-radius: 8px; padding: 9px 18px; font-weight: 600; font-size: var(--fs-m);
  border: 1px solid transparent; transition: background .15s, border-color .15s;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .55; }
.btn-secondary { background: var(--card); color: var(--text-2); border-color: var(--border-2); }
.btn-secondary:hover { background: var(--fill); }
.btn-secondary[hidden], .btn-primary[hidden] { display: none; }

/* ── Stepper ───────────────────────────────────── */
.stepper-list {
  list-style: none; display: flex; gap: 8px; margin-bottom: 24px;
}
.stepper-list li { flex: 1; }
.step-dot {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: none; border: 0;
  border-bottom: 2px solid var(--border); border-radius: 0;
  color: var(--muted); font-size: var(--fs-s); font-weight: 600; text-align: left;
}
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--fill); font-size: var(--fs-xs);
}
.step-dot.is-done { color: var(--text-2); border-bottom-color: var(--border-2); }
.step-dot.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.step-dot.is-active .step-num { background: var(--accent); color: var(--accent-text); }

.step-panel {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r);
  box-shadow: var(--shadow); padding: 28px;
}
.step-panel[hidden] { display: none; }
.step-title { font-size: var(--fs-l); font-weight: 700; letter-spacing: -.015em; }
.step-hint { color: var(--muted); font-size: var(--fs-s); margin: 4px 0 20px; }
.count-hint { margin: 12px 0 0; }

.step-nav { display: flex; justify-content: space-between; margin-top: 20px; }
.step-nav .btn-primary { margin-left: auto; }

.form-error {
  margin-top: 16px; padding: 12px 14px; border-radius: 8px;
  background: var(--danger-bg); color: var(--danger); font-size: var(--fs-s);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
}
.form-error[hidden] { display: none; }
.suggestion-pill {
  margin: 4px 6px 0 0; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border-2); background: var(--card); font-size: var(--fs-s);
}
.suggestion-pill:hover { background: var(--fill); }

/* ── Inputs ────────────────────────────────────── */
input[type="text"], select, textarea {
  width: 100%; padding: 9px 12px; background: var(--card);
  border: 1px solid var(--border-2); border-radius: 8px;
}
input[type="text"]:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-color: var(--accent);
}
textarea { resize: vertical; }
.field { display: flex; flex-direction: column; gap: 6px; margin-top: 20px; }
.field label, .field-label { font-size: var(--fs-s); font-weight: 600; color: var(--text-2); }
.field .optional { color: var(--muted); font-weight: 400; }
.field-help { font-size: var(--fs-s); color: var(--muted); margin-bottom: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .field { margin-top: 0; }
.toggle-row { display: flex; align-items: center; gap: 10px; margin-top: 20px; cursor: pointer; }
.toggle-row input { width: 16px; height: 16px; accent-color: var(--accent); }

/* Autocomplete + chips */
.autocomplete { position: relative; }
.suggestions {
  list-style: none; position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20;
  background: var(--card); border: 1px solid var(--border-2); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .12); max-height: 300px; overflow-y: auto;
}
.suggestions[hidden] { display: none; }
.suggestion { display: flex; gap: 12px; padding: 9px 12px; cursor: pointer; }
.suggestion.is-active, .suggestion:hover { background: var(--accent-soft); }
.sug-code { font-weight: 600; white-space: nowrap; }
.sug-title { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggestion-empty { padding: 10px 12px; color: var(--muted); font-size: var(--fs-s); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  padding: 6px 6px 6px 12px; background: var(--fill);
  border: 1px solid var(--border); border-radius: 8px; font-size: var(--fs-s);
}
.chip-main { display: flex; gap: 8px; min-width: 0; }
.chip-code { font-weight: 600; white-space: nowrap; }
.chip-title { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.chip-remove {
  width: 22px; height: 22px; border: 0; border-radius: 6px; background: none;
  color: var(--muted); font-size: 16px; line-height: 1;
}
.chip-remove:hover { background: var(--border); color: var(--text); }

/* Preferences */
.pref-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.pref-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  background: var(--card); border: 1px solid var(--border-2); border-radius: 10px;
  cursor: grab;
}
.pref-item.dragging { opacity: .5; }
.pref-item.drag-over { border-color: var(--accent); background: var(--accent-soft); }
.pref-rank {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: var(--fs-s);
}
.pref-grip { color: var(--muted); font-size: 18px; flex: none; }
.pref-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.pref-label { font-weight: 600; }
.pref-desc { font-size: var(--fs-s); color: var(--muted); }
.pref-btns { display: flex; flex-direction: column; gap: 2px; flex: none; }
.pref-btn {
  width: 26px; height: 18px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--fill); color: var(--text-2); font-size: 9px; line-height: 1;
}
.pref-btn:hover:not(:disabled) { background: var(--border); }
.pref-btn:disabled { opacity: .35; }

.days-off { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--border); }
.days-off legend { font-weight: 600; font-size: var(--fs-m); margin-bottom: 2px; }
.days-off fieldset { border: 0; }
.weekday-options { display: flex; flex-wrap: wrap; gap: 8px; }
.weekday-options label {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px;
  border: 1px solid var(--border-2); border-radius: 999px; cursor: pointer;
  font-size: var(--fs-s); font-weight: 500; user-select: none;
}
.weekday-options label:has(input:checked) {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent);
}
.weekday-options label.is-disabled {
  opacity: .45; cursor: not-allowed; color: var(--muted);
}
.weekday-options input { accent-color: var(--accent); }

/* ── Cards ─────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r);
  box-shadow: var(--shadow); padding: 20px 24px;
}
.card-flush { padding: 0; overflow: hidden; }
.card-title { font-size: var(--fs-m); font-weight: 700; letter-spacing: -.01em; }

/* ── Results ───────────────────────────────────── */
.results-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 20px;
}
.page-title { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -.02em; }
.results-actions { display: flex; gap: 8px; }
.results-actions .btn-secondary { padding: 7px 14px; font-size: var(--fs-s); }

.notice {
  padding: 10px 14px; margin-bottom: 8px; border-radius: 8px;
  font-size: var(--fs-s); background: var(--fill); border: 1px solid var(--border);
}
.notice-assumption { background: var(--accent-soft); border-color: transparent; }

.option-tabs { display: flex; gap: 8px; margin: 16px 0; flex-wrap: wrap; }
.option-tab {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0;
  padding: 8px 18px; min-width: 130px; text-align: left;
  background: var(--card); border: 1px solid var(--border-2); border-radius: 8px;
}
.option-tab-name { font-weight: 600; font-size: var(--fs-m); }
.option-tab-score { font-size: var(--fs-xs); color: var(--muted); }
.option-tab:hover { background: var(--fill); }
.option-tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); }
.option-tab[aria-selected="true"] .option-tab-name { color: var(--accent-text); }
.option-tab[aria-selected="true"] .option-tab-score { color: var(--accent-text); opacity: .8; }

.option-panel { display: none; }
.option-panel.is-active { display: block; }
.option-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start;
}
.option-main { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.option-side { position: sticky; top: 80px; }
.option-side .card { padding: 24px; }

.score-toggle {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 0; background: none; border: 0; text-align: left; color: inherit;
}
.score-row { display: flex; align-items: baseline; gap: 8px; margin: 0; flex: 1; }
.score-value { font-size: 2.25rem; font-weight: 700; letter-spacing: -.03em; line-height: 1; color: var(--accent); }
.score-label { font-size: var(--fs-s); color: var(--muted); }
.score-chevron {
  flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  font-size: var(--fs-m); font-weight: 700; line-height: 1;
  transition: transform .15s ease;
}
.score-toggle:hover .score-chevron { background: var(--accent-hover); }
.score-card.is-open .score-chevron { transform: rotate(180deg); }
.score-details { margin-top: 16px; }
.explanation { color: var(--text-2); font-size: var(--fs-s); line-height: 1.65; }

.stat-list { margin-top: 20px; border-top: 1px solid var(--border); }
.stat-row {
  display: flex; justify-content: space-between; padding: 9px 0;
  border-bottom: 1px solid var(--border); font-size: var(--fs-s);
}
.stat-row:last-child { border-bottom: 0; padding-bottom: 0; }
.stat-row dt { color: var(--muted); }
.stat-row dd { font-weight: 600; }

/* ── Calendar ──────────────────────────────────── */
.cal-scroller { overflow-x: auto; }
.cal-grid { display: grid; min-width: 100%; }
.cal-corner, .cal-day-head {
  background: var(--fill); border-bottom: 1px solid var(--border);
  padding: 10px 0; text-align: center; font-size: var(--fs-s); font-weight: 600; color: var(--text-2);
}
.cal-day-head { border-left: 1px solid var(--border); }
.cal-times { position: relative; }
.cal-hour {
  height: 60px; padding: 4px 8px 0 0; text-align: right;
  font-size: var(--fs-xs); color: var(--muted);
}
.cal-day-col {
  position: relative; border-left: 1px solid var(--border);
  background-image: linear-gradient(to bottom, var(--border) 1px, transparent 1px);
  background-size: 100% 60px;
}
.cal-block {
  position: absolute; left: 4px; right: 4px; padding: 5px 8px; overflow: hidden;
  border-radius: 6px; color: #111827; border-left: 3px solid rgba(0, 0, 0, .25);
  font-size: var(--fs-xs); line-height: 1.3;
}
.cal-block-code { font-weight: 700; font-size: var(--fs-s); }
.cal-block-time, .cal-block-loc { opacity: .75; }
.cal-empty { padding: 40px; text-align: center; color: var(--muted); }

/* ── Ease section ──────────────────────────────── */
.ease-section { padding: 28px; }
.ease-head { display: flex; align-items: center; gap: 20px; margin-bottom: 16px; }
.ease-score {
  display: flex; align-items: baseline; gap: 4px; padding: 10px 18px;
  background: var(--accent-soft); border-radius: 10px;
}
.ease-score-num { font-size: 2.5rem; font-weight: 700; line-height: 1; color: var(--accent); letter-spacing: -.03em; }
.ease-score-max { font-size: var(--fs-s); color: var(--muted); }
.ease-verdict { color: var(--muted); font-size: var(--fs-s); }
.ease-bar { height: 8px; border-radius: 999px; background: var(--fill); overflow: hidden; }
.ease-bar-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.ease-formula-toggle {
  margin-top: 16px; padding: 0; background: none; border: 0;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-s); color: var(--accent); text-decoration: none;
}
.ease-formula-toggle:hover { text-decoration: underline; }
.ease-formula-chevron { transition: transform .15s ease; }
.ease-formula-toggle.is-open .ease-formula-chevron { transform: rotate(180deg); }
.ease-formula-text {
  margin-top: 12px; padding: 12px 14px; background: var(--fill); border-radius: 8px;
  font-size: var(--fs-s); color: var(--text-2); line-height: 1.65;
}
.ease-breakdown-footer { margin-top: 16px; font-size: var(--fs-xs); color: var(--muted); }

.prof-list { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }
.prof-item {
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.prof-empty { padding: 14px 16px; color: var(--muted); font-size: var(--fs-s); }
.prof-toggle {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: none; border: 0; text-align: left; color: inherit;
}
.prof-toggle:hover { background: var(--fill); }
.prof-summary { display: flex; align-items: baseline; gap: 16px; flex: 1; min-width: 0; }
.prof-course { flex: 0 0 auto; font-weight: 700; font-size: var(--fs-s); }
.prof-name {
  flex: 1 1 auto; min-width: 0; font-size: var(--fs-s); color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.prof-rating { flex: 0 0 auto; font-weight: 700; font-size: var(--fs-s); color: var(--accent); }
.prof-chevron { flex: 0 0 auto; color: var(--muted); font-size: var(--fs-xs); transition: transform .15s ease; }
.prof-item.is-open .prof-chevron { transform: rotate(180deg); }
.prof-details {
  display: flex; flex-direction: column; gap: 8px; padding: 4px 14px 14px;
}
.prof-details[hidden] { display: none; }
.prof-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 4px 16px; }
.prof-stat { display: flex; flex-direction: column; font-size: var(--fs-xs); }
.prof-stat-label { color: var(--muted); }
.prof-stat-value { font-weight: 600; font-size: var(--fs-s); }
.prof-limited, .prof-none { font-size: var(--fs-xs); color: var(--muted); }
.prof-link { font-size: var(--fs-xs); color: var(--accent); text-decoration: none; }
.prof-link:hover { text-decoration: underline; }

/* ── Online list ───────────────────────────────── */
.async-list { display: flex; flex-direction: column; margin-top: 8px; }
.async-item { padding: 10px 0; border-top: 1px solid var(--border); }
.async-item:first-child { border-top: 0; }
.async-main { font-weight: 600; }
.async-sub { font-size: var(--fs-s); color: var(--muted); }

/* ── No schedule ───────────────────────────────── */
#no-schedule-wrap { max-width: 680px; margin: 0 auto; }
#no-schedule-wrap .card { padding: 28px; }
.bottleneck { margin: 16px 0 24px; display: flex; flex-direction: column; gap: 12px; }
.bottleneck-item { font-size: var(--fs-m); }
.bottleneck-suggest { background: var(--fill); border-radius: 8px; padding: 16px 20px; }
.bottleneck-suggest ul { margin: 8px 0 0 20px; }
.no-schedule-actions { justify-content: flex-start; gap: 8px; }
.no-schedule-actions .btn-primary { margin-left: 0; }

.footer-disclaimer {
  margin-top: 40px; text-align: center; font-size: var(--fs-xs); color: var(--muted);
}

/* ── Envelopes ─────────────────────────────────── */
.envelope-picker {
  margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border);
}
.envelope-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; padding: 0; margin-bottom: 10px;
  background: none; border: 0; color: var(--text); text-align: left; cursor: pointer;
}
.envelope-toggle .field-label { margin: 0; }
.envelope-toggle-caret {
  color: var(--accent); font-size: var(--fs-s); transition: transform .15s ease;
}
.envelope-toggle[aria-expanded="true"] .envelope-toggle-caret { transform: rotate(180deg); }
.envelope-panel { margin-bottom: 10px; }
.envelope-panel[hidden] { display: none; }
.envelope-hint { margin: 0 0 10px; }

.envelope-chip {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 6px 6px 6px 12px; background: var(--accent-soft);
  border: 1px solid var(--accent); border-radius: 8px; font-size: var(--fs-s);
}
.envelope-chip-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 0; padding: 0; color: var(--text); font-size: var(--fs-s);
}
.envelope-chip-caret { color: var(--accent); font-size: var(--fs-xs); transition: transform .15s ease; }
.envelope-chip.is-open .envelope-chip-caret { transform: rotate(180deg); }
.envelope-chip-body {
  flex-basis: 100%; padding: 6px 4px 2px 0; color: var(--text-2); font-size: var(--fs-xs);
}
.envelope-chip-body[hidden] { display: none; }
.envelope-chip-courses { line-height: 1.5; }

.cal-block-badge {
  display: inline-block; margin-top: 2px;
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em;
  color: #1748a6;
}

.envelope-notice { margin-bottom: 0; }
.envelope-notice .card-title { margin-bottom: 12px; }
.envelope-notice-block { padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.envelope-notice-block:last-of-type { padding-bottom: 0; margin-bottom: 0; border-bottom: 0; }
.envelope-notice-title { font-weight: 700; font-size: var(--fs-m); }
.envelope-notice-rule { color: var(--text-2); font-size: var(--fs-s); margin: 4px 0 8px; }
.envelope-notice-list { margin: 0 0 8px 20px; font-size: var(--fs-s); }
.envelope-notice-meta { font-size: var(--fs-xs); color: var(--muted); }
.envelope-notice-disclaimer {
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border);
  font-size: var(--fs-xs); color: var(--muted);
}

/* ── Responsive ────────────────────────────────── */
@media (max-width: 960px) {
  .option-layout { grid-template-columns: 1fr; }
  .option-side { position: static; order: -1; }
}
@media (max-width: 600px) {
  .app-main { padding: 20px 16px 40px; }
  .app-header { padding: 0 16px; }
  .step-panel { padding: 20px; }
  .form-grid { grid-template-columns: 1fr; }
  .step-dot { font-size: var(--fs-xs); padding: 8px 4px; }
}
