/* Burn — functional table styling (TASK-003). Visual polish is Task 4. */

:root {
  --bg: #17110c;
  --felt: #1f3b2c;
  --felt-edge: #14281e;
  --ink: #f3e7d3;
  --muted: #b9a88f;
  --accent: #ff7a1a;
  --accent-2: #ffb347;
  --danger: #e2483d;
  --ok: #5fc37a;
  --card-w: 50px;
  --card-h: 72px;
  --mini-w: 24px;
  --mini-h: 34px;
  --stage-w: 300px;
  --stage-h: 150px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

@media (min-width: 720px) {
  :root {
    --card-w: 64px;
    --card-h: 92px;
    --mini-w: 32px;
    --mini-h: 46px;
    --stage-w: 360px;
    --stage-h: 180px;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: radial-gradient(circle at 50% 20%, #2a1c12, var(--bg) 70%); min-height: 100vh; }
.hidden { display: none !important; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- buttons */
.btn {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: #3a2a1d;
  border: 1px solid #6b5038;
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, opacity 0.15s;
}
.btn:hover:not(:disabled) { background: #4a3626; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: #ffa35c; color: #1b0f05; }
.btn.primary:hover:not(:disabled) { background: #ff8c3a; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 6px 10px; font-size: 0.9rem; }
.btn.big { font-size: 1.15rem; padding: 12px 28px; }

/* ----------------------------------------------------------- start screen */
.screen.start { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.start-card { text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center; max-width: 360px; width: 100%; }
.logo { font-size: 3.5rem; }
.start-card h1 { font-size: 3rem; margin: 0; letter-spacing: 0.04em; }
.tagline { margin: 0; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.field-label { color: var(--muted); font-size: 0.95rem; }
.seg { display: flex; gap: 8px; }
.seg button {
  font: inherit; font-weight: 700; font-size: 1.2rem;
  width: 52px; height: 52px; border-radius: 12px;
  border: 1px solid #6b5038; background: #2a1e15; color: var(--ink); cursor: pointer;
}
.seg button[aria-pressed='true'] { background: var(--accent); color: #1b0f05; border-color: #ffa35c; }

/* ------------------------------------------------------------ game screen */
.screen.game { max-width: 980px; margin: 0 auto; padding: 8px 10px 24px; display: flex; flex-direction: column; gap: 8px; }
.topbar { display: flex; align-items: center; justify-content: space-between; }
.topbar .title { font-weight: 800; font-size: 1.15rem; }

.arena {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas: 'top' 'stage';
  gap: 8px;
  justify-items: center;
  align-items: center;
  background: radial-gradient(ellipse at center, var(--felt), var(--felt-edge));
  border-radius: 18px;
  padding: 10px 8px;
  border: 1px solid #0d1c14;
}
.arena[data-sides='yes'] {
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas: 'top top top' 'left stage right';
}
.opp-top { grid-area: top; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.opp-side.left { grid-area: left; justify-self: end; }
.opp-side.right { grid-area: right; justify-self: start; }
.arena[data-sides='no'] .opp-side { display: none; }

/* ------------------------------------------------------------------ seats */
.seat {
  background: rgba(0, 0, 0, 0.25);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 6px 8px;
  transition: border-color 0.2s, box-shadow 0.2s, opacity 0.2s;
}
.seat.active { border-color: var(--accent-2); box-shadow: 0 0 14px rgba(255, 179, 71, 0.55); }
.seat.target { border-color: var(--danger); box-shadow: 0 0 16px rgba(226, 72, 61, 0.75); }
.seat.is-out { opacity: 0.5; }
.seat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; font-size: 0.9rem; }
.seat-head .name { font-weight: 700; }
.count { color: var(--muted); font-variant-numeric: tabular-nums; }
.badge { font-size: 0.75rem; font-weight: 700; padding: 2px 6px; border-radius: 6px; }
.badge.out { background: var(--ok); color: #082010; }
.badge.burned { background: var(--danger); color: #fff; }
.slots { display: flex; gap: 4px; }

/* ------------------------------------------------------------------ cards */
.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 7px;
  flex: none;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}
.card.face {
  background: #fdfaf3;
  color: #1c1c1c;
  border: 1px solid #c9bfae;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.card.face.red { color: #c3271f; }
.card .rank { font-weight: 800; font-size: calc(var(--card-w) * 0.4); }
.card .suit { font-size: calc(var(--card-w) * 0.34); }
.card .tag {
  position: absolute; bottom: 3px; left: 0; right: 0; text-align: center;
  font-size: calc(var(--card-w) * 0.16); font-weight: 700; color: #a2400a; text-transform: uppercase; letter-spacing: 0.02em;
}
.card.back {
  background: repeating-linear-gradient(45deg, #8a2a10 0 6px, #a8381a 6px 12px);
  border: 2px solid #f0d9b5;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}
.card.empty { border: 2px dashed rgba(243, 231, 211, 0.22); background: transparent; }

.card.tappable { cursor: pointer; }
.card.tappable:hover { transform: translateY(-3px); }
.card.selected { transform: translateY(-8px); outline: 3px solid var(--accent); outline-offset: 1px; box-shadow: 0 6px 14px rgba(255, 122, 26, 0.5); }
.card.back.tappable { outline: 2px dashed var(--accent-2); outline-offset: 2px; }
.card.sacrifice { outline: 3px dashed var(--danger); outline-offset: 2px; cursor: pointer; animation: pulse 1s infinite alternate; }
.card { transition: transform 0.12s; }

/* A table slot: face-down underneath, its face-up on top, nudged so both read. */
.slot { position: relative; width: calc(var(--card-w) + 6px); height: calc(var(--card-h) + 8px); flex: none; }
.slot .under { position: absolute; left: 0; top: 0; }
.slot .over { position: absolute; left: 6px; top: 8px; }
.slot.mini { width: calc(var(--mini-w) + 3px); height: calc(var(--mini-h) + 4px); }
.slot.mini .card { width: var(--mini-w); height: var(--mini-h); border-radius: 4px; }
.slot.mini .over { left: 3px; top: 4px; }
.slot.mini .card .rank { font-size: calc(var(--mini-w) * 0.45); }
.slot.mini .card .suit { font-size: calc(var(--mini-w) * 0.38); }
.slot.mini .card .tag { display: none; }
.slot.mini .card.back { border-width: 1px; }

/* ------------------------------------------------- center stage (fixed size) */
.stage {
  grid-area: stage;
  position: relative;
  width: var(--stage-w);
  height: var(--stage-h);
  flex: none;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.stock { position: absolute; left: 14px; top: 12px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.pile { position: absolute; left: calc(14px + var(--card-w) + 28px); top: 12px; width: calc(var(--card-w) + 3 * 20px); }
.fan { position: relative; height: var(--card-h); }
.fan .pile-card { position: absolute; top: 0; left: calc(var(--i) * 20px); }
.fan .pile-card:last-child { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6); }
.label { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 4px; white-space: nowrap; }
.need {
  position: absolute; left: 8px; right: 8px; bottom: 8px; height: 1.3em;
  text-align: center; font-size: 0.85rem; font-weight: 600; color: var(--accent-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.burn-fx {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; font-weight: 900; color: #fff3d0; letter-spacing: 0.06em;
  background: radial-gradient(circle, rgba(255, 140, 30, 0.9), rgba(200, 40, 10, 0.75) 60%, transparent 80%);
  opacity: 0; pointer-events: none;
}
.burn-fx.go { animation: burn 1.1s ease-out; }

/* ----------------------------------------------------------------- banner */
.banner {
  min-height: 3em; /* reserved: two lines at phone width, so nothing below shifts */
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 6px 10px; border-radius: 10px; font-weight: 600; font-size: 0.95rem;
  background: rgba(255, 255, 255, 0.05); color: var(--muted);
}
.banner.mine { background: rgba(255, 179, 71, 0.15); color: var(--accent-2); }
.banner.attack { background: #6d1410; color: #fff; border: 1px solid var(--danger); animation: pulse 0.9s infinite alternate; }
.banner.over { background: rgba(226, 72, 61, 0.25); color: #fff; }

/* -------------------------------------------------------------------- you */
.seat.me { padding: 8px 10px 10px; }
.my-table { display: flex; gap: 10px; justify-content: center; margin-bottom: 10px; }
.hand { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; min-height: calc(var(--card-h) + 10px); padding-top: 8px; }
.hand-empty { color: var(--muted); align-self: center; }

.controls { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.controls .btn { min-width: 120px; }
.msg { min-height: 2.6em; text-align: center; font-size: 0.92rem; padding: 2px 6px; }
.msg.error { color: #ff8a80; font-weight: 600; }
.msg.info { color: var(--muted); }

/* -------------------------------------------------------------------- log */
.log-wrap { background: rgba(0, 0, 0, 0.3); border-radius: 12px; padding: 8px 12px; }
.log-wrap h2 { font-size: 0.95rem; margin: 0 0 6px; }
.log-wrap .hint { color: var(--muted); font-weight: 400; font-size: 0.8rem; }
.log { list-style: none; margin: 0; padding: 0; max-height: 200px; overflow-y: auto; font-size: 0.88rem; }
.log li { padding: 3px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
.log li:first-child { font-weight: 700; color: #fff; }
.log li.burn { color: #ffb347; }
.log li.attack { color: #ff8a80; }
.log li.answer { color: #9ad4ff; }
.log li.pickup { color: #e8c88f; }
.log li.out { color: var(--ok); }
.log li.over { color: var(--danger); font-weight: 700; }

/* ----------------------------------------------------------------- modals */
.modal {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(0, 0, 0, 0.7);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 12px; overflow-y: auto;
}
.modal-card {
  position: relative; background: #2a1e15; border: 1px solid #6b5038; border-radius: 14px;
  padding: 18px 18px 20px; max-width: 560px; width: 100%; margin: auto 0;
}
.modal-card h2 { margin: 0 0 8px; }
.modal-card h3 { margin: 14px 0 4px; font-size: 1rem; color: var(--accent-2); }
.modal-card p, .modal-card li { line-height: 1.4; font-size: 0.95rem; }
.modal-card ul { padding-left: 20px; margin: 4px 0; }
.modal-card > .btn { margin-top: 14px; width: 100%; }
.close { position: absolute; top: 8px; right: 8px; background: none; border: 0; color: var(--ink); font-size: 1.3rem; cursor: pointer; width: 40px; height: 40px; }
.specials { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
.specials th { width: 44px; text-align: center; font-size: 1.2rem; color: var(--accent); vertical-align: top; padding: 6px 4px; }
.specials td { padding: 6px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); line-height: 1.4; }
.end { text-align: center; }
.end-headline { font-size: 1.25rem; font-weight: 800; }
.end-headline.lost { color: var(--danger); }
.end-headline.safe { color: var(--ok); }
.finish { list-style: none; padding: 0; margin: 8px auto; max-width: 280px; text-align: left; }
.finish li { padding: 6px 8px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.finish li.burned { color: var(--danger); font-weight: 700; }
.finish .place { display: inline-block; width: 2.2em; color: var(--muted); }
.end-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }

/* ------------------------------------------------------------- animation */
.shake { animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.25); } }
@keyframes burn {
  0% { opacity: 0; transform: scale(0.6); }
  25% { opacity: 1; transform: scale(1.05); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.15); }
}
@media (prefers-reduced-motion: reduce) {
  .banner.attack, .card.sacrifice { animation: none; }
}
