:root {
  --bg: #f7f6f2;
  --ink: #1c1c1c;
  --muted: #6b6b6b;
  --accent: #2e5d4f;
  --accent-light: #cfe5dc;
  --gold: #d4a437;
  --got: #2e8540;
  --partial: #c98400;
  --missed: #b13a3a;
  --card: #ffffff;
  --border: #e3e0d8;
  --shadow: 0 1px 2px rgba(0,0,0,0.05), 0 4px 16px rgba(0,0,0,0.06);
  --radius: 12px;
  --max: 760px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; font-size: 17px; line-height: 1.5; }
body { min-height: 100vh; }
#fx-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 9999; }

header#topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
header#topbar[hidden] { display: none; }
label { display: block; }
label input, label textarea { display: block; margin-top: 4px; }
header#topbar .brand { font-weight: 700; color: var(--accent); letter-spacing: 0.5px; }
header#topbar .who { display: flex; gap: 16px; align-items: center; color: var(--muted); }
header#topbar .who #who-name { font-weight: 600; color: var(--ink); }

main#root { max-width: var(--max); margin: 0 auto; padding: 24px; }

button {
  font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--card);
  color: var(--ink); padding: 10px 16px; border-radius: 8px; transition: transform 0.05s ease, background 0.15s ease;
}
button:hover { background: var(--accent-light); }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); color: white; border-color: var(--accent); }
button.primary:hover { background: #224639; }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 0; }
button.link:hover { background: none; color: var(--ink); }

input, textarea {
  font: inherit; width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: white; color: var(--ink);
}
textarea { resize: vertical; min-height: 110px; font-family: inherit; }
input:focus, textarea:focus { outline: 2px solid var(--accent-light); border-color: var(--accent); }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 16px; }
h1 { margin: 0 0 8px; }
h2 { margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* Login */
.auth-page { max-width: 380px; margin: 60px auto; }
.auth-page h1 { text-align: center; color: var(--accent); }
.auth-page .card { text-align: center; }
.auth-page form { display: grid; gap: 12px; text-align: left; }
.auth-page .error { color: var(--missed); font-size: 14px; min-height: 20px; }

/* Dashboard */
.dash-header { display: flex; justify-content: space-between; align-items: baseline; }
.greeting h1 { margin: 0; }
.global-progress { margin: 16px 0 24px; }
.global-progress .bar { height: 12px; background: var(--border); border-radius: 99px; overflow: hidden; }
.global-progress .bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), #4a8c79); transition: width 0.4s ease; }
.global-progress .label { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 6px; }

.set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.set-tile {
  border: 1px solid var(--border); background: var(--card); border-radius: var(--radius);
  padding: 16px; text-align: center; cursor: pointer; transition: all 0.15s ease;
  position: relative;
}
.set-tile:hover:not(.locked) { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }
.set-tile .num { font-size: 28px; font-weight: 700; color: var(--accent); }
.set-tile .label { font-size: 13px; color: var(--muted); margin-top: 4px; }
.set-tile.completed { background: var(--accent-light); border-color: var(--accent); }
.set-tile.completed .check { position: absolute; top: 6px; right: 8px; color: var(--accent); font-weight: bold; font-size: 18px; }
.set-tile.locked { opacity: 0.45; cursor: not-allowed; background: #efece6; }
.set-tile.locked .lock { font-size: 22px; }
.set-tile.unlocked-next { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(212, 164, 55, 0.25); }

/* Study */
.study-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; font-size: 14px; color: var(--muted); }
.study-header .progress { font-variant-numeric: tabular-nums; }
.q-category { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--accent); margin-bottom: 6px; }
.q-prompt { font-size: 19px; line-height: 1.45; margin-bottom: 16px; }
.q-images { display: grid; gap: 10px; margin-bottom: 16px; }
.q-images.grid-3x2 { grid-template-columns: repeat(3, 1fr); }
.q-images.grid-1x2 { grid-template-columns: repeat(2, 1fr); }
.q-images img {
  width: 100%; max-height: 240px; object-fit: contain;
  border: 1px solid var(--border); border-radius: 8px; background: white;
}
.q-images.single img { max-height: 320px; }
.q-images .leaf-label { text-align: center; font-size: 12px; color: var(--muted); margin-top: 4px; }

