/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

:root {
  --green:       #2d6a4f;
  --green-light: #40916c;
  --felt:        #1b4332;
  --card-w:      70px;
  --card-h:      100px;
  --card-radius: 8px;
  --red:         #c0392b;
  --gold:        #f4d03f;
  --shadow:      0 4px 12px rgba(0,0,0,.5);
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', sans-serif;
  background: #111;
  color: #eee;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;    /* fallback */
  height: 100dvh;   /* dynamic: adjusts for browser chrome on mobile */
}

/* ── Top bar ──────────────────────────────────────────────── */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0d0d0d;
  padding: 6px 14px;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
  z-index: 10;
}

#game-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold);
}

#title-group { display: flex; align-items: baseline; gap: 10px; }

.back-to-hub {
  font-size: .75rem;
  color: #888;
  text-decoration: none;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
}
.back-to-hub:hover { color: var(--gold); text-decoration: underline; }

/* Hide once installed as a home-screen app -- there's no "back" to a
   browsing session to offer, and it'd break out of the app shell. */
@media (display-mode: standalone), (display-mode: fullscreen), (display-mode: minimal-ui) {
  .back-to-hub { display: none; }
}

#topbar-controls { display: flex; gap: 8px; }

#topbar-controls button {
  background: #222;
  border: 1px solid #444;
  color: #ccc;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: .85rem;
}
#topbar-controls button:hover { background: #333; }

/* ── Table ────────────────────────────────────────────────── */
#table {
  flex: 1;
  min-height: 0;   /* allow grid container to shrink as a flex item */
  overflow: hidden;
  background: radial-gradient(ellipse at center, var(--green-light) 0%, var(--felt) 60%, #0f2418 100%);
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: minmax(0,1fr) minmax(0,1fr) minmax(0,1fr);
  /* seats snap to corners/edges; center cell = play area */
}

/* ── Seats ────────────────────────────────────────────────── */
.seat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px;
  gap: 4px;
  overflow: hidden;
  min-height: 0;
}

.seat-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.seat-name {
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #ccc;
}

.seat-role { font-size: .65rem; }

.seat-style {
  font-size: .58rem;
  text-transform: capitalize;
  letter-spacing: .5px;
  opacity: .6;
  margin-top: -2px;
}
.seat-style-conservative { color: #60a5fa; }
.seat-style-neutral       { color: #9ca3af; }
.seat-style-aggressive    { color: #f87171; }

.seat-cards {
  display: flex;
  gap: -8px;
}

/* Face-down AI cards */
.card-back {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--card-radius);
  background: repeating-linear-gradient(135deg, #1a237e 0px, #1a237e 8px, #283593 8px, #283593 16px);
  border: 2px solid rgba(255,255,255,0.18);
  box-shadow: var(--shadow);
  margin-left: -20px;
  position: relative;
}
.card-back:first-child { margin-left: 0; }

/* Side seats — anchor to top; card-back is a sibling of seat-inner, not nested */
#seat-mid-left,
#seat-mid-right,
#seat-bot-left {
  justify-content: flex-start;
}

/* First card-back directly in side seat: no margin */
#seat-mid-left > .card-back,
#seat-mid-right > .card-back,
#seat-bot-left > .card-back {
  margin-top: 0;
  margin-left: 0;
}

/* Subsequent card-backs overlap the one above */
#seat-mid-left > .card-back ~ .card-back,
#seat-mid-right > .card-back ~ .card-back,
#seat-bot-left > .card-back ~ .card-back {
  margin-top: -30px;
}


/* Inner decorative frame */
.card-back::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 3px;
  pointer-events: none;
}

