:root {
  color-scheme: light;
  --bg: #eef2f7;
  --panel: #ffffff;
  --line: #d6dee8;
  --text: #183046;
  --muted: #61778c;
  --primary: #0e7490;
  --primary-strong: #155e75;
  --danger: #b91c1c;
  --danger-strong: #991b1b;
  --selected: #cffafe;
  --selected-text: #082f49;
  --tab-bg: #f8fafc;
  --tab-done-bg: #ecfeff;
  --tab-active-bg: #083344;
  --tab-active-text: #ecfeff;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.theme-dark {
  color-scheme: dark;
  --bg: #0b1220;
  --panel: #111b2e;
  --line: #2a3b57;
  --text: #e6edf7;
  --muted: #9ab0c9;
  --primary: #22c1dc;
  --primary-strong: #1aa1b9;
  --danger: #ef4444;
  --danger-strong: #dc2626;
  --selected: #14364f;
  --selected-text: #f3fbff;
  --tab-bg: #152235;
  --tab-done-bg: #113246;
  --tab-active-bg: #1f6f8b;
  --tab-active-text: #ffffff;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); }
body.modal-open { overflow: hidden; }
button, textarea, input { font: inherit; }
button {
  border: 0; border-radius: 18px; padding: 1.1rem 1.2rem; font-weight: 800; cursor: pointer;
  transition: transform 0.08s ease, background 0.2s ease, color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}
button:active { transform: scale(0.985); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.primary { background: var(--primary); color: white; }
.primary:hover { background: var(--primary-strong); }
.secondary { background: #dbeafe; color: #1d4ed8; }
body.theme-dark .secondary { background: #18314f; color: #b9dcff; }
.danger { background: var(--danger); color: white; }
.danger:hover { background: var(--danger-strong); }
.ghost { border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.hidden { display: none !important; }

.app-shell { max-width: 1520px; margin: 0 auto; padding: 1rem; }
.topbar { display: flex; justify-content: space-between; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.topbar h1, .panel h2, .section-group h3, .section-panel h2, .modal-card h2 { margin: 0; }
.brand-row { display: flex; align-items: center; gap: 0.9rem; }
.brand-logo {
  width: 3rem;
  height: 3rem;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--tab-done-bg) 60%, var(--panel) 40%);
  color: var(--primary-strong);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35);
}
body.theme-dark .brand-logo { color: #7be5f5; }
.brand-logo svg { width: 2rem; height: 2rem; }
.eyebrow { margin: 0 0 0.25rem; font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.topbar-actions, .section-nav-actions, .modal-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.layout { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(340px, 1fr); gap: 1rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 1rem; box-shadow: var(--shadow); }
.panel-subsection + .panel-subsection, .section-group + .section-group, .option-children { margin-top: 1rem; }
.status-banner { margin-bottom: 1rem; padding: 0.9rem 1rem; border-radius: 16px; background: #fff7ed; color: #9a3412; border: 1px solid #fdba74; }
body.theme-dark .status-banner { background: #402313; color: #ffd2ad; border-color: #b8622b; }

.section-nav {
  display: grid;
  gap: 0.9rem;
  position: sticky;
  top: 0.75rem;
  z-index: 20;
  background: color-mix(in srgb, var(--panel) 94%, transparent 6%);
  backdrop-filter: blur(10px);
}
.section-tabs { display: grid; gap: 0.8rem; }
.main-tabs { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.sub-tabs { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.section-tab {
  min-height: 88px;
  background: var(--tab-bg);
  color: var(--text) !important;
  border: 2px solid var(--line);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.25;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: 0 2px 0 rgba(0,0,0,0.05);
}
.tab-label {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-wrap: balance;
}
.section-tab:hover { box-shadow: 0 8px 20px rgba(0,0,0,0.08); }
.section-tab.done {
  background: linear-gradient(180deg, var(--tab-done-bg), color-mix(in srgb, var(--tab-done-bg) 70%, var(--panel) 30%));
  color: var(--text) !important;
  border-color: #67e8f9;
}
.section-tab.active {
  background: linear-gradient(180deg, var(--tab-active-bg), color-mix(in srgb, var(--tab-active-bg) 78%, black 22%));
  color: var(--tab-active-text) !important;
  border-color: #67e8f9;
  box-shadow: 0 0 0 2px rgba(103, 232, 249, 0.25);
}
.section-tab.active.done { color: var(--tab-active-text) !important; }
.section-tab-main { font-size: 1rem; }
.sub-section-tab { min-height: 74px; font-size: 0.96rem; }

.section-panel > p { color: var(--muted); }
.section-group { border: 1px solid var(--line); border-radius: 20px; padding: 1rem; background: color-mix(in srgb, var(--panel) 92%, white 8%); }
body.theme-dark .section-group { background: #101a2b; }
.group-label { margin-bottom: 0.75rem; }
.group-mode { color: var(--muted); font-size: 0.92rem; margin-top: 0.25rem; }
.option-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.9rem; }
.option-card {
  min-height: 118px; text-align: left; background: var(--tab-bg); color: var(--text);
  border: 2px solid var(--line); padding: 1.15rem;
}
.option-card.selected {
  background: var(--selected); color: var(--selected-text); border-color: #06b6d4;
  box-shadow: inset 0 0 0 1px rgba(8, 47, 73, 0.08), 0 8px 20px rgba(6, 182, 212, 0.08);
}
.option-card.selected strong, .option-card.selected small { color: var(--selected-text); }
.option-card strong { display: block; font-size: 1.03rem; line-height: 1.25; }
.option-card small { display: block; margin-top: 0.45rem; color: var(--muted); font-weight: 600; line-height: 1.35; }
.option-children { border-left: 4px solid #38bdf8; padding-left: 1rem; }

.field-list { display: grid; gap: 0.75rem; }
.field-list label { display: grid; gap: 0.4rem; font-weight: 700; }
.field-list textarea, #output, .inline-input-card input {
  width: 100%; min-height: 96px; padding: 0.85rem 0.9rem; border-radius: 16px;
  border: 1px solid var(--line); resize: vertical; background: var(--tab-bg); color: var(--text);
}
.field-list textarea:focus, .inline-input-card input:focus, button:focus-visible {
  outline: 2px solid rgba(34, 193, 220, 0.42);
  outline-offset: 2px;
}
.inline-input-card {
  margin-top: 0.9rem;
  padding: 0.85rem;
  border: 1px dashed #67e8f9;
  border-radius: 18px;
  background: color-mix(in srgb, var(--tab-done-bg) 42%, var(--panel) 58%);
}
.inline-input-card label {
  display: grid;
  gap: 0.45rem;
  font-weight: 700;
}
.inline-input-card input {
  min-height: auto;
  resize: none;
}
.output-panel { display: flex; flex-direction: column; gap: 0.75rem; position: sticky; top: 1rem; max-height: calc(100vh - 2rem); }
.output-header { display: flex; justify-content: space-between; gap: 0.75rem; align-items: center; }
#output { min-height: 520px; flex: 1; border-radius: 18px; }
.hint { margin: 0; color: var(--muted); font-size: 0.95rem; }
.calculator-summary { background: linear-gradient(180deg, color-mix(in srgb, var(--selected) 45%, var(--panel) 55%), var(--panel)); }
.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  padding: 0.9rem 1.1rem;
  border-radius: 16px;
  font-size: 1.05rem;
  font-weight: 900;
  background: color-mix(in srgb, var(--tab-active-bg) 18%, var(--panel) 82%);
  border: 2px solid #67e8f9;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(8, 15, 27, 0.58);
  backdrop-filter: blur(8px);
}
.modal-card {
  width: min(100%, 32rem);
  padding: 1.25rem;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.modal-card p {
  margin: 0.9rem 0 0;
  color: var(--muted);
  line-height: 1.45;
}
.modal-actions {
  margin-top: 1.25rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.modal-button {
  min-height: 72px;
  font-size: 1rem;
}

@media (max-width: 1280px) {
  .main-tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sub-tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .option-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .output-panel, .section-nav { position: static; max-height: none; }
}
@media (max-width: 640px) {
  .app-shell { padding: 0.75rem; }
  .topbar, .output-header, .section-nav-actions { flex-direction: column; align-items: stretch; }
  .topbar-actions, .output-header, .section-nav-actions, .modal-actions { flex-direction: column; grid-template-columns: 1fr; }
  .topbar-actions button, .output-header button, .section-nav-actions button, .modal-button { width: 100%; }
  .section-tabs, .main-tabs, .sub-tabs, .option-grid { grid-template-columns: 1fr; }
  .section-tab { min-height: 76px; }
  .sub-section-tab { min-height: 68px; }
  .option-card { min-height: 102px; }
  #output { min-height: 320px; }
}
