:root {
  --bg: #123524;
  --bg-2: #0d2a1b;
  --panel: #16391f;
  --panel-2: #1d4527;
  --panel-3: #24522f;
  --ink: #f3f7f0;
  --ink-dim: #b9c9b6;
  --accent: #f4c542;
  --accent-ink: #3a2a00;
  --red: #e0273f;
  --green: #8bc63e;
  --purple: #6b3fa0;
  --danger: #e0273f;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 24px rgba(0,0,0,0.35);
  --tap: 46px; /* minimum comfortable touch target */
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  /* Real rendered height of .action-bar (bell button + its padding) at the
     mobile breakpoint - .game-wrap reserves exactly this much bottom
     padding so the fixed bar can never overlap content above it. Bumped in
     the min-width:480px query when the bell button grows. */
  --action-bar-h: 138px;

  /* Custom Scrollbar Tokens */
  --scrollbar-thumb: #2c5a3a;
  --scrollbar-thumb-hover: #418256;
  --scrollbar-track: rgba(13, 42, 27, 0.6);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

/* Custom Scrollbar WebKit Styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
  background-clip: padding-box;
}
::-webkit-scrollbar-corner {
  background: transparent;
}

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(ellipse at top, var(--bg) 0%, var(--bg-2) 70%);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  overscroll-behavior-y: none;
}

button, input, select {
  font-family: inherit;
  -webkit-user-select: none;
  user-select: none;
}
input, select { -webkit-user-select: text; user-select: text; }

.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-t)) 16px 12px;
}

.brand { font-size: clamp(1.3rem, 4vw, 1.6rem); font-weight: 800; letter-spacing: 0.5px; }
.brand-hal { color: var(--accent); }
.brand-gal { color: var(--red); }

.who { color: var(--ink-dim); font-size: 0.9rem; }

main#app {
  display: flex;
  justify-content: center;
  padding: 6px 14px 40px;
}

.screen { display: none; width: 100%; }
.screen.active { display: block; }
#screen-game.active { display: flex; flex-direction: column; min-height: calc(100vh - 64px - var(--safe-t)); }

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin: 0 auto;
  width: 100%;
}
.panel.narrow { max-width: 420px; }
.panel.wide { max-width: 900px; }
.panel.center { text-align: center; }
.panel.center-v { margin-top: 8vh; }

h1 { margin: 0 0 8px; font-size: clamp(1.3rem, 4vw, 1.6rem); }
h2 { font-size: 1.05rem; color: var(--ink-dim); margin: 22px 0 10px; }
.muted { color: var(--ink-dim); font-size: 0.92rem; }
.label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.6px; }

input[type=text], input:not([type]) {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid #2c5a3a;
  background: var(--bg-2);
  color: var(--ink);
  font-size: 1rem;
  outline: none;
}
input:focus { border-color: var(--accent); }

.btn {
  min-height: var(--tap);
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--panel-2);
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:hover { background: #235433; }
.btn:active { transform: scale(0.96); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #ffd766; }
.btn.bot-btn {
  background: linear-gradient(135deg, #e0273f, #c0152b);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(224, 39, 63, 0.35);
}
.btn.bot-btn:hover {
  background: linear-gradient(135deg, #c81e34, #a00e21);
  box-shadow: 0 4px 16px rgba(224, 39, 63, 0.5);
}
.btn.big { width: 100%; font-size: 1.05rem; padding: 14px 18px; }
.btn.danger { background: var(--red); color: #fff; }
.btn.danger:hover { background: #ff4a61; }
.btn.small { min-height: 38px; padding: 7px 12px; font-size: 0.85rem; }
.btn.tiny { min-height: 32px; padding: 5px 10px; font-size: 0.78rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border-radius: 50%;
  border: none;
  background: var(--panel-2);
  color: var(--ink);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.icon-btn:active { transform: scale(0.92); }

#form-name { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }

/* ---------- Lobby ---------- */
.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 16px;
  border-bottom: 1px solid #234b30;
}
.quickmatch-box { display: flex; flex-direction: column; gap: 8px; }
.qm-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.qm-buttons .btn { flex: 1; min-width: 60px; }
.join-code-form { display: flex; gap: 8px; }
.join-code-form input { flex: 1; }

.queue-banner {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel-2);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
}
#queue-text { flex: 1; }
.queue-spinner {
  width: 18px;
  height: 18px;
  flex: none;
  border: 3px solid rgba(244, 197, 66, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: queue-spin 0.8s linear infinite;
}
@keyframes queue-spin {
  to { transform: rotate(360deg); }
}

/* Scrolls internally once a section gets tall (many rooms) instead of
   growing the whole page - keeps the lobby's overall height stable. */
.room-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(340px, 42vh);
  overflow-y: auto;
  padding-right: 4px;
}
.room-search { margin: 4px 0 18px; }
.room-search input { width: 100%; }
.room-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel-2);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
}
.room-row .r-name { font-weight: 700; word-break: break-word; }
.room-row .r-host { color: var(--ink-dim); font-size: 0.85rem; display: block; }
.room-row > div:first-child { min-width: 0; }
.room-row > div:last-child { display: flex; align-items: center; gap: 8px; flex: none; }
.room-empty { color: var(--ink-dim); padding: 20px 0; text-align: center; }