/* Card back colour variants */
.card-back--blue  { background: repeating-linear-gradient(135deg, #1a237e 0px, #1a237e 8px, #283593 8px, #283593 16px); border-color: rgba(255,255,255,0.18); }
.card-back--red   { background: repeating-linear-gradient(135deg, #7f1d1d 0px, #7f1d1d 8px, #991b1b 8px, #991b1b 16px); border-color: rgba(255,255,255,0.18); }
.card-back--green { background: repeating-linear-gradient(135deg, #14532d 0px, #14532d 8px, #166534 8px, #166534 16px); border-color: rgba(255,255,255,0.18); }
.card-back--dark  { background: repeating-linear-gradient(135deg, #0f172a 0px, #0f172a 8px, #1e293b 8px, #1e293b 16px); border-color: rgba(255,255,255,0.12); }
.card-back--gold  { background: repeating-linear-gradient(135deg, #78350f 0px, #78350f 8px, #9a3412 8px, #9a3412 16px); border-color: rgba(251,191,36,0.3); }

/* Card-back picker */
.cb-picker {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.cb-swatch {
  width: 28px;
  height: 40px;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
  transition: transform .1s;
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
}
.cb-swatch::before {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 2px;
}
.cb-swatch:hover { transform: translateY(-2px); }
.cb-swatch.active { border-color: var(--gold); box-shadow: 0 0 8px rgba(244,208,63,.55); }

/* Show card count badge on back of first AI card */
.card-back.count-badge::after {
  content: attr(data-count);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: #ffffffcc;
}

/* Active player highlight */
.seat.active .seat-inner {
  outline: 2px solid var(--gold);
  border-radius: 8px;
  padding: 4px 8px;
}

/* ── Play area (center) ───────────────────────────────────── */
#play-area {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#pile-label {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #aaa;
}

#pile {
  display: flex;
  gap: 6px;
  min-height: calc(var(--card-h) + 8px);
  align-items: center;
  justify-content: center;
}

#round-info {
  font-size: .8rem;
  color: #bbb;
  text-align: center;
  min-height: 1.2em;
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--card-radius);
  background: #fff;
  border: 1.5px solid #ccc;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 4px 5px;
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: transform .15s, box-shadow .15s;
}

.card:hover { transform: translateY(-6px); box-shadow: 0 8px 20px rgba(0,0,0,.6); }

.card.selected {
  transform: translateY(-14px);
  box-shadow: 0 12px 24px rgba(0,0,0,.7);
  outline: 2px solid var(--gold);
}

.card.red .card-value, .card.red .card-suit { color: var(--red); }
.card.black .card-value, .card.black .card-suit { color: #111; }

.card-value {
  font-size: .9rem;
  font-weight: 700;
  line-height: 1;
}

.card-suit {
  font-size: 1.6rem;
  line-height: 1;
  text-align: center;
  margin: auto 0;
}

.card-value-bottom {
  font-size: .9rem;
  font-weight: 700;
  line-height: 1;
  align-self: flex-end;
  transform: rotate(180deg);
}

/* Dimmed ghost of last played cards when pile is empty */
.card.last-play {
  opacity: 0.3;
  filter: grayscale(40%);
  cursor: default;
}

/* 2s get a special glow */
.card.trump {
  background: linear-gradient(135deg, #fffde7, #fff9c4);
  border-color: #f9a825;
  box-shadow: 0 0 12px #f9a82588, var(--shadow);
}

/* ── Player zone ──────────────────────────────────────────── */
#player-zone {
  background: linear-gradient(to top, #0d0d0d 60%, transparent);
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  position: relative;
}

#auto-pass-msg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 20, 10, 0.92);
  border: 1px solid #4ade80;
  color: #4ade80;
  padding: 8px 22px;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 600;
  letter-spacing: .5px;
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
}
#auto-pass-msg.hidden { display: none; }

#player-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.trick-leader-star {
  color: var(--gold);
  font-size: .85rem;
  line-height: 1;
}
.trick-leader-star:empty { display: none; }

#player-name {
  font-size: .85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.role-badge {
  font-size: .7rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.role-president  { background: var(--gold); color: #333; }
.role-wiper      { background: #7f1d1d; color: #fca5a5; }
.role-vp         { background: #78716c; color: #e7e5e4; }
.role-vw         { background: #44403c; color: #a8a29e; }
.role-neutral    { background: #374151; color: #9ca3af; }

#hand {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  max-width: 100%;
}

/* Fan/overlap the hand if many cards */
#hand .card { margin-left: -10px; }
#hand .card:first-child { margin-left: 0; }

/* ── Action bar ───────────────────────────────────────────── */
#action-bar {
  display: flex;
  gap: 12px;
}

.action-btn {
  padding: 8px 28px;
  border: none;
  border-radius: 6px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
  letter-spacing: .5px;
}
.action-btn:disabled { opacity: .4; cursor: not-allowed; transform: none !important; }
.action-btn:not(:disabled):hover { transform: translateY(-2px); }
.action-btn:not(:disabled):active { transform: translateY(0); }

.action-btn { background: #374151; color: #d1d5db; }
.action-btn.primary { background: #166534; color: #bbf7d0; }
.action-btn.large { padding: 12px 48px; font-size: 1.1rem; }

/* ── Modals ───────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }

.modal-box {
  background: #1c1c1e;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 28px 36px;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-box h1 { font-size: 2.5rem; color: var(--gold); text-align: center; letter-spacing: 4px; }
.modal-box h2 { font-size: 1.3rem; color: #ddd; }
.subtitle { text-align: center; color: #888; font-size: .9rem; letter-spacing: 2px; }

.modal-box label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: .85rem;
  color: #aaa;
}

.modal-box label select {
  background: #2a2a2e;
  border: 1px solid #444;
  color: #eee;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: .9rem;
}

.toggle-row {
  flex-direction: row !important;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px !important;
}

.toggle-hint {
  font-size: .7rem;
  color: #666;
  width: 100%;
}

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

.names-heading {
  font-size: .85rem;
  color: #aaa;
  margin-bottom: 6px;
}

#ai-names-grid, #role-names-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#setting-game-name {
  background: #2a2a2e;
  border: 1px solid #444;
  color: #eee;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: .9rem;
  width: 100%;
}
#setting-game-name:focus { outline: none; border-color: var(--gold); }

.name-row {
  flex-direction: row !important;
  align-items: center;
  gap: 6px !important;
  font-size: .8rem !important;
  color: #666 !important;
  white-space: nowrap;
}

.name-row input[type="text"] {
  flex: 1;
  background: #2a2a2e;
  border: 1px solid #444;
  color: #eee;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: .85rem;
  min-width: 0;
}

.name-row input[type="text"]:focus {
  outline: none;
  border-color: var(--gold);
}

.trade-label {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #777;
  margin-top: 12px;
  margin-bottom: 6px;
}

#trading-received-cards,
#trading-give-cards,
#kitty-cards,
#kitty-hand-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#trading-give-cards .card { cursor: pointer; }

#modal-trading .modal-box,
#modal-kitty .modal-box {
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}

/* Brighten player hand while hold-swap dialog is open */
body:has(#modal-hold:not(.hidden)) #player-zone {
  filter: brightness(1.6);
}

/* Hold modal: lighter overlay + anchored to top so hand is visible below */
#modal-hold {
  background: rgba(0, 0, 0, 0.55);
  align-items: flex-start;
  padding-top: 24px;
}
#modal-hold .modal-box {
  max-width: 360px;
}

#kitty-swap-info {
  text-align: center;
  font-size: .8rem;
  color: #888;
  min-height: 1.2em;
}

#trading-desc {
  color: #aaa;
  font-size: .85rem;
  line-height: 1.5;
}

/* ── Round-end results ────────────────────────────────────── */
.roundend-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0;
}

.roundend-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.roundend-pos {
  font-size: .75rem;
  color: #666;
  width: 26px;
  text-align: right;
  flex-shrink: 0;
}

.roundend-name {
  flex: 1;
  font-size: .9rem;
  font-weight: 600;
  color: #eee;
}

/* Conquest score columns */
.roundend-delta {
  font-size: .8rem;
  font-weight: 600;
  min-width: 32px;
  text-align: right;
  flex-shrink: 0;
  color: #666;
}
.roundend-delta.pos { color: #4ade80; }
.roundend-delta.neg { color: #f87171; }

.roundend-total {
  font-size: .85rem;
  font-weight: 600;
  min-width: 34px;
  text-align: right;
  flex-shrink: 0;
  color: #aaa;
  font-variant-numeric: tabular-nums;
}
.roundend-total.conquest-leader { color: var(--gold); }

.conquest-info {
  font-size: .72rem;
  color: #666;
  padding: 2px 0;
  line-height: 1.4;
}

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.modal-actions button {
  padding: 6px 20px;
  background: #2a2a2e;
  border: 1px solid #444;
  color: #ccc;
  border-radius: 6px;
  cursor: pointer;
}
.modal-actions button:hover { background: #333; }

/* ── Notifications ────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 160px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  border: 1px solid #374151;
  color: #f3f4f6;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: .85rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s;
  z-index: 200;
}
#toast.show { opacity: 1; }

/* ── Rules modal ──────────────────────────────────────────── */
.rules-box {
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  gap: 0;
}

.rules-section {
  padding: 14px 0;
  border-top: 1px solid #2a2a2e;
}
.rules-section:first-of-type { border-top: none; padding-top: 4px; }

.rules-section h3 {
  font-size: .8rem;
  font-weight: 700;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 8px;
}

.rules-section p,
.rules-section ul {
  font-size: .83rem;
  color: #aaa;
  line-height: 1.65;
}

.rules-section ul {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.rules-opt {
  color: #ddd;
  font-weight: 600;
}

/* ── Confetti ─────────────────────────────────────────────── */
@keyframes confetti-cw {
  0%   { transform: translateY(0) rotate(0deg);     opacity: 1; }
  85%  { opacity: 1; }
  100% { transform: translateY(110vh) rotate(540deg);  opacity: 0; }
}
@keyframes confetti-ccw {
  0%   { transform: translateY(0) rotate(0deg);     opacity: 1; }
  85%  { opacity: 1; }
  100% { transform: translateY(110vh) rotate(-540deg); opacity: 0; }
}
.confetti-piece {
  position: fixed;
  top: -14px;
  pointer-events: none;
  z-index: 300;
  animation-fill-mode: forwards;
  animation-timing-function: linear;
}

/* ── Safe-area inset (notch / home bar) ─────────────────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #player-zone { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}

/* ── Responsive tweaks ────────────────────────────────────── */

/* Mid-size (small tablets / large phones landscape) */
@media (max-width: 600px) {
  :root { --card-w: 54px; --card-h: 78px; }
}

/* Phones portrait */
@media (max-width: 430px) {
  :root {
    --card-w: 46px;
    --card-h: 66px;
    --card-radius: 6px;
  }

  /* Top bar */
  #topbar { padding: 5px 10px; }
  #game-title { font-size: .9rem; letter-spacing: 1px; }
  .back-to-hub { font-size: .65rem; }
  #topbar-controls button { padding: 3px 8px; font-size: .75rem; }

  /* Table seats */
  .seat { padding: 4px 2px; }
  .seat-name { font-size: .6rem; letter-spacing: .5px; }
  .seat-role { font-size: .52rem; padding: 1px 5px; }
  .seat-style { display: none; }

  /* AI card backs — compact */
  .card-back {
    width: 26px;
    height: 38px;
    border-radius: 4px;
    margin-left: -12px;
    border-width: 1.5px;
  }
  .card-back:first-child { margin-left: 0; }
  .card-back::before { inset: 3px; }
  .card-back.count-badge::after { font-size: .95rem; }

  /* Play area */
  #pile-label { font-size: .6rem; }
  #round-info { font-size: .68rem; }

  /* Card face */
  .card { padding: 3px 4px; }
  .card-value, .card-value-bottom { font-size: .75rem; }
  .card-suit { font-size: 1.1rem; }

  /* Player zone */
  #player-zone { padding: 6px 8px 8px; gap: 5px; }
  #player-name { font-size: .75rem; }
  .role-badge { font-size: .6rem; padding: 1px 6px; }

  /* Tighter vertical overlap for small card-backs on side seats */
  #seat-mid-left .card-back,
  #seat-mid-right .card-back,
  #seat-bot-left .card-back { margin-top: -14px; }

  /* Hand — remove negative margin so cards wrap cleanly into rows */
  #hand { gap: 4px; }
  #hand .card { margin-left: 0; }

  /* Action buttons — big tap targets, fill full width */
  #action-bar { gap: 8px; width: 100%; }
  .action-btn { flex: 1; padding: 13px 0; font-size: .95rem; }

  /* Modals — full width, scrollable */
  .modal-box {
    min-width: unset;
    width: calc(100vw - 24px);
    max-height: 88vh;
    overflow-y: auto;
    padding: 20px 16px;
    border-radius: 10px;
  }
  .modal-box h1 { font-size: 1.8rem; letter-spacing: 2px; }

  /* Card back swatches in picker */
  .cb-swatch { width: 22px; height: 32px; }
  .cb-swatch::before { inset: 3px; }
}
