/* Braindance app: the Night Study Room (DESIGN.md) as a working study app.
   The world lends type, palette, density and one move: the lamp's stepped pool.
   Shared vocabulary for every view lives here; views add only view-scoped rules
   in their own stylesheet. */

:root {
  --ink-deep: #15122B;
  --ink: #1C1838;
  --shadow: #221D47;
  --wall: #2A2350;
  --dot: #2F2857;
  --wood-edge: #322A5C;
  --wood: #3A3166;
  --wood-mid: #4A4080;
  --wood-light: #5A4E9E;
  --muted: #5E587A;
  --amber: #FFB547;
  --amber-hi: #FFC874;
  --amber-dark: #E08F2A;
  --amber-deep: #A8651F;
  --teal: #3FA7A0;
  --teal-dark: #2B7A75;
  --teal-deep: #1D4A54;
  --teal-light: #7FD1C9;
  --sky: #173843;
  --glass: #255F65;
  --chalk: #F2EEE6;
  --chalk-dim: #CFCADB;
  --chalk-faint: #A9A3BF;
  --chalk-line: #E3DDD1;
  --on-chalk: #1C1838;
  --on-chalk-soft: #4A4370;
  --error: #FF8A70;
  --error-on-chalk: #A3341F;

  --display: "Pixelify Sans", "Figtree", system-ui, sans-serif;
  --text: "Figtree", system-ui, sans-serif;

  --a: 8px;          /* art pixel for sprites and stepped light */
  --c: 4px;          /* pixel-cut corner step */
  --bar-h: 64px;     /* top bar */
  --tabs-h: 64px;    /* phone bottom tabs */
  --gutter: clamp(16px, 3vw, 40px);

  --cut: polygon(0 var(--c), var(--c) var(--c), var(--c) 0, calc(100% - var(--c)) 0, calc(100% - var(--c)) var(--c), 100% var(--c), 100% calc(100% - var(--c)), calc(100% - var(--c)) calc(100% - var(--c)), calc(100% - var(--c)) 100%, var(--c) 100%, var(--c) calc(100% - var(--c)), 0 calc(100% - var(--c)));

  color-scheme: dark;
  scrollbar-color: var(--wood-mid) var(--ink);
}
@media (min-width: 900px) { :root { --a: 10px; } }

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--wall); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100svh;
  font: 400 16px/1.5 var(--text); color: var(--chalk-dim);
  background: var(--wall) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8' shape-rendering='crispEdges'%3E%3Cpath fill='%232F2857' d='M0 0h1v1H0zM4 4h1v1H4z'/%3E%3C/svg%3E") 0 0 / calc(8 * var(--a)) calc(8 * var(--a));
  -webkit-font-smoothing: antialiased; caret-color: var(--amber-dark);
}
::selection { background: var(--amber); color: var(--ink); }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }
/* Pixelify at 600: at app heading sizes its 700 closes the lowercase c into an o ("deoks") */
h1, h2, h3 { margin: 0; font-family: var(--display); font-weight: 600; color: var(--chalk); text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
a { color: inherit; text-underline-offset: 0.2em; text-decoration-thickness: 2px; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.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; }
.skip { position: absolute; left: 16px; top: -100px; z-index: 60; padding: 10px 16px; background: var(--amber); color: var(--ink); font-weight: 700; text-decoration: none; }
.skip:focus { top: 12px; }
svg[shape-rendering] { display: block; }

/* ---------- Shell: top bar ---------- */

.bar {
  position: sticky; top: 0; z-index: 30; height: var(--bar-h);
  display: flex; align-items: center; gap: clamp(16px, 2.6vw, 40px); padding: 0 var(--gutter);
  background: var(--ink); border-bottom: 2px solid var(--ink-deep);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font: 600 22px/1 var(--display); color: var(--chalk); text-decoration: none; white-space: nowrap; }
.brand-mark { display: block; width: 28px; height: 28px; }
.brand-mark svg { width: 100%; height: 100%; }

.tabs { display: flex; align-self: stretch; gap: 4px; }
.tabs a {
  position: relative; display: flex; align-items: center; padding: 0 14px;
  font: 600 15px/1 var(--text); color: var(--chalk-dim); text-decoration: none;
}
.tabs a:hover { color: var(--chalk); }
.tabs a[aria-current="page"] { color: var(--chalk); }
.tabs a[aria-current="page"]::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: 0; height: 4px; background: var(--amber);
}

