:root {
  --blue: #1b3a6b;
  --blue-2: #2a5397;
  --tan: #b5793c;
  --tan-2: #d9a35f;
  --cream: #f7f0e1;
  --cream-2: #efe3c9;
  --ink: #2a2118;
  --muted: #7d6c58;
  --berry: #8c2b3a;
  --bg: #e9dfca;
  --panel: #fffaf0;
  --radius: 16px;
  --shadow: 0 6px 18px rgba(42, 33, 24, 0.14);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  background-image: radial-gradient(rgba(181, 121, 60, 0.12) 1px, transparent 1px);
  background-size: 14px 14px;
  color: var(--ink);
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(110px + env(safe-area-inset-bottom));
}

h1, h2 { font-family: 'Fraunces', Georgia, serif; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }

.screen { display: flex; flex-direction: column; gap: 14px; }

.hero { text-align: center; color: var(--blue); padding-top: 12px; }
.hero .logo { color: var(--tan); }
.hero h1 { font-size: 2.1rem; line-height: 1.05; margin: 6px 0; font-weight: 800; }
.hero h1 span { font-style: italic; color: var(--berry); font-weight: 600; }
.tagline { color: var(--muted); margin: 6px 0 0; }

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.panel.center { align-items: center; text-align: center; }

label { font-weight: 800; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
input, select {
  font: inherit;
  font-size: 1.05rem;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid var(--cream-2);
  background: white;
  color: var(--ink);
  width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--tan); }
.code-input { text-transform: uppercase; letter-spacing: 0.4em; font-weight: 800; text-align: center; }

.btn {
  font: inherit;
  font-weight: 800;
  font-size: 1.05rem;
  border: 2px solid var(--blue);
  color: var(--blue);
  background: transparent;
  border-radius: 999px;
  padding: 13px 18px;
  cursor: pointer;
  width: 100%;
  transition: transform 0.08s ease, background 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--blue); color: var(--cream); }
.btn.primary:disabled { background: #9ea9bd; border-color: #9ea9bd; cursor: not-allowed; }
.btn.small { font-size: 0.9rem; padding: 8px 14px; width: auto; align-self: center; }
.btn.ghost { border-color: transparent; color: var(--muted); }

.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.85rem; margin: 6px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--cream-2); }

.error { color: var(--berry); font-weight: 700; margin: 0; min-height: 1.2em; }
.muted { color: var(--muted); margin: 0; }

.how summary { font-weight: 800; cursor: pointer; color: var(--blue); }
.how ol { margin: 8px 0 0; padding-left: 20px; }
.how li { margin-bottom: 6px; }

.big-code {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 3.2rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--blue);
  margin-right: -0.2em;
}

.count { color: var(--muted); font-weight: 400; }
.player-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.player-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; border-radius: 10px; background: var(--cream);
}
.tag { font-size: 0.75rem; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: var(--tan-2); color: var(--ink); }
.offline { opacity: 0.5; }

