:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #667381;
  --line: #dfe5eb;
  --panel: #ffffff;
  --panel-soft: #f7f9fb;
  --road: #26313d;
  --teal: #157f7a;
  --yellow: #f2b84b;
  --red: #c84f4f;
  --green: #3b8b5a;
  --blue: #3468a3;
  --shadow: 0 18px 50px rgba(30, 45, 60, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.92), rgba(255,255,255,0.82)),
    url("assets/road-study.svg") center / cover fixed;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: calc(24px + env(safe-area-inset-top)) 18px 24px;
  color: #f8fafc;
  background: var(--road);
  border-right: 1px solid rgba(255,255,255,0.1);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: #f8fafc;
}

.brand-mark span {
  width: 28px;
  height: 16px;
  border: 4px solid var(--teal);
  border-top: 0;
  border-radius: 0 0 20px 20px;
  position: relative;
}

.brand-mark span::before,
.brand-mark span::after {
  content: "";
  position: absolute;
  bottom: -10px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--yellow);
}

.brand-mark span::before {
  left: -6px;
}

.brand-mark span::after {
  right: -6px;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
}

.brand p {
  margin-top: 3px;
  color: #b9c4cf;
  font-size: 13px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 12px;
  color: #dfe7ee;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.nav-tab:hover,
.nav-tab.active {
  color: #fff;
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.14);
}

.icon {
  display: inline-grid;
  place-items: center;
  width: 22px;
  color: var(--yellow);
}

.side-panel {
  display: grid;
  gap: 10px;
  margin-top: 26px;
}

.metric {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
}

.metric span {
  color: #c7d2dc;
  font-size: 13px;
}

.metric strong {
  font-size: 20px;
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.eyebrow {
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar h2 {
  margin-top: 4px;
  font-size: 28px;
}

.top-actions,
.button-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button,
.ghost-text-button {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 700;
}

.primary-button {
  color: #fff;
  background: var(--teal);
}

.secondary-button {
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.danger-button {
  color: #fff;
  background: var(--red);
}

.ghost-button {
  width: 44px;
  padding: 0;
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
}

.ghost-text-button {
  color: var(--teal);
  background: transparent;
  border-color: var(--line);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  align-items: start;
}

.question-area,
.workspace-panel,
.bank-view,
.settings-view {
  min-width: 0;
}

.status-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  color: #fff;
  background: var(--blue);
  font-size: 13px;
  font-weight: 700;
}

.pill.muted {
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
}

.question-card,
.panel-section,
.settings-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,0.96);
  box-shadow: var(--shadow);
}

.question-card {
  padding: 22px;
}

.question-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.question-head p {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: var(--yellow);
  background: #fff;
  border: 1px solid var(--line);
  font-size: 24px;
}

.question-card h3 {
  margin: 16px 0;
  font-size: 24px;
  line-height: 1.42;
}