/* ---------- Room ---------- */
.room-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.room-meta { display: flex; align-items: center; gap: 10px; margin-top: 4px; flex-wrap: wrap; }
.badge {
  background: var(--panel-2);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 0.78rem;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.room-code code { background: var(--bg-2); padding: 2px 8px; border-radius: 6px; }
.room-header-actions { display: flex; gap: 8px; flex: none; }

.player-list { list-style: none; margin: 20px 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.player-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel-2);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  flex-wrap: wrap;
}
.player-name { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.player-name svg { width: 16px; height: 16px; color: var(--accent); flex: none; }
.player-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.room-footer { display: flex; flex-direction: column; align-items: stretch; gap: 10px; }
.room-footer .muted { text-align: center; }

/* ---------- Game ---------- */
.game-wrap { flex: 1; display: flex; flex-direction: column; padding-bottom: calc(var(--action-bar-h) + var(--safe-b)); }
.game-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.turn-banner { flex: 1; min-width: 0; text-align: center; }
.turn-indicator {
  font-weight: 700;
  font-size: clamp(0.95rem, 3.6vw, 1.1rem);
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.turn-timer {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 800;
  font-size: 0.95rem;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--ink-dim);
  flex: none;
}
.turn-timer svg { width: 15px; height: 15px; }
.turn-timer.low { color: #fff; background: var(--red); animation: pulse 0.6s ease infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }

.pot-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--ink-dim);
}
.pot-banner .pot-count { color: var(--accent); font-weight: 800; }

.seats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.seat {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  border: 2px solid transparent;
  position: relative;
  transition: border-color 0.2s ease, opacity 0.2s ease;
  min-width: 0;
}
.seat.turn { border-color: var(--accent); }
.seat.me { background: var(--panel-3); }
.seat.eliminated { opacity: 0.4; }
.seat-header { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 8px; }
.seat-name {
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
}
.seat-name svg { width: 13px; height: 13px; color: var(--accent); flex: none; }
.deck-count { font-size: 0.72rem; color: var(--ink-dim); flex: none; }
.timeout-badge {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--red);
  background: rgba(224,39,63,0.15);
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 4px;
}
.seat-cards { display: flex; gap: 7px; align-items: center; justify-content: center; }

/* The face-up .card is what players actually need to read at a glance (the
   fruit/count that matters for spotting a sum of 5), so it gets most of the
   size increase; .card-back is just the hidden-deck indicator and stays
   closer to its original size to leave room for the bigger face-up card
   without forcing the seat grid down to one column on common phone widths. */
.card {
  width: 72px;
  height: 100px;
  background: #fbf6e8;
  border-radius: 9px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  flex: none;
}
.card .card-fruits {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2px;
  width: 52px;
  height: 62px;
  align-content: center;
  justify-items: center;
}
.card .card-fruits svg { width: 19px; height: 19px; }
.card .card-count {
  position: absolute;
  bottom: 4px;
  right: 6px;
  font-size: 0.68rem;
  font-weight: 800;
  color: #333;
}
.card-back {
  width: 46px;
  height: 64px;
  border-radius: 8px;
  background: repeating-linear-gradient(45deg, #245a34, #245a34 6px, #1a4327 6px, #1a4327 12px);
  border: 2px solid #f4c542;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: var(--accent);
  font-size: 0.56rem;
  text-align: center;
  flex: none;
}
.card-empty {
  width: 72px;
  height: 100px;
  border: 2px dashed #2c5a3a;
  border-radius: 9px;
  flex: none;
}

/* Fixed bottom action bar - keeps Flip/Bell reachable with a thumb on any
   phone size, regardless of how tall the seat grid above gets. Fixed
   (rather than sticky) so it can never end up layered over content -
   .game-wrap reserves matching bottom padding below. */
.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 18px;
  padding: 14px 16px calc(14px + var(--safe-b));
  background: linear-gradient(to top, var(--bg-2) 75%, transparent);
}
.flip-btn { font-size: 1rem; padding: 14px 22px; flex: 1; max-width: 220px; }
/* Bell always hugs the right edge, whether or not the Flip button is
   present - otherwise a lone bell would re-center itself when Flip hides
   (not your turn), making it jump around exactly like the wobble did. */
