/* Self-hosted fonts (Google Fonts subsets) so the app works offline */
@font-face {
  font-family: 'GFS Didot';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/gfsdidot-greek.woff2) format('woff2');
  unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF;
}
@font-face {
  font-family: 'GFS Didot';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/gfsdidot-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Cinzel';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url(fonts/cinzel-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Cinzel';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url(fonts/cinzel-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --stone: #2A2723;
  --stone-deep: #1F1D1A;
  --marble: #EFEBE3;
  --marble-hi: #F5F2EC;
  --marble-lo: #E5DFD2;
  --carved: #3A352E;
  --frame: #B9AF9C;
  --basalt: #4A4640;
  --basalt-hi: #534E47;
  --basalt-lo: #3F3B36;
  --frame-dark: #8C7B5E;
  --gold: #D2B27A;
  --gold-dark: #A8875A;
  --bronze-text: #6E5A3A;
  --muted: #BDB4A3;
  --track-border: #5A534A;
  --didot: 'GFS Didot', 'Didot', 'Times New Roman', serif;
  --cinzel: 'Cinzel', 'Trajan Pro', 'Times New Roman', serif;
  --spring: cubic-bezier(0.3, 1.4, 0.5, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--stone);
  color: var(--marble);
  font-family: var(--cinzel);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.sr-only, .measure {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.measure {
  width: auto;
  height: auto;
  clip-path: none;
  visibility: hidden;
  left: -9999px;
  top: 0;
  line-height: 1;
}

.label {
  font-family: var(--cinzel);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  line-height: 1.2;
}

/* ---------- Card screen ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.deck {
  background: var(--stone);
  padding:
    max(64px, calc(env(safe-area-inset-top) + 20px))
    max(24px, calc(env(safe-area-inset-right) + 16px))
    max(40px, calc(env(safe-area-inset-bottom) + 16px))
    max(24px, calc(env(safe-area-inset-left) + 16px));
  gap: var(--deck-gap, 48px);
  max-width: 480px;
  margin: 0 auto;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  flex: none;
}

.hud-half {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hud-mastered {
  align-items: flex-end;
  background: none;
  border: 0;
  padding: 14px 0 0;
  margin: -14px 0 0;
  min-height: 44px;
  justify-content: flex-end;
  cursor: pointer;
  text-align: right;
}

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

.segs span {
  height: 8px;
  border-radius: 1px;
  background: var(--stone-deep);
  border: 1px solid var(--track-border);
  transition: background-color 200ms ease, border-color 200ms ease;
}

.segs span.on { background: var(--gold); border-color: var(--gold); }

.bar {
  display: block;
  width: 100%;
  height: 8px;
  border-radius: 1px;
  background: var(--stone-deep);
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 1px;
  background: var(--gold);
  transition: width 240ms ease;
}

.table {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.stage-box { position: relative; flex: none; }

.stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 330px;
  height: 462px;
  transform-origin: 0 0;
  transform: scale(var(--fit, 1));
}

/* ---------- Cards ---------- */

.card {
  position: absolute;
  inset: 0;
  width: 330px;
  height: 462px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  box-shadow: 0 30px 50px rgba(0, 0, 0, 0.55), 0 8px 14px rgba(0, 0, 0, 0.35);
  text-align: left;
  font-family: var(--cinzel);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  --dy: 0px;
  --dx: 0px;
}

.card.current {
  z-index: 2;
  cursor: grab;
  touch-action: none;
  transform: translate(var(--dx), var(--dy));
  will-change: transform, opacity;
}

.card.current.dragging { cursor: grabbing; }
.card.current.spring { transition: transform 220ms var(--spring); }

.card.behind {
  z-index: 1;
  transform: scale(0.96);
  opacity: 0.85;
  will-change: transform, opacity;
}

.face {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  padding: 14px;
  overflow: hidden;
}

.face-front {
  background: linear-gradient(160deg, var(--marble-hi) 0%, var(--marble) 48%, var(--marble-lo) 100%);
  color: var(--carved);
}

.face-back {
  background: linear-gradient(160deg, var(--basalt-hi) 0%, var(--basalt) 50%, var(--basalt-lo) 100%);
  color: var(--marble);
  display: none;
}

.card.flipped .face-front { display: none; }
.card.flipped .face-back { display: block; }

.veins { position: absolute; left: 0; top: 0; pointer-events: none; }

.frame {
  position: relative;
  height: 100%;
  border: 1px solid var(--frame);
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.face-back .frame { border-color: var(--frame-dark); }

.card-top {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 3px;
  line-height: 1.2;
}

.glyph-front {
  font-family: var(--didot);
  font-weight: 400;
  font-size: 176px;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  color: var(--carved);
  text-shadow: 0 1px 0 #FFFFFF, 0 -1px 0 rgba(0, 0, 0, 0.28);
}

.card-foot {
  border-top: 1px solid var(--gold-dark);
  padding-top: 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 3px;
  line-height: 1.2;
  text-align: center;
  color: var(--bronze-text);
}

.face-back .card-foot { border-top-color: var(--gold); color: var(--marble); }

.back-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.glyph-back {
  font-family: var(--didot);
  font-size: 48px;
  line-height: 1;
  color: var(--gold);
}

.name {
  font-size: 54px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 4px;
  white-space: nowrap;
  /* letter-spacing adds trailing space; pull it back so the word stays centred */
  margin-right: -4px;
}

.pron {
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 4px;
  line-height: 1.2;
  white-space: nowrap;
  margin-right: -4px;
}

/* ---------- Grade motion ---------- */

@keyframes nod      { 0%, 100% { transform: translateY(var(--dy)) scale(1); } 50% { transform: translateY(var(--dy)) scale(1.06); } }
@keyframes exitUp   { from { transform: translateY(var(--dy)); opacity: 1; } to { transform: translateY(calc(var(--dy) - 560px)); opacity: 0; } }
@keyframes shake    { 0% { transform: translate(0, var(--dy)) rotate(0); }
                      20% { transform: translate(18px, var(--dy)) rotate(2.5deg); }
                      45% { transform: translate(-12px, var(--dy)) rotate(-1.6deg); }
                      70% { transform: translate(6px, var(--dy)) rotate(.8deg); }
                      100% { transform: translate(0, var(--dy)) rotate(0); } }
@keyframes exitDown { from { transform: translateY(var(--dy)); opacity: 1; } to { transform: translateY(calc(var(--dy) + 560px)); opacity: 0; } }
@keyframes exitLeft { from { transform: translate(var(--dx), var(--dy)); opacity: 1; } to { transform: translate(calc(var(--dx) - 420px), var(--dy)) rotate(-6deg); opacity: 0; } }
@keyframes exitRight{ from { transform: translate(var(--dx), var(--dy)); opacity: 1; } to { transform: translate(calc(var(--dx) + 420px), var(--dy)) rotate(6deg); opacity: 0; } }
@keyframes rise     { from { transform: scale(.96); opacity: .85; } to { transform: scale(1); opacity: 1; } }
@keyframes fadeOut  { from { opacity: 1; } to { opacity: 0; } }
@keyframes fadeIn   { from { opacity: .85; } to { opacity: 1; } }

.card.up    { animation: nod 140ms ease-out, exitUp 240ms ease-in 140ms forwards; }
.card.down  { animation: shake 200ms ease-out, exitDown 240ms ease-in 200ms forwards; }
.card.left  { animation: exitLeft 240ms ease-in forwards; }
.card.right { animation: exitRight 240ms ease-in forwards; }

.card.behind.rise-up   { animation: rise 240ms ease-out 140ms forwards; }
.card.behind.rise-down { animation: rise 240ms ease-out 200ms forwards; }
.card.behind.rise-now  { animation: rise 240ms ease-out forwards; }

.reduced .card.behind { transform: none; }
.reduced .card.current.up,
.reduced .card.current.down,
.reduced .card.current.left,
.reduced .card.current.right { animation: fadeOut 150ms linear forwards; }
.reduced .card.behind.rise-up,
.reduced .card.behind.rise-down,
.reduced .card.behind.rise-now { animation: fadeIn 150ms linear forwards; }
.reduced .card.current.spring { transition-duration: 150ms; transition-timing-function: ease-out; }

/* ---------- Stoa ---------- */

.stoa {
  z-index: 10;
  background: var(--stone-deep);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.stoa-inner {
  min-height: 100%;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding:
    max(56px, calc(env(safe-area-inset-top) + 16px))
    max(24px, calc(env(safe-area-inset-right) + 16px))
    max(32px, calc(env(safe-area-inset-bottom) + 16px))
    max(24px, calc(env(safe-area-inset-left) + 16px));
}

.stoa-head { display: flex; justify-content: space-between; align-items: center; }
.stoa-title { display: flex; flex-direction: column; gap: 2px; }

.stoa-title h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 4px;
  line-height: 1;
}

.stoa-greek { font-family: var(--didot); font-size: 15px; color: var(--gold); letter-spacing: 2px; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--frame-dark);
  background: transparent;
  color: var(--marble);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}

.stoa-summary { display: flex; flex-direction: column; gap: 8px; }
.summary-row { display: flex; justify-content: space-between; gap: 12px; }
.bar-stoa { background: var(--stone); }

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.tile {
  height: 72px;
  border-radius: 4px;
  padding: 6px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  border: 1px solid rgba(0, 0, 0, 0.35);
  min-width: 0;
}

.tile-glyph { font-family: var(--didot); font-size: 24px; line-height: 1; white-space: nowrap; }
.tile-name { font-size: 7.5px; font-weight: 600; letter-spacing: 0.3px; line-height: 1; white-space: nowrap; }

.tile-segs {
  width: 100%;
  padding: 0 3px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
}

.tile-segs span { height: 4px; border-radius: 1px; background: rgba(0, 0, 0, 0.3); }

.legend { display: flex; flex-direction: column; gap: 8px; }

.legend-ramps {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--muted);
}

.legend-ramp { display: flex; flex-direction: column; gap: 6px; }
.ramp { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 3px; }
.ramp span { height: 10px; border-radius: 2px; border: 1px solid rgba(0, 0, 0, 0.35); }

.legend-note { margin: 0; font-family: var(--didot); font-size: 13px; line-height: 1.35; color: var(--muted); }

.stoa-spacer { flex: 1; min-height: 4px; }

.stoa-msg {
  margin: 0;
  min-height: 1.35em;
  text-align: center;
  font-family: var(--didot);
  font-size: 14px;
  line-height: 1.35;
  color: var(--gold);
}

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

.btn {
  height: 44px;
  border-radius: 4px;
  border: 1px solid var(--frame-dark);
  background: var(--stone);
  color: var(--marble);
  font-family: var(--cinzel);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  padding: 0 6px;
  cursor: pointer;
}

.btn-reset {
  width: 100%;
  height: 48px;
  border-color: var(--gold);
  background: transparent;
  font-size: 15px;
  letter-spacing: 4px;
}

.btn-danger { border-color: var(--gold); background: var(--gold); color: var(--stone-deep); }

.reset-confirm { display: flex; flex-direction: column; gap: 10px; }
.reset-q { margin: 0; text-align: center; color: var(--gold); }

.offline { text-align: center; color: var(--muted); }
.offline.ready { color: var(--gold); }
