:root {
  --board: #223a33;
  --board-dark: #14241d;
  --chalk: #f4efe1;
  --chalk-dim: #cbc3ae;
  --pimenton: #d9532c;
  --pimenton-dark: #b8431f;
  --oro: #e3b23c;
  --cork: #8a6a4a;
  --radius-sm: 0.6rem;
  --radius: 1rem;
  --radius-lg: 1.4rem;
  --shadow-1: 0 2px 6px rgba(0, 0, 0, 0.25);
  --shadow-2: 0 6px 16px rgba(0, 0, 0, 0.35);
  --font-display: 'Fredoka', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: radial-gradient(ellipse at top, var(--board) 0%, var(--board-dark) 70%);
  color: var(--chalk);
  font-family: var(--font-body);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

button, input {
  font-family: inherit;
  touch-action: manipulation;
}

.screen {
  padding: 1rem 1rem calc(2rem + env(safe-area-inset-bottom));
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
}

h1 {
  font-family: var(--font-display);
  color: var(--chalk);
  font-size: clamp(1.25rem, 5vw, 1.6rem);
  margin: 0;
}

h2 {
  font-family: var(--font-display);
  color: var(--chalk-dim);
  font-size: 1rem;
  margin: 1.5rem 0 0.5rem;
}

/* Top app bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: -1rem -1rem 1rem;
  padding: calc(0.75rem + env(safe-area-inset-top)) 0.75rem 0.75rem;
  background: var(--board-dark);
  box-shadow: var(--shadow-1);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { line-height: 1.15; }
.topbar-meta { font-size: 0.8rem; color: var(--chalk-dim); margin-top: 0.1rem; }

.topbar-action { display: flex; }

.icon-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  background: transparent;
  color: var(--chalk);
  border: none;
  text-decoration: none;
  transition: background 0.15s ease;
}

.icon-button:active { background: rgba(244, 239, 225, 0.15); }

/* Buttons */
.button, button {
  font-size: 1rem;
  padding: 0.7rem 1.1rem;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-weight: 600;
  background: var(--board-dark);
  color: var(--chalk);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  box-shadow: var(--shadow-1);
}

.button:active, button:active { transform: scale(0.96); }

.button-primary {
  background: var(--pimenton);
  color: var(--chalk);
  font-family: var(--font-display);
}

.button-primary:disabled { opacity: 0.4; box-shadow: none; }

a.button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

/* Home */
.hero {
  text-align: center;
  padding: calc(1.5rem + env(safe-area-inset-top)) 0 1rem;
}

.hero-emoji { font-size: 2.5rem; }

.hero h1 { font-size: clamp(1.6rem, 7vw, 2.2rem); margin: 0.25rem 0; }

.hero p { color: var(--chalk-dim); margin: 0 0 1.25rem; }

.game-list { list-style: none; padding: 0; margin: 0; }

.game-item a {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  background: var(--board-dark);
  color: var(--chalk);
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.6rem;
  text-decoration: none;
  border: 1px dashed rgba(244, 239, 225, 0.25);
  box-shadow: var(--shadow-1);
}

.game-item strong { font-family: var(--font-display); font-size: 1.05rem; }
.game-item .game-status { color: var(--oro); font-size: 0.85rem; }
.game-item span:not(.game-status) { color: var(--chalk-dim); font-size: 0.85rem; }

.empty-state {
  text-align: center;
  color: var(--chalk-dim);
  padding: 2rem 1rem;
  border: 1px dashed rgba(244, 239, 225, 0.2);
  border-radius: var(--radius);
}

/* Loading skeleton */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  min-height: 60vh;
  color: var(--chalk-dim);
}

.spinner {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: 4px solid rgba(244, 239, 225, 0.2);
  border-top-color: var(--oro);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Setup */
.field { display: block; margin-bottom: 1rem; }
.field span { display: block; margin-bottom: 0.35rem; color: var(--chalk-dim); font-size: 0.9rem; }

.field input[type="text"] {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(244, 239, 225, 0.25);
  background: var(--board-dark);
  color: var(--chalk);
  font-size: 1rem;
}

.player-row { display: flex; gap: 0.5rem; }
.player-row input { flex: 1; }

.chip-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.75rem 0 1.25rem; }

.chip-list li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--cork);
  color: var(--chalk);
  padding: 0.35rem 0.5rem 0.35rem 0.8rem;
  border-radius: 999px;
  font-size: 0.9rem;
}

.chip-list button {
  background: rgba(0,0,0,0.25);
  color: var(--chalk);
  width: 1.4rem;
  height: 1.4rem;
  min-width: 0;
  min-height: 0;
  border-radius: 50%;
  padding: 0;
  font-size: 0.8rem;
  box-shadow: none;
}

.error { color: var(--pimenton); min-height: 1.2rem; }

/* Game table */
.hint {
  text-align: center;
  color: var(--chalk-dim);
  font-size: 0.85rem;
  margin: 0 0 0.75rem;
}

.table {
  position: relative;
  width: min(90vw, 26rem);
  aspect-ratio: 1;
  background:
    radial-gradient(circle at 50% 50%, rgba(0,0,0,0.15) 0%, transparent 60%),
    var(--board);
  border: 6px solid var(--cork);
  border-radius: 50%;
  margin: 0.5rem auto 1rem;
  box-shadow: var(--shadow-2), inset 0 0 30px rgba(0,0,0,0.4);
}

.seat {
  position: absolute;
  transform: translate(-50%, -50%);
  text-align: center;
  background: rgba(20, 36, 29, 0.75);
  border-radius: var(--radius);
  padding: 0.5rem 0.4rem;
  min-width: 5.2rem;
  border: 1px solid rgba(244, 239, 225, 0.15);
}