.bell-wobble { margin-left: auto; }
.bell-wobble { flex: none; }
.spectator-badge {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--ink-dim);
  font-weight: 700;
  font-size: 0.9rem;
}
.bell-btn {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 35% 30%, #ffe27a, var(--accent) 60%, #c98f10 100%);
  box-shadow: 0 6px 0 #a97a10, 0 10px 18px rgba(0,0,0,0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
  touch-action: manipulation;
}
.bell-btn svg { width: 46px; height: 46px; color: var(--accent-ink); }
.bell-btn:active {
  transform: translateY(5px);
  box-shadow: 0 1px 0 #a97a10, 0 3px 8px rgba(0,0,0,0.4);
}
.bell-btn.flash-correct { animation: flashGreen 0.5s ease; }
.bell-btn.flash-wrong { animation: flashRed 0.5s ease; }
@keyframes flashGreen { 0% { box-shadow: 0 0 0 0 rgba(139,198,62,0.9), 0 6px 0 #a97a10; } 100% { box-shadow: 0 0 0 34px rgba(139,198,62,0), 0 6px 0 #a97a10; } }
@keyframes flashRed { 0% { box-shadow: 0 0 0 0 rgba(224,39,63,0.9), 0 6px 0 #a97a10; } 100% { box-shadow: 0 0 0 34px rgba(224,39,63,0), 0 6px 0 #a97a10; } }

/* PC-only keyboard shortcut hint - hidden by default (mobile has no
   keyboard); shown at the same width breakpoint the rest of the desktop
   layout kicks in at. */
.kbd-hints { display: none; }

.event-log {
  margin-top: auto;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 8px 14px;
  height: 96px;
  overflow-y: auto;
  font-size: 0.8rem;
  color: var(--ink-dim);
  display: flex;
  flex-direction: column;
}
.event-log div { padding: 3px 0; border-bottom: 1px solid #1d4527; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.scores { text-align: left; margin: 16px 0; padding-left: 24px; }
.scores li { margin: 4px 0; }
.gameover-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }

#modal-create .panel { text-align: left; }
.field { display: block; margin: 14px 0 4px; font-size: 0.88rem; color: var(--ink-dim); }
.field input, .field select { margin-top: 6px; }
.row { display: flex; align-items: center; gap: 8px; margin: 14px 0; font-size: 0.92rem; }
.row input { width: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
select {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid #2c5a3a;
  background: var(--bg-2);
  color: var(--ink);
}

.toast {
  position: fixed;
  /* Clears the fixed action bar on the game screen too - a plain 20px
     offset would render error toasts underneath the Flip/Bell buttons. */
  bottom: calc(var(--action-bar-h) + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 100;
  text-align: center;
}
.toast.toast-error { background: var(--red); }
.toast.toast-success { background: #3a8a3f; }

@media (min-width: 480px) {
  main#app { padding: 20px 16px 40px; }
  .lobby-actions { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; }
  .quickmatch-box { flex-direction: row; }
  .btn.big { width: auto; }
  .room-footer { flex-direction: row; align-items: center; }
  .room-footer .muted { text-align: left; }
  .bell-btn { width: 120px; height: 120px; }
  .bell-btn svg { width: 56px; height: 56px; }
  :root { --action-bar-h: 162px; }
}

@media (min-width: 700px) {
  .kbd-hints {
    display: block;
    text-align: center;
    color: var(--ink-dim);
    font-size: 0.82rem;
    margin: -4px 0 12px;
  }
  .seats { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
  .seat-cards { gap: 10px; }
  .card { width: 96px; height: 134px; }
  .card .card-fruits { width: 70px; height: 82px; }
  .card .card-fruits svg { width: 27px; height: 27px; }
  .card .card-count { bottom: 5px; right: 8px; font-size: 0.82rem; }
  .card-back { width: 64px; height: 90px; font-size: 0.62rem; }
  .card-empty { width: 96px; height: 134px; }
  .event-log { max-width: 560px; margin-left: auto; margin-right: auto; height: 130px; }
}

/* Bot difficulty selector styling */
#modal-bot .panel { text-align: left; }
.bot-difficulty-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0;
}
.bot-diff-option {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid #2c5a3a;
  background: var(--bg-2);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.bot-diff-option:hover {
  border-color: var(--accent);
  background: rgba(139, 198, 62, 0.08);
}
.bot-diff-option input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}
.diff-card {
  display: flex;
  flex-direction: column;
}
.diff-title {
  font-weight: 700;
  color: var(--ink);
  font-size: 0.95rem;
}
.diff-desc {
  font-size: 0.8rem;
  color: var(--ink-dim);
  margin-top: 2px;
}

/* Anti-Cheat Modal Styling */
#modal-anticheat .panel { text-align: left; }
.ac-modal-title { color: var(--red); display: flex; align-items: center; gap: 8px; }
.anticheat-details {
  background: var(--bg-2);
  border: 1px solid #e0273f;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ac-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.95rem;
  color: var(--ink);
}
.ac-row strong { color: var(--red); font-size: 1.1rem; }
.ac-section { display: flex; flex-direction: column; gap: 6px; }
.ac-label { font-size: 0.85rem; font-weight: 700; color: var(--ink-dim); }
.ac-list {
  margin: 0;
  padding-left: 18px;
  font-size: 0.84rem;
  color: #ff8093;
}
.ac-list li { margin: 4px 0; line-height: 1.35; }
.ac-samples {
  font-family: monospace;
  font-size: 0.85rem;
  background: rgba(0,0,0,0.3);
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--accent);
  word-break: break-all;
}