/* game */
.topbar {
  display: flex; justify-content: space-between;
  background: var(--blue); color: var(--cream);
  border-radius: var(--radius); padding: 10px 16px;
}
.topbar .muted { color: #b6c6e3; font-size: 0.8rem; }

.scoreboard { list-style: none; margin: 0 -16px; padding: 10px 16px 6px; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.scoreboard::-webkit-scrollbar { display: none; }
.scoreboard li {
  flex: 0 0 auto;
  background: var(--panel); border-radius: 12px; padding: 6px 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; min-width: 72px; position: relative;
  border: 2px solid transparent;
}
.scoreboard li.judge { border-color: var(--tan); }
.scoreboard li.me .pname { text-decoration: underline; text-decoration-color: var(--tan); }
.scoreboard .pname { font-weight: 800; font-size: 0.85rem; max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scoreboard .pscore { font-family: 'Fraunces', serif; font-weight: 800; font-size: 1.2rem; color: var(--blue); }
.scoreboard .badge { position: absolute; top: -8px; right: -6px; font-size: 0.7rem; background: var(--tan); color: white; border-radius: 999px; padding: 1px 6px; font-weight: 800; }
.scoreboard .badge.done { background: var(--blue-2); }

.notice { background: var(--tan-2); padding: 10px 14px; border-radius: 12px; margin: 0; font-weight: 700; }
.status { text-align: center; font-weight: 800; font-size: 1.1rem; margin: 4px 0 0; color: var(--blue); }

/* cards: a stitched-leather look */
.card {
  position: relative;
  border-radius: 14px;
  padding: 18px 18px 30px;
  font-weight: 800;
  font-size: 1.12rem;
  line-height: 1.3;
  box-shadow: var(--shadow);
}
.card::before {
  content: '';
  position: absolute; inset: 6px;
  border: 2px dashed currentColor;
  border-radius: 10px;
  opacity: 0.22;
  pointer-events: none;
}
.card::after {
  content: 'EAN';
  position: absolute; bottom: 10px; right: 16px;
  font-family: 'Fraunces', serif; font-size: 0.7rem; letter-spacing: 0.15em; opacity: 0.5;
}
.card.prompt {
  background: linear-gradient(160deg, var(--blue-2), var(--blue));
  color: var(--cream);
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.35rem;
  min-height: 140px;
}
.card.prompt .pick { position: absolute; bottom: 10px; left: 16px; font-family: 'Nunito', sans-serif; font-size: 0.75rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--tan-2); }
.blank { display: inline-block; min-width: 3.5em; border-bottom: 3px solid var(--tan-2); }
.fill { color: var(--tan-2); }
.card.prompt .fill { color: #f3c77f; }
.card.prompt .blank { border-bottom-color: #f3c77f; }

.answer {
  background: #ffffff;
  color: var(--ink);
  width: 100%; text-align: left; font-family: inherit; border: 3px solid transparent;
  cursor: pointer;
}
.answer.selected { border-color: var(--tan); transform: translateY(-4px); box-shadow: 0 10px 22px rgba(42, 33, 24, 0.22); }
.answer .order {
  position: absolute; top: -10px; left: -6px; background: var(--tan); color: white;
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 0.85rem;
}

.hand { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 4px; }
@media (min-width: 420px) { .hand { grid-template-columns: 1fr 1fr; } .hand .answer { font-size: 1rem; min-height: 110px; } }

.subs { display: flex; flex-direction: column; gap: 12px; }
.sub { background: #ffffff; color: var(--ink); text-align: left; font-family: 'Fraunces', serif; font-size: 1.1rem; border: 3px solid transparent; cursor: default; }
.sub.choosable { cursor: pointer; }
.sub.selected { border-color: var(--tan); }
.sub.winner { border-color: var(--tan); background: #fff4dc; }
.sub .fill { color: var(--berry); }
.sub .who { display: block; font-family: 'Nunito', sans-serif; font-size: 0.85rem; color: var(--muted); margin-top: 8px; }
.sub.winner .who { color: var(--blue); }

.waiting { text-align: center; padding: 18px; }
.waiting .horse { font-size: 2.4rem; display: inline-block; animation: trot 0.6s ease-in-out infinite alternate; }
@keyframes trot { from { transform: translateY(0) rotate(-4deg); } to { transform: translateY(-6px) rotate(4deg); } }

.winner-banner { text-align: center; }
.winner-banner h2 { font-size: 1.6rem; color: var(--blue); margin: 4px 0; }

.action-bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}
.action-bar .btn { max-width: 528px; margin: 0 auto; display: block; box-shadow: var(--shadow); }

.toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--cream); padding: 10px 16px; border-radius: 999px; font-weight: 700; z-index: 10;
  max-width: calc(100% - 32px);
}

.linkish { background: none; border: none; color: var(--muted); text-decoration: underline; font: inherit; font-size: 0.9rem; cursor: pointer; padding: 4px; align-self: center; }
