@font-face { font-family: "General Sans"; src: url("/fonts/general-sans-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "General Sans"; src: url("/fonts/general-sans-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "General Sans"; src: url("/fonts/general-sans-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Zodiak"; src: url("/fonts/zodiak-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --font-display: "Zodiak", Georgia, serif;
  --font-body: "General Sans", -apple-system, "Segoe UI", sans-serif;

  /* The table: deep felt green. Cards: warm card stock. */
  --table: #1f3a33;
  --table-deep: #172c27;
  --table-ink: #e9efe9;
  --table-muted: #a9bdb4;
  --card: #fbf7ef;
  --card-ink: #1d1b18;
  --card-muted: #6b645a;
  --card-rule: #e7dfd0;
  --answer-border: #3730a3; /* indigo, matches the printed answer side */
  --accent: #f2c14e;
  --danger: #c2410c;

  --radius-card: 18px;
  --radius: 12px;
  --shadow-card: 0 1px 0 rgba(255,255,255,.6) inset, 0 18px 40px -12px rgba(0,0,0,.55), 0 4px 10px rgba(0,0,0,.25);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { background: var(--table-deep); }
body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  color: var(--table-ink);
  background:
    radial-gradient(120% 80% at 50% 0%, #27483f 0%, var(--table) 45%, var(--table-deep) 100%) no-repeat;
  background-color: var(--table-deep);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

#app {
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 16px);
  display: flex;
  flex-direction: column;
}

/* ── Top bar ─────────────────────────────────────────────── */
.bar { display: flex; align-items: center; gap: 8px; min-height: 48px; }
.bar h1 {
  font-family: var(--font-display); font-weight: 700;
  font-size: 26px; line-height: 1.1; margin: 0; letter-spacing: -0.01em;
}
.bar .title { flex: 1; min-width: 0; }
.bar .title h1 { font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .title .sub { font-size: 13px; color: var(--table-muted); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 999px; border: 0;
  background: rgba(255,255,255,.08); display: grid; place-items: center; cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,.16); }
.icon-btn svg { width: 22px; height: 22px; }

/* ── Library ─────────────────────────────────────────────── */
.lede { color: var(--table-muted); margin: 4px 0 20px; font-size: 15px; }
.deck-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.deck {
  display: flex; align-items: stretch; gap: 0;
  background: var(--card); color: var(--card-ink);
  border-radius: var(--radius); box-shadow: 0 6px 16px -6px rgba(0,0,0,.45);
  overflow: hidden;
}
.deck-open {
  flex: 1; display: flex; gap: 14px; align-items: center; text-align: left;
  padding: 14px; border: 0; background: none; cursor: pointer; min-width: 0;
}
.deck-swatch {
  flex: none; width: 46px; height: 62px; border-radius: 8px; background: var(--table);
  display: grid; grid-template-columns: repeat(2, 10px); gap: 4px; place-content: center;
}
.deck-swatch i { width: 10px; height: 10px; border-radius: 99px; display: block; }
.deck-name { font-weight: 600; font-size: 17px; line-height: 1.25; }
.deck-meta { font-size: 13px; color: var(--card-muted); }
.deck-more { border: 0; background: none; width: 48px; color: var(--card-muted); cursor: pointer; }

.panel {
  margin-top: 24px; padding: 16px; border-radius: var(--radius);
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08);
}
.panel h2 { font-size: 16px; font-weight: 600; margin: 0 0 6px; }
.panel p { margin: 0 0 12px; color: var(--table-muted); font-size: 14px; }
.row { display: flex; gap: 8px; }
.input {
  flex: 1; min-width: 0; height: 48px; border-radius: 10px; border: 1px solid rgba(255,255,255,.18);
  background: rgba(0,0,0,.2); color: var(--table-ink); padding: 0 12px; font: inherit; font-size: 16px;
}
.input::placeholder { color: #7f978d; }

.btn {
  height: 48px; padding: 0 18px; border-radius: 999px; border: 0; cursor: pointer;
  font-weight: 600; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary { background: var(--accent); color: #2a2208; }
.btn-primary:active { filter: brightness(.94); }
.btn-ghost { background: rgba(255,255,255,.1); color: var(--table-ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn[disabled] { opacity: .5; }

.empty { text-align: center; padding: 40px 12px 8px; }
.empty .stack { position: relative; width: 120px; height: 150px; margin: 0 auto 20px; }
.empty .stack span {
  position: absolute; inset: 0; border-radius: 12px; background: var(--card);
  box-shadow: 0 8px 18px -8px rgba(0,0,0,.6);
}
.empty .stack span:nth-child(1) { transform: rotate(-9deg) translate(-10px, 4px); opacity: .55; }
.empty .stack span:nth-child(2) { transform: rotate(5deg) translate(8px, 0); opacity: .8; }
.empty h2 { font-family: var(--font-display); font-weight: 700; font-size: 24px; margin: 0 0 6px; }
.empty p { color: var(--table-muted); margin: 0 auto; max-width: 30ch; }

.hint {
  margin-top: 16px; font-size: 14px; color: var(--table-muted);
  display: flex; gap: 10px; align-items: flex-start;
}
.hint svg { flex: none; width: 20px; height: 20px; margin-top: 1px; }

/* ── Play ────────────────────────────────────────────────── */
.play { flex: 1; display: flex; flex-direction: column; }
.stage { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 10px 0 14px; perspective: 1600px; }

.card {
  display: grid; /* both faces share one cell, so height = taller face */
  cursor: pointer; border: 0; padding: 0; background: none; text-align: left; width: 100%;
  transform-style: preserve-3d;
  transition: transform .5s cubic-bezier(.2,.7,.2,1);
  touch-action: pan-y;
}
.card.flipped { transform: rotateY(180deg); }
.card.enter { animation: deal .32s cubic-bezier(.2,.7,.2,1); }
.card.enter-back { animation: deal-back .32s cubic-bezier(.2,.7,.2,1); }
@keyframes deal { from { transform: translateX(40%) rotate(4deg); opacity: 0; } }
@keyframes deal-back { from { transform: translateX(-40%) rotate(-4deg); opacity: 0; } }

.face {
  grid-area: 1 / 1;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--card); color: var(--card-ink);
  border-radius: var(--radius-card); box-shadow: var(--shadow-card);
  padding: 18px 18px 14px; display: flex; flex-direction: column;
}
.face.back {
  transform: rotateY(180deg);
  box-shadow: var(--shadow-card), inset 0 0 0 4px var(--answer-border);
}
.face-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--card-muted);
  padding-bottom: 10px; margin-bottom: 4px; border-bottom: 1px solid var(--card-rule);
}
.face-head b { color: var(--card-ink); letter-spacing: .04em; }
.q-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.q { display: grid; grid-template-columns: 30px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--card-rule); }
.q:last-child { border-bottom: 0; }
.dot {
  width: 28px; height: 28px; border-radius: 99px; color: #fff;
  display: grid; place-items: center; font-weight: 600; font-size: 15px; line-height: 1;
  margin-top: 1px; box-shadow: inset 0 -2px 0 rgba(0,0,0,.12);
}
.q-text { font-size: 17px; line-height: 1.4; }
.a-text { font-size: 17px; font-weight: 600; line-height: 1.35; }
.fun { font-size: 14.5px; font-style: italic; color: var(--card-muted); margin-top: 3px; line-height: 1.4; }
.flip-hint { margin-top: 10px; text-align: center; font-size: 12px; color: var(--card-muted); }

.controls {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center;
  position: sticky; bottom: 0; z-index: 5;
  margin: 0 -16px calc(-1 * (var(--safe-bottom) + 16px));
  padding: 12px 16px calc(var(--safe-bottom) + 16px);
  background: linear-gradient(to bottom, rgba(23,44,39,0), var(--table-deep) 35%);
}
.controls .btn-ghost { background: #2c4a42; }
.controls[hidden] { display: none; }
.controls .btn { width: 100%; }
.counter { font-size: 14px; color: var(--table-muted); text-align: center; min-width: 72px; font-variant-numeric: tabular-nums; }

.done { text-align: center; padding: 30px 8px; }
.done h2 { font-family: var(--font-display); font-weight: 700; font-size: 26px; margin: 0 0 8px; }
.done p { color: var(--table-muted); margin: 0 0 20px; }
.done .row { justify-content: center; flex-wrap: wrap; }

/* ── Sheet / dialog ──────────────────────────────────────── */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; z-index: 20; animation: fade .15s; }
.sheet {
  width: 100%; max-width: 560px; background: #24423a; color: var(--table-ink);
  border-radius: 20px 20px 0 0; padding: 20px 16px calc(var(--safe-bottom) + 16px);
  animation: up .2s cubic-bezier(.2,.7,.2,1);
}
.sheet h2 { margin: 0 0 4px; font-size: 18px; font-weight: 600; }
.sheet p { margin: 0 0 16px; color: var(--table-muted); font-size: 14px; }
.sheet .stack-btns { display: grid; gap: 10px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }

.toast {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 12px); transform: translateX(-50%);
  background: #0e1b17; color: var(--table-ink); padding: 12px 16px; border-radius: 12px;
  font-size: 14px; z-index: 30; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.status { text-align: center; padding: 48px 16px; color: var(--table-muted); }
.status h2 { color: var(--table-ink); font-size: 20px; margin: 0 0 8px; }
.spinner { width: 28px; height: 28px; border-radius: 99px; border: 3px solid rgba(255,255,255,.2); border-top-color: var(--accent); margin: 0 auto 14px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .card.enter, .card.enter-back, .sheet, .scrim { animation: none; }
}
@media (min-height: 860px) { .q-text, .a-text { font-size: 18px; } }

/* Short phones (iPhone SE / mini): tighter card so more fits on screen. */
@media (max-height: 740px) {
  .face { padding: 14px 14px 10px; }
  .face-head { padding-bottom: 8px; }
  .q { padding: 7px 0; gap: 10px; grid-template-columns: 26px 1fr; }
  .dot { width: 24px; height: 24px; font-size: 13px; }
  .q-text, .a-text { font-size: 15.5px; }
  .fun { font-size: 13.5px; margin-top: 2px; }
  .stage { padding: 6px 0 8px; }
  .flip-hint { margin-top: 6px; }
}
