:root {
  --bg: #141a33;
  --panel: #1e2647;
  --panel-2: #2a3360;
  --line: #3a4578;
  --text: #eef0fa;
  --muted: #a3abd0;
  --accent: #f2c14e;
  --accent-text: #2a2000;
  --good: #7ddc9a;
  --bad: #ff8f8f;
  --red: #d8433f;
  --blue: #2f6fde;
  --green: #2e9b57;
  --yellow: #c99700;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100dvh;
}

h1,
h2,
p {
  margin: 0;
}

h2 {
  font-size: 1.05rem;
}

.logo {
  font-size: 3.2rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--accent);
}

.logo.small {
  font-size: 1.6rem;
}

.muted {
  color: var(--muted);
}

.center {
  text-align: center;
}

.error {
  color: var(--bad);
}

.auth {
  justify-content: center;
  align-items: stretch;
  text-align: center;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
  color: var(--muted);
}

input:not([type='checkbox']) {
  font: inherit;
  /* 16px or more keeps iOS from zooming into the field. */
  font-size: 16px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}

input[type='checkbox'] {
  width: 24px;
  height: 24px;
  accent-color: var(--accent);
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}

button.big {
  padding: 16px;
  font-size: 1.1rem;
}

button.link {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  padding: 8px;
}

button.tiny {
  min-height: 32px;
  padding: 4px 8px;
  font-size: 0.8rem;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.grow {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.72rem;
  font-weight: 700;
}

.badge.off {
  background: var(--bad);
}

.links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: auto;
}

.link-box {
  display: block;
  padding: 10px;
  background: var(--bg);
  border-radius: 8px;
  overflow-wrap: anywhere;
  font-size: 0.85rem;
  user-select: all;
}

.setting {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text);
  font-size: 1rem;
}

