/* Conjuga: the desk is WebGL behind everything; the card is HTML placed on
   its 3D card by the CSS3DRenderer; the rest is a thin HUD over it. */
:root {
  --bg: #1d1410;
  --ink: #f4e9d6;
  --muted: #c9b89d;
  --paper: #fbf5e6;
  --paper-2: #f1e7cf;
  --rule: #c9d7e6;
  --rule-red: #e08a8a;
  --card-ink: #27211b;
  --card-muted: #6b6052;
  --red: #a93226;
  --green: #2f7a48;
  --accent: #e4a33a;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Noto Serif", "Droid Serif", ui-serif, serif;
  --sab: var(--random-nav-h, env(safe-area-inset-bottom, 0px));
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
html { background: var(--bg); overscroll-behavior: none; }
body {
  margin: 0; color: var(--ink); font: 16px/1.45 var(--sans);
  background: var(--bg); overflow: hidden; -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sheet :focus-visible, .card :focus-visible { outline-color: var(--card-ink); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* the scene fills the window; the hub's bar is a strip at the bottom */
#stage { position: fixed; inset: 0; bottom: var(--sab); }
#stage .gl { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; }
#stage .css3d { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
/* a soft vignette, the room's corners a little darker */
#stage::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, transparent 55%, #00000055 100%); }
.desk-tag {
  pointer-events: none !important;
  font: 600 30px/1 var(--sans); letter-spacing: .04em; text-transform: uppercase;
  color: #fff2d8; background: #6e4a2a; padding: 12px 20px; border-radius: 4px; opacity: .92;
  box-shadow: 0 1px 0 #3e2a17;
}
.desk-tag.miss { background: #8c3b32; }
.desk-tag.got { background: #3c6b45; }

/* ------------------------------------------------------------- the card */
.card {
  width: 320px; height: 240px; position: relative; transform-style: preserve-3d;
  pointer-events: auto !important; cursor: pointer; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.card .face {
  position: absolute; inset: 0; border-radius: 6px; overflow: hidden;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: linear-gradient(180deg, #fffbf1 0, var(--paper) 30%, var(--paper-2) 100%);
  color: var(--card-ink); text-align: center;
  box-shadow: inset 0 0 0 1px #e2d6bd;
}
/* an index card, ruled: a blue line every 20px from 20, the red one at 40.
   Every string of text rests on a rule (rules.js puts it there), baseline
   on the line. */
.card .face::before, .pile-card::before {
  content: ""; position: absolute; left: 0; right: 0; top: 20px; bottom: 0; pointer-events: none; opacity: .6;
  background: linear-gradient(180deg, var(--rule) 0 1.2px, transparent 1.2px) 0 0 / 100% 20px repeat-y;
}
.card .face::after, .pile-card::after {
  content: ""; position: absolute; left: 0; right: 0; top: 40px; height: 1.6px; pointer-events: none; background: var(--rule-red); opacity: .8;
}
/* every string is one or more 20px lines, set where rules.js puts it */
:where(.card .face > :not(.say):not(.table-btn), .pile-card > *) { position: absolute; left: 20px; right: 20px; margin: 0; line-height: 20px; white-space: nowrap; }
.bl { display: inline-block; width: 0; height: 0; vertical-align: baseline; }
/* The faces sit a hair apart (never coplanar: the browser would draw the
   wrong one), and the one facing away is hidden outright, since
   backface-visibility isn't honoured under the CSS3D renderer's mirrored
   transform. */
.card .front { transform: translateZ(1px); }
.card .back { transform: rotateY(180deg) translateZ(1px); visibility: hidden; }
.card.flipped .front { visibility: hidden; }
.card.flipped .back { visibility: visible; }
/* the tense is written on the red rule; a long name wraps upward onto the
   rule above, and keeps clear of the speaker button on the back */
.card .tense, .pile-card .tense {
  font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--card-muted); white-space: normal;
}
/* the English name, the Spanish name and the command tag are each whole: a
   long tense wraps between them, never inside one (so two lines at most) */
.card .tense > *, .pile-card .tense > * { display: inline-block; white-space: nowrap; }
.card .tense > .bl { display: inline-block; }
.card .back .tense { left: 48px; right: 48px; }
.card .tense small { font: italic 13px/20px var(--serif); letter-spacing: .02em; text-transform: none; margin-left: .5em; }
.card .tense small:first-of-type { margin-left: .5em; }
.card .tense .command { font: 11px/20px var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--red); margin-left: .6em; }
/* the Spanish is serif, the apparatus sans */
.card .pronoun { font: italic 22px/20px var(--serif); color: #5a5047; }
.card .inf { font: 400 40px/20px var(--serif); letter-spacing: -.01em; }
.card .gloss { font-size: 14px; color: var(--card-muted); }
.card .tap { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--card-muted); }
.card .form { font: 600 40px/20px var(--serif); letter-spacing: -.01em; }
.card .meaning { font-size: 14px; color: #5a5047; }
.card .note { font-size: 13px; color: #8a4a2a; white-space: normal; text-wrap: pretty; left: 24px; right: 24px; }
.card .note:empty, .card .example:empty { display: none !important; }
.card .example { font: italic 15px/20px var(--serif); color: #4a4036; white-space: normal; text-wrap: pretty; left: 24px; right: 24px; }
/* centred between the card's top edge and the red rule (40px): a 44px
   target whose middle is at 20px */
.card .say, .card .table-btn {
  position: absolute; top: -2px; width: 44px; height: 44px; border: 0; padding: 0; color: #3a2f24;
  display: grid; place-items: center; background: radial-gradient(circle at center, #eadfc6 16.5px, transparent 17px);
}
.card .say { right: 0; }
.card .table-btn { left: 0; right: auto; }
.card .say svg, .card .table-btn svg { width: 20px; height: 20px; }
.card .say.on { background: radial-gradient(circle at center, var(--accent) 16.5px, transparent 17px); color: #2b1d08; }


/* the last card on each pile, lying there answer up */
.pile-card {
  pointer-events: none !important;
  width: 320px; height: 240px; border-radius: 6px; overflow: hidden;
  background: linear-gradient(180deg, #fffbf1 0, var(--paper) 30%, var(--paper-2) 100%);
  color: var(--card-ink); text-align: center;
  box-shadow: inset 0 0 0 1px #e2d6bd; position: relative;
}
.pile-card .form { font: 600 40px/20px var(--serif); letter-spacing: -.01em; }
.pile-card .who { font: italic 15px/20px var(--serif); color: #5a5047; }

/* --------------------------------------------------------------- the HUD */
.hud { position: fixed; left: 0; right: 0; z-index: 3; padding: 0 16px; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud.top { top: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: max(10px, env(safe-area-inset-top)); }
.hud .line { font-size: 14px; color: var(--ink); background: #0007; padding: 4px 10px; border-radius: 999px; backdrop-filter: blur(6px); width: fit-content; min-height: 1.4em; }
.hud .tools { display: flex; gap: 6px; }
.icon {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: #fff2; color: var(--ink); display: grid; place-items: center; padding: 0;
  backdrop-filter: blur(6px);
}
.icon svg { width: 20px; height: 20px; }
.icon:hover { background: #fff3; }
.hud.bottom { bottom: calc(var(--sab) + 14px); display: grid; gap: 10px; justify-items: center; }
.grade { display: flex; gap: 10px; width: min(100%, 440px); }
.grade button {
  flex: 1; min-height: 58px; border: 0; border-radius: 14px; font-size: 17px; font-weight: 600; color: #fff;
  display: flex; align-items: center; justify-content: center; gap: 10px; box-shadow: 0 6px 18px #0006, inset 0 1px 0 #fff3;
}
.grade .t { display: grid; line-height: 1.15; text-align: left; }
.grade .t small { font-size: 12px; font-weight: 500; }
.grade .miss { background: linear-gradient(180deg, #a83b2f, #8a2f25); }
.grade .got { background: linear-gradient(180deg, #367a4c, #2a6640); }
.grade .k { font-size: 11px; font-weight: 600; border: 1px solid #fff8; border-radius: 4px; padding: 0 5px; line-height: 16px; }
@media (hover: none) { .grade .k { display: none; } }
.start, .done { display: grid; gap: 12px; justify-items: center; text-align: center; max-width: 360px; }
.start .welcome { margin: 0; color: var(--ink); text-shadow: 0 1px 3px #000a; font-size: 15px; }
.big {
  min-height: 54px; padding: 0 34px; border: 0; border-radius: 999px; font-size: 18px; font-weight: 600;
  background: linear-gradient(180deg, #f1b74d, #d9942a); color: #2b1d08; box-shadow: 0 6px 18px #0006;
}
.done { background: #000a; backdrop-filter: blur(8px); padding: 18px 22px; border-radius: 16px; }
.done h2 { margin: 0; font: 600 22px/1.2 var(--serif); }
.done p { margin: 0; }
.small { font-size: 13px; color: var(--muted); }
.hud .lines { display: grid; gap: 6px; min-width: 0; }
.voice-note { margin: 0; font-size: 12.5px; line-height: 1.35; color: #ffd9a3; background: #000a; border: 0; padding: 7px 10px; border-radius: 10px; max-width: 420px; text-align: left; }

.toast {
  position: fixed; left: 50%; top: 64px; transform: translateX(-50%); z-index: 5; pointer-events: none;
  background: #2b1d08ee; color: #ffe8bd; border: 1px solid #e4a33a88; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: min(90vw, 420px); text-align: center;
  box-shadow: 0 8px 24px #0008; animation: toast .35s ease-out;
}
@keyframes toast { from { opacity: 0; transform: translate(-50%, -8px); } }

/* --------------------------------------------------------------- sheets */
.sheet {
  border: 0; padding: 0; margin: auto; width: min(100vw, 520px); max-height: min(92vh, 92dvh);
  background: var(--paper); color: var(--card-ink); border-radius: 18px 18px 0 0; box-shadow: 0 -10px 40px #000a;
  position: fixed; bottom: 0; top: auto; left: 0; right: 0; color-scheme: light;
}
@media (min-width: 560px) { .sheet { border-radius: 18px; bottom: auto; top: 50%; transform: translateY(-50%); } }
.sheet::backdrop { background: #0009; }
.sheet form { margin: 0; padding: 14px 18px calc(18px + var(--sab)); overflow: auto; max-height: inherit; }
.sheet header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; position: sticky; top: -14px; margin-top: -14px; padding: 14px 0 8px; background: var(--paper); z-index: 1; } /* (sticks to the very top: nothing scrolls past above it) */
.sheet h2 { margin: 0; font: 600 24px/1.2 var(--serif); }
.sheet h3 { margin: 18px 0 6px; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--card-muted); }
.sheet .icon { background: #0001; color: var(--card-ink); }
.sheet .small { color: var(--card-muted); margin: 4px 0 8px; }
.sheet .field { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 6px; margin: 8px 0; font-size: 15px; }
.sheet .field > select, .sheet .field > input { grid-column: 1 / -1; }
.sheet .field .val { font-weight: 600; }
.sheet select, .sheet input[type="search"] { font: inherit; padding: 9px 10px; border-radius: 10px; border: 1px solid #8f7f62; background: #fff; color: inherit; width: 100%; }
.sheet input[type="range"] { width: 100%; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 10px; min-height: 40px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--green); }
.sheet .row { display: flex; gap: 8px; flex-wrap: wrap; }
.sheet .row button, .sheet button.plain { min-height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid #cdbf9f; background: #fff; color: inherit; }
.sheet .row .danger { color: var(--red); border-color: #e3b1aa; }
.tenses { list-style: none; margin: 0; padding: 0; }
.tenses li { display: flex; align-items: center; gap: 10px; min-height: 44px; border-top: 1px solid #e6dcc3; font-size: 15px; }
.tenses li .name { flex: 1; }
.tenses li .name small { display: block; color: var(--card-muted); font-size: 12px; font-style: italic; }
.tenses li .state { font-size: 12px; color: var(--card-muted); letter-spacing: .06em; text-transform: uppercase; }
.tenses li .state.open { color: var(--green); }
.tenses li .state.next { color: #8a5a10; }
.tenses li .pct { font-size: 12px; color: var(--card-muted); min-width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; }
.tenses li button { min-height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid #cdbf9f; background: #fff; color: inherit; font-size: 13px; }
.verbs { list-style: none; margin: 10px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.verbs button { width: 100%; text-align: left; min-height: 44px; padding: 6px 10px; border-radius: 10px; border: 1px solid #e6dcc3; background: #fff; color: inherit; display: grid; }
.verbs button b { font: 600 17px/1.1 var(--serif); }
.verbs button small { color: var(--card-muted); font-size: 12px; }
.verbs button .dots { font-size: 10px; letter-spacing: .15em; color: var(--green); }
.tense-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.tense-tabs button { flex: none; min-height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid #cdbf9f; background: #fff; color: inherit; font-size: 13px; }
.tense-tabs button[aria-selected="true"] { background: var(--card-ink); color: var(--paper); border-color: var(--card-ink); }
.tense-tabs button.locked { opacity: .6; border-style: dashed; }
.conj { width: 100%; border-collapse: collapse; }
.conj td { padding: 0; border-top: 1px solid #e6dcc3; }
.conj button { width: 100%; display: grid; grid-template-columns: 9em 1fr 18px; align-items: center; gap: 12px; min-height: 48px; padding: 6px 8px; border: 0; background: none; color: inherit; text-align: left; border-radius: 8px; }
.conj button:hover { background: #0000000a; }
.conj .p { color: var(--card-muted); font-size: 13px; }
.conj .f { font: 600 20px/1.1 var(--serif); }
@media (max-width: 24rem) { .conj button { grid-template-columns: 7.5em 1fr 18px; } .conj .p { font-size: 12px; } }
.conj .f:empty::before { content: "—"; color: #cdbf9f; font-weight: 400; }
.conj svg { width: 18px; height: 18px; color: var(--card-muted); flex: none; }
.conj button.on svg { color: var(--accent); }
kbd { font: 12px/1 ui-monospace, Menlo, monospace; background: #fff; border: 1px solid #cdbf9f; border-bottom-width: 2px; border-radius: 4px; padding: 2px 5px; }

@media (max-height: 560px) {
  .start .welcome { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
  * { transition-duration: 0s !important; }
}

/* the voice note, faded once it has been read */
.voice-note { transition: opacity .6s; }
.voice-note.faded { opacity: 0; pointer-events: none; }