.answer-area .controls { display: flex; gap: 8px; justify-content: space-between; margin-top: 12px; align-items: center; }
.answer-area .controls .left { display: flex; gap: 8px; }
.muted-tip { font-size: 13px; color: var(--muted); }

.reveal { margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--border); }
.reveal h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.reveal .official { background: #f3efe6; padding: 12px 14px; border-radius: 8px; border-left: 4px solid var(--gold); white-space: pre-wrap; }
.reveal .suggestion { font-size: 14px; color: var(--muted); margin: 12px 0 8px; }
.reveal .grade-buttons { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 10px; }
.reveal .grade-buttons button { font-weight: 600; padding: 12px; }
.reveal .grade-buttons .got { color: var(--got); border-color: var(--got); }
.reveal .grade-buttons .got.suggested { background: var(--got); color: white; }
.reveal .grade-buttons .partial { color: var(--partial); border-color: var(--partial); }
.reveal .grade-buttons .partial.suggested { background: var(--partial); color: white; }
.reveal .grade-buttons .missed { color: var(--missed); border-color: var(--missed); }
.reveal .grade-buttons .missed.suggested { background: var(--missed); color: white; }

.streak { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--gold); font-weight: 600; }

/* Hint + result */
.hint { margin-top: 10px; padding: 10px 12px; background: #fff8e1; border-left: 4px solid var(--gold); border-radius: 6px; font-size: 14px; }
#btn-hint { font-size: 14px; padding: 6px 10px; }
#btn-hint:disabled { opacity: 0.6; cursor: wait; }
.result { margin-top: 16px; padding: 14px; border-radius: 10px; border-left: 4px solid; }
.result.correct { background: #e8f5ec; border-color: var(--got); }
.result.wrong { background: #fbecec; border-color: var(--missed); }
.result .badge { font-weight: 700; font-size: 16px; margin-bottom: 6px; }
.result.correct .badge { color: var(--got); }
.result.wrong .badge { color: var(--missed); }
.result .rationale { font-size: 14px; color: var(--ink); line-height: 1.4; }
.result .expected { margin-top: 10px; padding: 10px 12px; background: white; border-radius: 6px; border: 1px solid var(--border); }
#typed { transition: border-color 0.2s ease; }

/* Admin stat grid */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin: 16px 0; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.stat-value { font-size: 28px; font-weight: 700; color: var(--accent); margin-top: 2px; }
.stat-value .muted { font-size: 18px; color: var(--muted); font-weight: 400; }
.stat-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* Admin attempts inline */
.attempts-cell { background: #fafaf6; padding: 8px 12px 12px !important; }
.attempt-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; padding: 4px 0; font-size: 13px; border-top: 1px dashed var(--border); }
.attempt-row:first-child { border-top: none; }
.attempt-row .typed { font-weight: 600; }
.attempt-row .rationale { flex: 1 1 100%; padding-left: 12px; }
.sub-row { border-top: 2px solid var(--border); }

/* Session complete */
.celebration { text-align: center; padding: 40px 20px; }
.celebration h1 { font-size: 36px; color: var(--accent); }
.celebration .subtitle { font-size: 18px; color: var(--muted); margin-top: 8px; }
.celebration .summary-bar { margin: 28px 0; }
.celebration .next-actions { display: flex; gap: 12px; justify-content: center; }

/* Admin */
.admin-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.admin-tabs button { font-size: 14px; }
.admin-tabs button.active { background: var(--accent); color: white; border-color: var(--accent); }
table.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--card); }
table.admin-table th, table.admin-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.admin-table th { background: #efece6; }
.grade-pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.grade-pill.got { background: rgba(46, 133, 64, 0.15); color: var(--got); }
.grade-pill.partial { background: rgba(201, 132, 0, 0.15); color: var(--partial); }
.grade-pill.missed { background: rgba(177, 58, 58, 0.15); color: var(--missed); }
