:root {
  --bg: #14110f;
  --felt: #173a2c;
  --felt-edge: #0e2a1f;
  --text: #f6f1e7;
  --muted: #b9b2a5;
  --gold: #e9b949;
  --gold-dark: #b98a1c;
  --red: #d2283c;
  --ink: #16141a;
  --card: #fbf8f1;
  --line: rgba(255, 255, 255, 0.14);
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-edge) 70%, var(--bg) 100%) fixed;
  color: var(--text);
  font: 18px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

.screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.panel {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.panel.center { text-align: center; align-items: center; }

h1 { margin: 0; font-size: clamp(2rem, 6vw, 3rem); color: var(--gold); letter-spacing: 0.5px; }
h2 { margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.crown-big { font-size: 4.5rem; color: var(--gold); line-height: 1; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.tight { gap: 4px; flex-wrap: nowrap; }
.panel.center .row { justify-content: center; }

/* Big, high-contrast controls: this gets used in the dark with wet hands. */
.btn {
  min-height: 52px;
  padding: 0 20px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: rgba(255, 255, 255, 0.14); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.btn.primary:hover { background: #f3c85e; }
.btn.big { min-height: 60px; font-size: 1.15rem; flex: 1 1 200px; }
.btn.link { background: none; border: none; color: var(--gold); text-decoration: underline; min-height: 44px; }

.icon-btn {
  width: 48px; height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
}

input[type="text"] {
  flex: 1 1 180px;
  min-width: 0;
  min-height: 52px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font: inherit;
}
input[type="text"]:focus { outline: 2px solid var(--gold); outline-offset: 1px; }

textarea {
  width: 100%;
  min-height: 70px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  resize: vertical;
}

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips li {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 6px 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}
.chips button {
  width: 32px; height: 32px; border-radius: 50%;
  border: none; background: rgba(0, 0, 0, 0.3); color: var(--text); cursor: pointer;
}

/* ---------- Game ---------- */

.screen.game {
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: 12px;
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.kings { display: flex; gap: 2px; font-size: 1.5rem; }
#remaining { white-space: nowrap; font-size: 0.9rem; }
.king-slot { color: rgba(255, 255, 255, 0.18); transition: color 0.3s, transform 0.3s; }
.king-slot.on { color: var(--gold); transform: scale(1.15); }

.table {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.card {
  position: relative;
  width: min(62vw, 42dvh, 320px);
  aspect-ratio: 5 / 7;
  border-radius: 18px;
  border: none;
  padding: 0;
  cursor: pointer;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  font-family: Georgia, "Times New Roman", serif;
  user-select: none;
  transition: transform 0.12s;
}
.card:active { transform: scale(0.97); }
.card.red { color: var(--red); }

.card.back {
  background:
    repeating-linear-gradient(45deg, rgba(233, 185, 73, 0.18) 0 10px, transparent 10px 20px),
    #7a1222;
  border: 8px solid var(--card);
}
.card.back .card-corner, .card.back .card-center { display: none; }
.card .card-hint { display: none; }
.card.back .card-hint {
  display: block;
  position: absolute; inset: auto 0 14%;
  color: var(--card);
  font: 600 1.1rem system-ui, sans-serif;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
.card.empty { opacity: 0.35; cursor: default; }

.card-corner {
  position: absolute;
  font-size: clamp(1.4rem, 4.5vmin, 2.4rem);
  line-height: 1;
  font-weight: 700;
  text-align: center;
  white-space: pre-line;
}
.card-corner.tl { top: 8%; left: 9%; }
.card-corner.br { bottom: 8%; right: 9%; transform: rotate(180deg); }
.card-center {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(4rem, 17vmin, 9rem);
}

.card.flip { animation: flip 0.35s ease-out; }
/* Scale/fade rather than a 3D flip, so the card never shrinks to zero width and eats a tap. */
@keyframes flip {
  from { transform: scale(0.88); opacity: 0.3; }
  to { transform: scale(1); opacity: 1; }
}

.info {
  width: 100%;
  max-width: 640px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.info #rule-title { font-size: clamp(1.8rem, 6vmin, 3.2rem); color: var(--gold); }
.info #rule-text { font-size: clamp(1.1rem, 3.4vmin, 1.8rem); }
.info form { width: 100%; justify-content: center; }
.turn { color: var(--muted); font-weight: 600; min-height: 1.4em; }

.status { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.status .tag {
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  font-size: clamp(0.95rem, 2.6vmin, 1.3rem);
  text-align: left;
}
.status .tag b { color: var(--gold); }

/* Landscape / TV: card on the left, rule on the right, everything bigger. */
@media (orientation: landscape) and (min-width: 700px) {
  .table { flex-direction: row; gap: 5vw; }
  .card { width: min(32vw, 62dvh, 520px); }
  .info { text-align: left; align-items: flex-start; max-width: 46vw; }
  .info form { justify-content: flex-start; }
  .kings { font-size: 5vmin; }
  #remaining { font-size: 3vmin; }
  .icon-btn { width: 7vmin; height: 7vmin; min-width: 48px; min-height: 48px; font-size: 3vmin; }
  /* Readable from across the room. */
  .info { gap: 2vmin; }
  .info #rule-title { font-size: clamp(2.4rem, 10vmin, 7rem); line-height: 1.05; }
  .info #rule-text { font-size: clamp(1.2rem, 5vmin, 3.2rem); line-height: 1.3; }
  .turn { font-size: clamp(1rem, 3.6vmin, 2.2rem); }
  .status .tag { font-size: clamp(1rem, 3.4vmin, 2rem); }
}

/* ---------- Dialogs ---------- */

dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #1f1b18;
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.7); }
.dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.rule-field { display: grid; grid-template-columns: 52px 1fr; gap: 8px 12px; align-items: start; padding: 10px 0; border-top: 1px solid var(--line); }
.rule-field .rank { font: 700 1.5rem Georgia, serif; color: var(--gold); padding-top: 8px; text-align: center; }
.rule-field .fields { display: flex; flex-direction: column; gap: 6px; }
.rule-field input[type="text"] { min-height: 44px; }
.sticky-actions { position: sticky; bottom: -20px; background: #1f1b18; padding: 12px 0; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; }

@media (max-width: 480px) {
  .stack-mobile .btn { flex: 1 1 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .card.flip { animation: none; }
  .card, .king-slot { transition: none; }
}