.seat-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(0.8rem, 3.2vw, 0.95rem);
}

.seat-total { font-size: 0.75rem; color: var(--oro); margin-top: 0.1rem; }

.seat-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.seat-controls button {
  width: 2.75rem;
  height: 2.75rem;
  min-width: 44px;
  min-height: 44px;
  font-size: 1.3rem;
  background: var(--pimenton);
  color: var(--chalk);
  padding: 0;
}

.seat-value { min-width: 1.6rem; font-size: 1.15rem; font-weight: 700; font-family: var(--font-display); }

/* Pot signature */
.pot {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.pot-emoji { font-size: clamp(1.6rem, 7vw, 2.4rem); }

.pot.shake { animation: pot-shake 0.4s ease; }

@keyframes pot-shake {
  0%, 100% { transform: translate(-50%, -50%) rotate(0deg); }
  25% { transform: translate(-50%, -50%) rotate(-8deg); }
  75% { transform: translate(-50%, -50%) rotate(8deg); }
}

.pot-beans { position: absolute; inset: 0; pointer-events: none; z-index: 2; }

.bean {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0.85rem;
  height: 0.55rem;
  background: var(--oro);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  border: 1px solid rgba(0, 0, 0, 0.3);
  animation: bean-fly 0.7s ease-out forwards;
}

@keyframes bean-fly {
  0% { transform: translate(calc(-50% + var(--sx, 0%)), calc(-50% + var(--sy, 0%))) scale(0.6) rotate(var(--rot, 0deg)); opacity: 0; }
  40% { opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1) rotate(var(--rot, 0deg)); opacity: 1; }
}

.puff {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.3rem;
  animation: puff-rise 0.7s ease-out forwards;
}

@keyframes puff-rise {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  50% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1.3); }
}

/* Speech bubbles */
.seat-bubble {
  --tx: -50%;
  position: absolute;
  bottom: 100%;
  left: 50%;
  margin-bottom: 0.35rem;
  transform: translate(var(--tx), 0);
  background: var(--chalk);
  color: var(--board-dark);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.2;
  padding: 0.4rem 0.7rem;
  border-radius: 0.9rem;
  max-width: min(10.5rem, 60vw);
  text-align: center;
  box-shadow: var(--shadow-1);
  animation: bubble-pop 2.2s ease forwards;
  z-index: 6;
}

.seat-bubble.below { bottom: auto; top: 100%; margin-bottom: 0; margin-top: 0.35rem; }
.seat-bubble.align-left { left: 0; --tx: 0%; }
.seat-bubble.align-right { left: auto; right: 0; --tx: 0%; }

@keyframes bubble-pop {
  0% { opacity: 0; transform: translate(var(--tx), 0) scale(0.85); }
  12% { opacity: 1; transform: translate(var(--tx), 0) scale(1); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--tx), 0) scale(0.95); }
}

.round-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  font-family: var(--font-display);
}

.rounds-strip {
  display: flex;
  gap: 0.4rem;
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.rounds-strip::-webkit-scrollbar { display: none; }

.round-chip {
  background: var(--board-dark);
  color: var(--chalk-dim);
  white-space: nowrap;
  border: 1px solid rgba(244, 239, 225, 0.15);
  box-shadow: none;
  padding: 0.5rem 0.8rem;
}

.round-chip.active { background: var(--oro); color: var(--board-dark); }

/* History / summary */
.status-pill {
  display: inline-block;
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--board-dark);
  color: var(--chalk-dim);
  margin-bottom: 1rem;
}

.ranking { list-style: none; padding: 0; margin: 0 0 1.25rem; }

.ranking li {
  display: flex;
  flex-direction: column;
  background: var(--board-dark);
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
}

.ranking li .rank-line { display: flex; justify-content: space-between; font-family: var(--font-display); }

.ranking .winner { border: 1px solid var(--oro); }
.ranking .winner .rank-line { color: var(--oro); }

.rank-comment {
  font-family: var(--font-body);
  font-weight: 500;
  font-style: italic;
  font-size: 0.9rem;
  color: var(--chalk-dim);
  margin-top: 0.15rem;
}

.rounds-table-wrap { overflow-x: auto; }

.rounds-table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; font-size: 0.9rem; }
.rounds-table th, .rounds-table td {
  border: 1px solid rgba(244, 239, 225, 0.15);
  padding: 0.45rem;
  text-align: center;
}
.rounds-table th { font-family: var(--font-display); color: var(--chalk-dim); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  .bean, .puff, .pot.shake, .seat-bubble, .spinner { animation: none !important; }
}

@media (max-width: 360px) {
  .seat { min-width: 4.4rem; padding: 0.4rem 0.3rem; }
  .seat-controls button { width: 2.4rem; height: 2.4rem; }
}

/* 5+ players: seats get close together on the circle, so trim padding/gaps
   and shrink the buttons a touch (still comfortably tappable) to fit. */
.seat-compact { min-width: 0; padding: 0.35rem 0.25rem; }
.seat-compact .seat-name { font-size: clamp(0.68rem, 2.8vw, 0.8rem); }
.seat-compact .seat-total { font-size: 0.68rem; }
.seat-compact .seat-controls { gap: 0.2rem; margin-top: 0.25rem; }
.seat-compact .seat-controls button { width: 2.3rem; height: 2.3rem; min-width: 0; min-height: 0; font-size: 1.05rem; }
.seat-compact .seat-value { min-width: 1.2rem; font-size: 1rem; }
