:root {
  color-scheme: light;
  --bg: #f5f7f2;
  --paper: #fff;
  --ink: #1b3429;
  --muted: #4d6256;
  --line: #d9e3d8;
  --accent: #245a43;
  --soft: #e8f1e7;
  --lime: #d9edac;
  --sidebar: 14rem;
  --content: 76rem;
  --radius: .9rem;
  font: 100%/1.55 "DM Sans", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
p { margin: 0 0 .65rem; }
p:last-child { margin-bottom: 0; }
h1, h2, h3 { line-height: 1.32; margin: 0 0 .55rem; }
h1 { font-size: clamp(1.75rem, 4vw, 2.55rem); letter-spacing: -.04em; }
h2 { font-size: 1.25rem; letter-spacing: -.02em; }
h3 { font-size: 1.125rem; }
button, select, input, textarea { font: inherit; color: inherit; }
button, .button, select, input[type="search"], .field input {
  min-height: 2.75rem; border: 1px solid #bdcdbf; border-radius: .65rem; background: var(--paper); padding: .55rem .8rem;
}
button, .button { display: inline-flex; align-items: center; justify-content: center; font-weight: 650; cursor: pointer; text-align: center; }
button:hover:not(:disabled), .button:hover { border-color: var(--accent); background: var(--soft); }
button:disabled { opacity: .5; cursor: default; }
.primary { border-color: var(--accent); color: white; background: var(--accent); }
button.primary:hover:not(:disabled), .button.primary:hover { color: white; background: #194432; }
:focus-visible, .import-label:focus-within { outline: 3px solid #43865b; outline-offset: 3px; }
[tabindex="-1"]:focus { outline: none; }
.screenreader, .skip:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.skip:focus { position: fixed; top: .5rem; left: .5rem; z-index: 10; padding: .5rem; background: var(--paper); }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: #fbfcf8; border-right: 1px solid var(--line); padding: 1.7rem 1rem; overflow-y: auto; }
.brand { display: inline-flex; align-items: center; gap: .68rem; font-size: 1.12rem; font-weight: 800; min-height: 2.75rem; }
.brand-icon { display: grid; place-items: center; width: 2.5rem; height: 2.5rem; border-radius: .7rem; color: var(--lime); background: var(--ink); font: bold 1.14rem ui-monospace, monospace; }
.sidebar nav { display: grid; gap: .35rem; margin-top: 2.2rem; }
.sidebar nav a { min-width: 0; min-height: 2.85rem; display: flex; align-items: center; gap: .6rem; border-radius: .65rem; color: var(--muted); padding: .45rem .7rem; font-size: .94rem; }
.sidebar nav a:hover, .sidebar nav a[aria-current="page"] { background: var(--soft); color: var(--ink); }
.sidebar nav a[aria-current="page"] { font-weight: 750; }
.nav-icon { width: 1.4rem; flex: none; text-align: center; font: 1.12rem/1.1 ui-monospace, monospace; }
.short-label, .mobile-brand { display: none; }
#mistake-badge:not(:empty) { margin-left: auto; padding: 0 .34rem; background: #d5e6d6; border-radius: .4rem; font-size: .75rem; }
.workspace { margin-left: var(--sidebar); }
main, footer { max-width: var(--content); margin-inline: auto; padding-inline: clamp(1rem, 3vw, 2.5rem); }
main { padding-block: clamp(1.25rem, 3vw, 2.5rem) 2.2rem; min-height: 78vh; min-height: 78svh; }
footer { border-top: 1px solid var(--line); color: var(--muted); padding-block: 1rem 1.4rem; display: flex; align-items: center; justify-content: space-between; gap: .65rem; flex-wrap: wrap; font-size: .875rem; }
.page-heading { margin-bottom: 1.25rem; }
.page-heading p, .unit > p, .meta { color: var(--muted); }
.eyebrow { color: var(--accent); font-size: .83rem; font-weight: 750; margin-bottom: .35rem; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .55rem; }
.hero { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: center; gap: 1rem; background: #1d3d30; color: #f5f9ed; padding: clamp(1.1rem, 3vw, 2.1rem); border-radius: 1.15rem; }
.hero p { color: #d4e1d5; }
.hero .eyebrow { color: var(--lime); }
.hero .actions { margin-top: 1rem; }
.hero .primary { color: var(--ink); background: var(--lime); border-color: var(--lime); }
.hero .primary:hover:not(:disabled) { color: var(--ink); background: #cce29d; }
.hero .button { color: #f5f9ed; background: transparent; border-color: #829789; }
.hero .button:hover { background: #355446; }
.hero-code { border: 1px solid #5b7465; padding: 1rem; background: #142c23; color: #e8f0e7; border-radius: .75rem; overflow: hidden; font: .92rem/1.85 ui-monospace, Consolas, monospace; }
.hero-code span { color: var(--lime); }
.stats, .unit-grid, .notes-grid, .source-grid { display: grid; gap: .85rem; }
.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 1rem 0 1.65rem; }
.stat, .unit, .panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.stat { display: block; padding: .8rem .95rem; }
a.stat:hover { border-color: var(--accent); }
.stat span { display: block; color: var(--muted); font-size: .88rem; }
.stat strong { display: block; font-size: 1.5rem; line-height: 1.3; margin-top: .2rem; }
.stat small { font-size: .85rem; color: var(--muted); }
.unit-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.unit, .panel { padding: 1rem; }
.unit h3 { margin-bottom: .35rem; }
.unit > p:not(.eyebrow) { font-size: .88rem; }
.unit .eyebrow { color: var(--accent); }
.recent-unit { background: #f1f7e9; border-color: #b9d0ae; }
progress { display: block; width: 100%; height: .45rem; accent-color: var(--accent); overflow: hidden; border: 0; border-radius: 999px; background: var(--soft); }
progress::-webkit-progress-bar { background: var(--soft); }
progress::-webkit-progress-value { background: var(--accent); }
.unit-foot { display: flex; align-items: center; justify-content: space-between; gap: .35rem; color: var(--accent); }
.unit-foot a { display: flex; align-items: center; min-height: 2.75rem; font-size: .875rem; font-weight: 700; }
.unit-foot a:hover, .inline-link { text-decoration: underline; text-underline-offset: .16em; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .65rem; }
.section-head h2 { margin: 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .65rem; margin-bottom: 1rem; }
.field { display: grid; gap: .2rem; min-width: 0; font-size: .875rem; font-weight: 700; color: var(--muted); }
.field select, .field input { width: 100%; font-size: 1rem; }
.field.grow { flex: 1 1 14rem; max-width: 25rem; }
select { appearance: none; padding-right: 2.1rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='10' viewBox='0 0 14 10'%3E%3Cpath fill='none' stroke='%23245a43' stroke-width='1.7' d='m2 2 5 5 5-5'/%3E%3C/svg%3E"); background-position: right .7rem center; background-repeat: no-repeat; text-overflow: ellipsis; }
.notes-grid, .source-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
pre { margin: .65rem 0; padding: .85rem; overflow: auto; background: #19382d; color: #f1f7eb; border-radius: .65rem; tab-size: 2; }
pre, code { font-family: ui-monospace, Consolas, monospace; font-size: .92rem; line-height: 1.6; }
.mnemonic, .warning, .message { padding: .68rem .8rem; border-radius: .65rem; background: var(--soft); }
.warning { background: #fff4db; color: #67440f; }
.message.success { background: #dff2e8; color: #154a34; }
.message.error { background: #f9e9e3; color: #782b20; overflow-wrap: anywhere; }
.segmented { display: flex; gap: .23rem; padding: .16rem; border-radius: .8rem; background: var(--soft); }
.segmented button { min-width: 3.6rem; border-color: transparent; background: transparent; }
.segmented button[aria-pressed="true"], .toggle[aria-pressed="true"] { background: var(--paper); color: var(--accent); border-color: #79a082; }
.flash-layout { max-width: 43rem; margin-inline: auto; }
.flash-meta { display: flex; justify-content: space-between; gap: .5rem; color: var(--muted); font-size: .9rem; margin-bottom: .4rem; }
.flash-card { background: var(--paper); border: 1px solid var(--line); border-radius: 1rem; margin: .75rem 0; padding: clamp(1rem, 4vw, 2rem); min-height: 14rem; display: grid; align-content: center; justify-items: start; gap: .65rem; }
.flash-card h2 { font-size: clamp(1.2rem, 3vw, 1.65rem); }
.flash-card pre, #recall-form { width: 100%; min-width: 0; }
#recall-form { display: flex; align-items: end; flex-wrap: wrap; gap: .6rem; }
#recall-form label { flex: 1 1 12rem; }
.flash-answer { font: bold clamp(1.2rem, 4vw, 1.65rem)/1.3 ui-monospace, monospace; overflow-wrap: anywhere; }
.flash-card .message span { display: block; overflow-wrap: anywhere; }
.flash-actions > button { flex: 1; }
.practice-layout { display: grid; grid-template-columns: minmax(12rem, 16rem) minmax(0, 1fr); gap: 1rem; align-items: start; }
.question-sidebar { position: sticky; top: 1rem; padding: .75rem; }
.question-list { position: relative; display: grid; gap: .3rem; overflow: auto; max-height: 65vh; max-height: 65svh; padding: .2rem; }
.question-item { display: block; font-size: .875rem; padding: .55rem; border-radius: .55rem; overflow-wrap: anywhere; }
.question-item .meta { display: block; margin-bottom: .15rem; }
.question-item:hover, .question-item[aria-current] { background: var(--soft); }
.question-item[aria-current] { font-weight: 700; }
.mobile-picker { display: none; }
.practice-main { min-width: 0; }
.editor-panel { padding: 0; }
.question-heading, .editor-label, .editor-actions, .question-nav, .result-box { padding-inline: 1rem; }
.question-heading { padding-top: 1rem; }
.question-heading h2 { overflow-wrap: anywhere; scroll-margin: 1rem; }
.question-meta { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; color: var(--accent); font-size: .83rem; font-weight: 750; margin-bottom: .45rem; }
details { margin-top: .45rem; min-width: 0; }
summary { padding: .6rem 0; min-height: 2.75rem; cursor: pointer; font-weight: 650; }
.answer-panel details + details, .source-panel details + details { border-top: 1px solid var(--line); }
.schema { display: grid; gap: .45rem; margin-bottom: .75rem; }
.schema-row { display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--line); border-radius: .6rem; padding: .45rem .6rem; gap: .55rem; }
.schema-row div { min-width: 0; }
.schema-row p { margin: 0; font-size: .875rem; overflow-wrap: anywhere; }
.editor-label { display: flex; justify-content: space-between; padding-block: .48rem; background: #214435; color: #f2f7eb; font-weight: 700; }
.editor-label small { align-self: center; color: #cde0d1; }
#sql-editor { display: block; width: 100%; margin: 0; padding: .8rem 1rem; border: 0; border-radius: 0; background: #112820; color: #f3faee; resize: vertical; min-height: 8rem; font: 1rem/1.55 ui-monospace, Consolas, monospace; }
#sql-editor::placeholder { color: #a8c0b3; }
#sql-editor:focus-visible { outline-offset: -3px; outline-color: #add47a; }
.editor-actions { padding-block: .65rem; }
#sql-hint { margin: 0 1rem .65rem; }
.result-box { margin-bottom: .65rem; scroll-margin-block: 1rem 4rem; }
.result-box:empty, #schema-result:empty { display: none; }
.meta { font-size: .83rem; }
.table-wrap { max-width: 100%; overflow: auto; margin: .4rem 0 .65rem; border: 1px solid var(--line); border-radius: .55rem; }
table { width: 100%; min-width: max-content; border-collapse: collapse; text-align: left; font: .875rem/1.5 ui-monospace, Consolas, monospace; }
th, td { padding: .48rem .62rem; border-bottom: 1px solid var(--line); max-width: 24rem; overflow-wrap: anywhere; }
th { background: var(--soft); }
tr:last-child td { border-bottom: 0; }
.null { color: var(--muted); font-style: italic; }
.question-nav { display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); padding-block: .55rem; }
.answer-panel { margin-top: .85rem; }
.answer-panel details:first-child { margin-top: 0; }
.review-list { display: grid; gap: .65rem; }
.review-item { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
.review-item a { flex: none; }
.source-panel ul { margin: .2rem 0 .7rem; padding-left: 1.3rem; }
.source-panel li { margin-bottom: .35rem; overflow-wrap: anywhere; }
.gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
.gallery figure { margin: 0; min-width: 0; }
.gallery figcaption { font-size: .82rem; color: var(--muted); overflow-wrap: anywhere; }
.image-link { display: block; }
.image-link img { display: block; max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: .5rem; }
.empty { text-align: center; padding: 2rem 1rem; }
#toast { position: fixed; z-index: 7; right: 1rem; bottom: 1rem; max-width: min(23rem, calc(100% - 2rem)); color: white; background: var(--ink); padding: .7rem .95rem; border-radius: .65rem; opacity: 0; pointer-events: none; }
#toast.show { opacity: 1; }
@media (max-width: 68rem) {
  :root { --sidebar: 11.5rem; }
  .unit-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .question-sidebar { position: static; }
  .practice-layout { grid-template-columns: minmax(10rem, 12rem) minmax(0, 1fr); }
  .shortcut { display: none; }
}
@media (max-width: 55rem) {
  .sidebar { inset: auto 0 0; width: auto; padding: .25rem max(.25rem, env(safe-area-inset-right)) calc(.25rem + env(safe-area-inset-bottom)) max(.25rem, env(safe-area-inset-left)); z-index: 5; border: 0; border-top: 1px solid var(--line); overflow: visible; box-shadow: 0 -.15rem .65rem #1b342910; }
  .sidebar > .brand, .wide-label { display: none; }
  .sidebar nav { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .14rem; margin: 0; }
  .sidebar nav a { position: relative; flex-direction: column; justify-content: center; text-align: center; gap: .12rem; padding: .25rem .04rem; font-size: .79rem; }
  .short-label { display: block; }
  #mistake-badge:not(:empty) { position: absolute; inset: .05rem .12rem auto auto; line-height: 1.15; }
  .workspace { margin: 0; padding-bottom: calc(3.55rem + env(safe-area-inset-bottom)); }
  .mobile-brand { display: block; padding: .5rem 1rem; background: #fbfcf8; border-bottom: 1px solid var(--line); }
  .mobile-brand .brand-icon { width: 2rem; height: 2rem; font-size: .95rem; }
  .practice-layout { display: block; }
  .question-sidebar { display: none; }
  .mobile-picker { display: grid; margin-bottom: .7rem; }
  #toast { bottom: calc(3.9rem + env(safe-area-inset-bottom)); }
  .result-box { scroll-margin-bottom: 5rem; }
}
@media (max-width: 42rem) {
  .hero { grid-template-columns: minmax(0, 1fr); }
  .hero-code { display: none; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; }
  .notes-grid, .source-grid { grid-template-columns: minmax(0, 1fr); }
  .toolbar .field { flex: 1 1 9rem; }
  .toolbar .field.grow { flex-basis: 100%; max-width: none; }
  .editor-actions > button { flex: 1; min-width: max-content; }
  .editor-actions .primary { flex-grow: 2; }
  footer { font-size: .83rem; }
}
@media (max-width: 24rem) {
  main { padding-inline: .75rem; }
  .unit, .stat { padding-inline: .65rem; }
  .unit h3 { font-size: 1rem; }
  .unit-foot { flex-wrap: wrap; }
  .question-heading, .editor-label, .editor-actions, .question-nav, .result-box { padding-inline: .7rem; }
  .gallery { grid-template-columns: minmax(0, 1fr); }
}