.stats { margin-left: auto; display: flex; align-items: center; gap: clamp(14px, 2vw, 28px); }
.stat { display: grid; gap: 5px; min-width: 0; }
.stat-top { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
/* Pixelify's 2 and 5 read as a reversed S and an S, so every number in the app is set in Figtree */
.stat b { font: 700 16px/1 var(--text); font-variant-numeric: tabular-nums; color: var(--chalk); white-space: nowrap; }
.stat small { font: 500 12px/1 var(--text); color: var(--chalk-faint); }
.stat-streak { display: flex; align-items: center; gap: 8px; }
.flame { width: 18px; height: 22px; flex: none; }
.stat-streak[data-status="at-risk"] b { color: var(--amber); }
.stat-streak[data-status="broken"] b, .stat-streak[data-status="none"] b { color: var(--chalk-faint); }

/* the plate carries the pixel-cut corners, so the level badge can sit over its edge unclipped */
.me {
  position: relative; isolation: isolate; display: block; width: 44px; height: 44px; padding: 0; border: 0;
  text-decoration: none;
}
.me::before { content: ""; position: absolute; inset: 0; z-index: -1; background: var(--wood); clip-path: var(--cut); }
.me:hover::before { background: var(--wood-mid); }
.me .me-noggin { position: absolute; left: 7px; top: 6px; width: 30px; height: 30px; }
.me .me-noggin svg { width: 100%; height: 100%; }
.lvl-badge {
  position: absolute; right: -2px; bottom: -2px; min-width: 18px; padding: 2px 4px; text-align: center;
  font: 700 12px/1 var(--text); font-variant-numeric: tabular-nums; color: var(--ink); background: var(--amber);
}
.me-wrap { position: relative; }

/* narrower desktops: the stats drop their sublabels and the goal bar, so the tabs still fit */
@media (max-width: 1179px) {
  .stats { gap: 18px; }
  .stat small { display: none; }
  .stat-goal .segbar { display: none; }
  .stats .xpbar { width: 96px; }
}

/* phones: the tabs move to a bottom bar, the stats compress to numbers */
.tabbar { display: none; }
@media (max-width: 899px) {
  .bar { gap: 12px; padding: 0 12px; }
  .bar .tabs { display: none; }
  .brand span:not(.brand-mark) { display: none; }
  .stats { gap: 12px; }
  .stat-streak { gap: 5px; }
  .stat .unit { display: none; }
  .stats .xpbar { width: 60px; }
  body.is-welcome main { padding-bottom: 24px; }
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    display: grid; grid-template-columns: repeat(4, 1fr); background: var(--ink); border-top: 2px solid var(--ink-deep);
  }
  .tabbar a {
    position: relative; display: grid; place-items: center; align-content: center; gap: 4px;
    font: 600 12px/1 var(--text); color: var(--chalk-dim); text-decoration: none;
  }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a[aria-current="page"] { color: var(--chalk); }
  .tabbar a[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 4px; background: var(--amber); }
  main { padding-bottom: calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom)); }
}

/* ---------- Focus: studying dims the shell to the wall's own quiet values ---------- */

body.is-focus .bar { background: var(--ink-deep); }
body.is-focus .bar .brand, body.is-focus .tabs a, body.is-focus .stat b { color: var(--muted); }
body.is-focus .tabs a[aria-current="page"]::after { background: var(--wood-mid); }
body.is-focus .stat small { color: var(--wood-light); }
body.is-focus .xpbar > span, body.is-focus .segbar i.on { background: var(--wood-light); }
body.is-focus .tabbar { background: var(--ink-deep); }
body.is-focus .tabbar a, body.is-focus .tabbar a[aria-current="page"] { color: var(--muted); }
body.is-focus .tabbar a[aria-current="page"]::before { background: var(--wood-mid); }
body.is-focus { background-color: var(--ink); background-image: none; }

body.is-welcome .bar .tabs, body.is-welcome .stats, body.is-welcome .tabbar { display: none; }

/* ---------- Page layout ---------- */