.setting.check {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.setting.check small {
  display: block;
}

.segmented {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.segmented button {
  flex: 1;
}

.segmented button.on {
  border-color: var(--accent);
  color: var(--accent);
  opacity: 1;
  font-weight: 700;
}

/* ---------- game ---------- */

.game {
  gap: 10px;
}

.game .bar {
  font-size: 0.9rem;
  flex-wrap: nowrap;
  min-height: 46px;
}

.bar-actions {
  display: flex;
  white-space: nowrap;
}

.bar-actions button.link {
  padding: 8px 6px;
}

.trump-box {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.trump {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
}

.trump .glyph {
  width: 16px;
  height: 16px;
}

.seats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.seat {
  flex: 1 1 96px;
  max-width: 180px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 6px 8px;
  text-align: center;
  font-size: 0.85rem;
}

.seat.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgb(242 193 78 / 0.25);
}

.seat-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.seat-stats {
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

.own .seat {
  max-width: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.felt {
  flex: 1;
  min-height: 150px;
  background: #0f1530;
  border: 1px solid var(--line);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
}

.trick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.played {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.75rem;
  max-width: 64px;
  overflow-wrap: anywhere;
  text-align: center;
}

.played.won .card {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.status {
  text-align: center;
  min-height: 1.4em;
  font-weight: 600;
}

.countdown {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.pad {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.pad.column {
  flex-direction: column;
  align-items: center;
}

.bid {
  min-width: 48px;
  font-size: 1.1rem;
  font-weight: 700;
}

.suit-pick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
}

.suit-pick .glyph {
  width: 18px;
  height: 18px;
}

.winner {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--accent);
}

.hand {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  padding-bottom: 6px;
}

/* ---------- cards: midnight face, gold frame, the familiar in a moon window ---------- */

.card {
  --ink: #f5cf6b;
  --tint: #3d2569;
  --halo: radial-gradient(circle at 50% 40%, #7a58c0 0%, #33206a 55%, #120a28 100%);
  --glow: rgb(245 207 107 / 0.55);
  position: relative;
  width: 56px;
  height: 82px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  background: radial-gradient(130% 90% at 50% 45%, var(--tint) 0%, #0b0e24 76%);
  box-shadow: inset 0 0 0 1.5px #c9a24a, 0 3px 8px rgb(0 0 0 / 0.4);
  color: var(--ink);
  display: block;
  flex: none;
  transition: transform 0.12s;
}

.card.c-red {
  --ink: #ff7a57;
  --tint: #4a1828;
  --halo: radial-gradient(circle at 50% 40%, #b0462c 0%, #4e1622 55%, #1e0810 100%);
  --glow: rgb(255 122 87 / 0.7);
}

.card.c-blue {
  --ink: #61b6ff;
  --tint: #10305a;
  --halo: radial-gradient(circle at 50% 40%, #2f74b0 0%, #123a66 55%, #071630 100%);
  --glow: rgb(97 182 255 / 0.65);
}

.card.c-green {
  --ink: #5fd68e;
  --tint: #0f3d2c;
  --halo: radial-gradient(circle at 50% 40%, #3f8a4c 0%, #164a2c 55%, #06200f 100%);
  --glow: rgb(95 214 142 / 0.6);
}

.card.c-yellow {
  --ink: #ffd34d;
  --tint: #473a0d;
  --halo: radial-gradient(circle at 50% 40%, #ffd34d 0%, #c98a1a 32%, #3d2a08 75%);
  --glow: rgb(255 211 77 / 0.65);
}

.card.c-fizzle {
  --ink: #c9c4e2;
  --tint: #23233b;
  --halo: radial-gradient(circle at 50% 40%, #5a5878 0%, #26263e 60%, #0e0e1c 100%);
  --glow: rgb(181 176 207 / 0.35);
}

.card.c-special {
  --ink: #7fe3d4;
  --tint: #0c3439;
  --halo: radial-gradient(circle at 50% 45%, #145a5c 0%, #071c22 75%);
  --glow: rgb(127 227 212 / 0.6);
}

.card .win {
  color: var(--ink);
  position: absolute;
  left: 7px;
  top: 33px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--halo);
  box-shadow: 0 0 0 1px #c9a24a, 0 0 8px var(--glow);
}

.card .win img {
  position: absolute;
  max-width: none;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.card .win .glyph {
  position: absolute;
  left: 20%;
  top: 20%;
  width: 60%;
  height: 60%;
  filter: drop-shadow(0 0 4px var(--glow));
}

.card .corner {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 17px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 1px 0 2px;
  border-radius: 5px;
  background: rgb(11 14 36 / 0.72);
  font: 700 16px/1 Georgia, 'Times New Roman', serif;
  color: var(--ink);
}

.card .corner .glyph {
  width: 10px;
  height: 10px;
}

/* Trump card and score sheet: number and suit only. */
.card.small {
  width: 30px;
  height: 42px;
  border-radius: 5px;
  box-shadow: inset 0 0 0 1px #c9a24a;
}

.card.small .win {
  display: none;
}

.card.small .corner {
  inset: 0;
  width: auto;
  align-items: flex-start;
  gap: 4px;
  padding: 3px 0 0 4px;
  background: none;
  font-size: 11px;
}

.card.small .corner .glyph {
  width: 15px;
  height: 15px;
  margin-left: 4px;
}

.glyph {
  fill: currentColor;
  fill-rule: evenodd;
}

/* Large hands on narrow screens: cards overlap, the corner with number and suit stays visible. */
@media (max-width: 520px) {
  .hand.dense {
    gap: 6px 0;
    padding-right: 24px;
  }

  .hand.dense .card {
    margin-right: -24px;
    box-shadow: inset 0 0 0 1.5px #c9a24a, -3px 0 6px rgb(0 0 0 / 0.5);
  }

  .hand.dense .card.selected {
    z-index: 1;
  }
}

.card.dim {
  opacity: 0.4;
}

.card.selected {
  transform: translateY(-12px);
  box-shadow: inset 0 0 0 1.5px #c9a24a, 0 0 0 3px var(--accent), 0 6px 14px rgb(0 0 0 / 0.5);
}

.c-red {
  color: var(--red);
}

.c-blue {
  color: var(--blue);
}

.c-green {
  color: var(--green);
}

.c-yellow {
  color: var(--yellow);
}

/* The text colour of trump and suit buttons must stay readable on dark panels. */
.trump.c-red,
.suit-pick.c-red {
  color: #ff8a86;
}

.trump.c-blue,
.suit-pick.c-blue {
  color: #8db4ff;
}

.trump.c-green,
.suit-pick.c-green {
  color: #7ddc9a;
}

.trump.c-yellow,
.suit-pick.c-yellow {
  color: #f2c14e;
}

/* ---------- score sheet, overlays ---------- */

.sheet-wrap {
  overflow: auto;
  max-height: 55dvh;
  width: 100%;
}

.sheet {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.sheet th,
.sheet td {
  padding: 4px 6px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

.sheet th:first-child,
.sheet td:first-child {
  text-align: left;
}

.sheet small {
  color: var(--muted);
}

.sheet .good {
  color: var(--good);
}

.sheet .bad {
  color: var(--bad);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgb(5 8 20 / 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.overlay .panel {
  width: 100%;
  max-width: 600px;
}

.banner,
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.banner {
  top: calc(8px + env(safe-area-inset-top));
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.toast {
  bottom: calc(110px + env(safe-area-inset-bottom));
  background: var(--bad);
  color: #3a0000;
  font-weight: 700;
}

@media (prefers-reduced-motion: reduce) {
  .card {
    transition: none;
  }
}

.legend {
  display: block;
  font-size: 0.7rem;
}

.sheet caption {
  caption-side: bottom;
  padding-top: 6px;
  font-size: 0.75rem;
  text-align: left;
}

/* ---------- voice ---------- */

.voice {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.voice button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

button.warn {
  border-color: var(--bad);
  color: var(--bad);
}

.mic-wrap {
  display: inline-flex;
  vertical-align: middle;
  margin-left: 4px;
}

.mic {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--good);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mic.muted {
  stroke: var(--bad);
}

.mic-wrap.speaking {
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--good);
  background: rgb(125 220 154 / 0.25);
}

.rules {
  margin: 0;
  padding-left: 18px;
  font-size: 0.85rem;
}

.played strong {
  font-size: 0.7rem;
}

/* ---------- how to play ---------- */

.tutorial {
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}

.overlay .panel.tutorial {
  max-width: 460px;
}

.tutorial h2 {
  margin: 0;
}

.tutorial p {
  margin: 0;
  line-height: 1.45;
}

.tut-head,
.tut-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tut-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  align-items: center;
}

.tut-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.tut-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
}

.tut-cards {
  display: flex;
  gap: 4px;
}

.tutorial .card {
  width: 44px;
  height: 64px;
  border-radius: 7px;
}

.tutorial .card .win {
  left: 5px;
  top: 25px;
  width: 34px;
  height: 34px;
}

.tutorial .card .corner {
  top: 3px;
  left: 3px;
  width: 14px;
  font-size: 13px;
}

.tutorial .card .corner .glyph {
  width: 8px;
  height: 8px;
}

.tut-row.tight {
  gap: 4px;
  flex-wrap: nowrap;
}

.tut-nav {
  position: sticky;
  bottom: -16px;
  margin: 0 -16px -16px;
  padding: 10px 16px 16px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}

.tut-gt {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--muted);
}

.tut-caption {
  text-align: center;
  font-size: 0.9rem;
}

.tut-bid {
  min-width: 40px;
  padding: 8px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: center;
  font-weight: 700;
  background: var(--panel-2);
}

.tut-bid.on {
  border-color: var(--accent);
  color: var(--accent);
}

.tut-trick {
  padding: 10px 12px;
  border-radius: 14px;
  background: #0f1530;
  border: 1px solid var(--line);
}

.tut-hand {
  padding-top: 14px;
}

.tut-score {
  width: 100%;
}

.tut-score td:last-child {
  text-align: right;
  font-weight: 700;
}

.tut-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.tut-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line);
}

.tut-dots span.on {
  background: var(--accent);
}