.media-frame {
  overflow: hidden;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.media-frame img {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: contain;
}

.options {
  display: grid;
  gap: 10px;
}

.option-button {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 54px;
  padding: 9px 12px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.option-button:hover {
  border-color: var(--teal);
}

.option-key {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--teal);
  background: #e7f4f2;
  font-weight: 800;
}

.option-button.correct {
  border-color: rgba(59,139,90,0.7);
  background: #edf7f1;
}

.option-button.selected {
  border-color: rgba(21,127,122,0.7);
  background: #e7f4f2;
}

.option-button.wrong {
  border-color: rgba(200,79,79,0.7);
  background: #fbeeee;
}

.answer-panel {
  margin-top: 18px;
  padding: 14px;
  border-radius: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.answer-panel p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.answer-result {
  font-weight: 900;
}

.auto-advance-status {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  margin-top: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 800;
}

.workspace-panel {
  display: grid;
  gap: 14px;
}

.panel-section {
  padding: 16px;
  box-shadow: none;
}

.panel-section h3,
.settings-section h3 {
  margin: 0 0 14px;
  font-size: 16px;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.field span,
.toggle-line,
.search-field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

select,
input[type="number"],
input[type="search"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
}

.toggle-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.mini-stats div {
  padding: 10px;
  border-radius: 8px;
  background: var(--panel-soft);
}

.mini-stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.mini-stats strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.list {
  display: grid;
  gap: 8px;
  max-height: 250px;
  overflow: auto;
}

.list-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.list-item button {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.list-item p {
  margin: 0;
  line-height: 1.45;
}

.list-item span {
  color: var(--muted);
  font-size: 12px;
}

.bank-view,
.settings-view {
  margin-top: 20px;
}

.bank-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 12px;
  margin-bottom: 14px;
}

.search-field {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.search-field input {
  border: 0;
}

.search-field span {
  text-align: center;
}

.bank-list {
  display: grid;
  gap: 10px;
}

.bank-item {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.bank-item h3 {
  margin: 0 0 8px;
  font-size: 17px;
  line-height: 1.5;
}

.bank-item p {
  margin: 4px 0;
  color: var(--muted);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.settings-section {
  padding: 18px;
  box-shadow: none;
}

.settings-section p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.7;
}

.settings-section.wide {
  grid-column: 1 / -1;
}

.dataset-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.dataset-meta div {
  padding: 12px;
  border-radius: 8px;
  background: var(--panel-soft);
}

.dataset-meta span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.dataset-meta strong {
  display: block;
  margin-top: 5px;
}

.score-box {
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  line-height: 1.7;
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-tabs {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .nav-tab {
    justify-content: center;
    padding: 10px 8px;
    text-align: center;
  }

  .nav-tab .icon {
    display: none;
  }

  .side-panel {
    grid-template-columns: repeat(3, 1fr);
  }

  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  body {
    background:
      linear-gradient(90deg, rgba(255,255,255,0.95), rgba(255,255,255,0.9)),
      url("assets/road-study.svg") center / cover fixed;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
  }

  .main {
    order: 1;
    padding: calc(10px + env(safe-area-inset-top)) 10px calc(82px + env(safe-area-inset-bottom));
  }

  .topbar {
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
  }

  .top-actions {
    justify-content: flex-end;
    gap: 6px;
    flex-wrap: nowrap;
  }

  .top-actions .primary-button {
    flex: 0 0 auto;
  }

  .eyebrow {
    display: none;
  }

  .topbar h2 {
    margin: 0;
    font-size: 18px;
    line-height: 1.2;
  }

  .primary-button,
  .secondary-button,
  .danger-button,
  .ghost-button,
  .ghost-text-button {
    min-height: 38px;
    padding: 0 12px;
  }

  .ghost-button {
    width: 38px;
  }

  .nav-tabs,
  .settings-grid,
  .dataset-meta,
  .bank-toolbar {
    grid-template-columns: 1fr;
  }

  .sidebar {
    order: 2;
    position: static;
    height: auto;
    padding: 0;
    background: transparent;
    border-right: 0;
  }

  .brand,
  .side-panel {
    display: none;
  }

  .nav-tabs {
    position: fixed;
    z-index: 20;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: rgba(38,49,61,0.97);
    border-top: 1px solid rgba(255,255,255,0.12);
    box-shadow: 0 -12px 30px rgba(23,33,43,0.22);
  }

  .nav-tab {
    min-height: 50px;
    padding: 6px 4px;
    border-radius: 8px;
    font-size: 11px;
    line-height: 1.2;
  }

  .question-card {
    padding: 12px;
  }

  .question-head {
    gap: 8px;
  }

  .question-head p {
    font-size: 12px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    font-size: 20px;
  }

  .question-card h3 {
    margin: 10px 0 12px;
    font-size: 18px;
    line-height: 1.42;
  }

  .status-row {
    gap: 6px;
    margin-bottom: 6px;
  }

  .pill {
    min-height: 24px;
    padding: 3px 8px;
    font-size: 11px;
  }

  .media-frame {
    margin-bottom: 8px;
  }

  .media-frame img {
    max-height: 150px;
  }

  .options {
    gap: 8px;
  }

  .option-button {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 8px;
    min-height: 46px;
    padding: 7px 8px;
    font-size: 15px;
    line-height: 1.35;
  }

  .option-key {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }

  .answer-panel {
    margin-top: 10px;
    padding: 10px;
  }

  .answer-panel p {
    margin-top: 6px;
    font-size: 13px;
    line-height: 1.45;
  }

  .auto-advance-status {
    min-height: 28px;
    margin-top: 8px;
    padding: 4px 8px;
    font-size: 13px;
  }

  .workspace-panel {
    gap: 8px;
    margin-top: 8px;
  }

  .panel-section {
    padding: 10px;
  }

  .panel-section h3,
  .settings-section h3 {
    margin-bottom: 8px;
    font-size: 14px;
  }

  .field {
    margin-bottom: 8px;
  }

  select,
  input[type="number"],
  input[type="search"] {
    min-height: 38px;
  }

  .mini-stats div {
    padding: 8px;
  }

  .mini-stats strong {
    margin-top: 2px;
    font-size: 16px;
  }

  .list {
    max-height: 120px;
  }
}