main { display: block; }
.page { max-width: 1360px; margin: 0 auto; padding: clamp(28px, 4vw, 48px) var(--gutter) 64px; }
.page-narrow { max-width: 860px; }
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 32px; }
.span-7 { grid-column: span 7; }
.span-5 { grid-column: span 5; }
@media (max-width: 899px) { .grid { grid-template-columns: minmax(0, 1fr); gap: 28px; } .span-7, .span-5 { grid-column: auto; } }
.stack { display: grid; gap: 16px; align-content: start; }
.stack-lg { display: grid; gap: 32px; align-content: start; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.h-display { font-size: clamp(30px, 3.4vw, 44px); line-height: 1.05; }
.h-section { font-size: clamp(22px, 2vw, 26px); line-height: 1.1; }
.lede { font-size: 17px; color: var(--chalk-dim); max-width: 60ch; }
.label { font: 600 13px/1.2 var(--text); color: var(--chalk-faint); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Buttons: plate with pixel-cut corners and a lip ---------- */

.btn {
  position: relative; isolation: isolate; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px 3px; border: 0; background: none;
  font: 700 15px/1 var(--text); text-decoration: none; white-space: nowrap;
  --plate: var(--wood); --lip: var(--ink-deep); color: var(--chalk);
}
.btn::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(to top, var(--lip) 0 var(--c), var(--plate) var(--c));
  clip-path: var(--cut);
}
.btn:hover { --plate: var(--wood-mid); }
.btn:active:not(:disabled):not([aria-disabled="true"]) { transform: translateY(2px); }
.btn:active:not(:disabled):not([aria-disabled="true"])::before { background: var(--plate); }
.btn:disabled { cursor: not-allowed; --plate: var(--wood-edge); --lip: var(--ink-deep); color: var(--muted); }
/* busy: looks disabled but keeps keyboard focus while it works */
.btn[aria-disabled="true"], .btn[aria-disabled="true"]:hover { cursor: progress; --plate: var(--wood-edge); --lip: var(--ink-deep); color: var(--muted); }
.btn-amber { --plate: var(--amber); --lip: var(--amber-dark); color: var(--ink); }
.btn-amber:hover { --plate: var(--amber-hi); }
.btn-ink { --plate: var(--wall); --lip: var(--ink-deep); color: var(--chalk); }
.btn-ink:hover { --plate: var(--wood); }
.btn-teal { --plate: var(--teal); --lip: var(--teal-dark); color: var(--ink); }
.btn-teal:hover { --plate: var(--teal-light); }
.btn-danger { --plate: #7A2E2A; --lip: #4A1A18; color: var(--chalk); }
.btn-danger:hover { --plate: #933833; }
.btn-sm { min-height: 36px; padding: 0 12px 3px; font-size: 14px; --c: 3px; }
.btn-lg { min-height: 52px; padding: 0 24px 4px; font-size: 17px; --c: 5px; }
.btn-block { width: 100%; }
.link-btn { padding: 0; border: 0; background: none; font: 600 15px/1.3 var(--text); color: var(--chalk-dim); text-decoration: underline; text-underline-offset: 0.25em; text-decoration-thickness: 2px; }
.link-btn:hover { color: var(--amber); }
.btn svg, .link-btn svg { width: 16px; height: 16px; flex: none; }

/* ---------- Surfaces ---------- */

.paper { background: var(--chalk); color: var(--on-chalk); clip-path: var(--cut); --c: 6px; }
.paper .label { color: var(--on-chalk-soft); }
.paper h2, .paper h3 { color: var(--on-chalk); }
.panel { background: var(--ink); clip-path: var(--cut); --c: 6px; }
.panel-pad { padding: clamp(16px, 2vw, 24px); }

/* ---------- Tags and notices ---------- */

.tag { display: inline-flex; align-items: center; padding: 3px 7px 4px; font: 700 12px/1 var(--text); background: var(--wall); color: var(--chalk); white-space: nowrap; }
.tag-amber { background: var(--amber); color: var(--ink); }
.tag-teal { background: var(--teal); color: var(--ink); }
.tag-dim { background: var(--wood); color: var(--chalk-dim); }
.notice {
  display: flex; align-items: center; gap: 12px; padding: 14px 18px;
  background: var(--teal-deep); color: var(--chalk); clip-path: var(--cut); --c: 4px;
  font: 500 15px/1.4 var(--text);
}
.notice b { color: var(--teal-light); }
.notice-amber { background: #5C4325; }
.notice-amber b { color: var(--amber); }
.notice-error { background: #5A2622; }

/* ---------- Bars ---------- */

.xpbar { position: relative; display: block; width: 132px; height: 8px; background: var(--wood); }
.xpbar > span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--amber); }
.segbar { display: flex; gap: 2px; }
.segbar i { display: block; width: 6px; height: 8px; background: var(--wood); }
.segbar i.on { background: var(--amber); }
.mastery { display: inline-flex; gap: 2px; vertical-align: middle; }
.mastery i { display: block; width: 7px; height: 10px; background: var(--wood); }
.mastery i.on { background: var(--teal); }
.paper .mastery i { background: #DCD5C8; }
.paper .mastery i.on { background: var(--teal-dark); }

/* ---------- Table ---------- */

.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th {
  padding: 12px; text-align: left; font: 600 13px/1.2 var(--text); color: var(--chalk-faint);
  border-bottom: 2px solid var(--wood);
}
.table td { padding: 14px 12px; border-bottom: 2px solid var(--shadow); color: var(--chalk-dim); vertical-align: middle; }
.table td:first-child, .table th:first-child { padding-left: 16px; }
.table td:last-child, .table th:last-child { padding-right: 16px; }
.table tr:last-child td { border-bottom: 0; }
.table .t-num { text-align: right; font-variant-numeric: tabular-nums; }
.table .t-name a, .table .t-name { color: var(--chalk); font-weight: 700; text-decoration: none; }
.table .t-name a:hover { text-decoration: underline; }
.table tr.is-flag td { background: #2A2148; }
.table th button { padding: 0; border: 0; background: none; font: inherit; color: inherit; }
.table th button:hover { color: var(--chalk); }

/* ---------- Fields ---------- */

.field { display: grid; gap: 6px; }
.field > span, .field > label { font: 600 14px/1.2 var(--text); color: var(--chalk); }
.input, .textarea, .select {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 2px solid var(--wood-mid); border-radius: 0;
  background: var(--ink); color: var(--chalk); font: 500 16px/1.35 var(--text);
}
.textarea { resize: vertical; min-height: 64px; }
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.input:focus-visible, .textarea:focus-visible, .select:focus-visible { outline: 3px solid var(--amber); outline-offset: 0; border-color: var(--amber); }
.paper .input, .paper .textarea { background: #FBF8F2; color: var(--on-chalk); border-color: var(--on-chalk); }
.paper .input::placeholder, .paper .textarea::placeholder { color: #7C7598; }
.paper .input:focus-visible, .paper .textarea:focus-visible { outline-color: var(--amber-dark); border-color: var(--on-chalk); }
.field-error { font: 600 14px/1.3 var(--text); color: var(--error); }
.paper .field-error { color: var(--error-on-chalk); }
.field-error:empty { display: none; }

/* ---------- Noggin and its line ---------- */

.noggin { width: calc(var(--w, 22) * var(--s, 1) * var(--a)); height: calc(var(--h, 20) * var(--s, 1) * var(--a)); flex: none; }
.noggin svg { width: 100%; height: 100%; }
.noggin-line { font: 600 17px/1.4 var(--text); color: var(--chalk); max-width: 34ch; }
.noggin-line::before { content: ""; }

/* ---------- The lamp: stepped pool behind whatever it lights ---------- */

.lamp-stage { position: relative; isolation: isolate; }
.lamp-pool { position: absolute; left: 0; top: 0; z-index: -1; pointer-events: none; }
.sprite { display: block; width: calc(var(--w, 1) * var(--s, 1) * var(--a)); height: calc(var(--h, 1) * var(--s, 1) * var(--a)); }
.sprite svg { width: 100%; height: 100%; }
.desk-band {
  height: calc(6 * var(--a));
  background: linear-gradient(to bottom, var(--wood-edge) 0 var(--a), var(--wood) var(--a) calc(4 * var(--a)), var(--wood-light) calc(4 * var(--a)) calc(5 * var(--a)), var(--ink-deep) calc(5 * var(--a)));
}

/* ---------- Empty states ---------- */

.empty { display: grid; justify-items: start; gap: 16px; padding: 28px; }

/* ---------- Announcer and storage warning ---------- */

.storage-warn { margin: 0; padding: 10px var(--gutter); background: #5C4325; color: var(--chalk); font: 600 14px/1.4 var(--text); }

@media (prefers-reduced-motion: reduce) {
  .btn:active:not(:disabled) { transform: none; }
  * { scroll-behavior: auto !important; }
}
