/* Trang xem trận - cùng phong cách tiền sử với trang chủ */
:root {
  --bg: #2a1a0e;
  --bg-2: #3b2614;
  --parchment: #ecdcae;
  --parchment-2: #dcc58a;
  --ink: #3a240f;
  --ink-soft: #6b4a26;
  --wood: #7a4b22;
  --wood-dark: #4e2e12;
  --stone: #8d8579;
  --stone-dark: #5e574d;
  --fire: #e8742a;
  --fire-2: #f4a83a;
  --leaf: #5c8f2a;
  --blood: #b8382a;
  --side0: #f4a83a;
  --side1: #d65a45;
  --font: "Baloo 2", "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  color: var(--parchment);
  background: radial-gradient(ellipse at top, var(--bg-2), var(--bg) 70%) fixed, var(--bg);
}
button { font: inherit; cursor: pointer; }

/* ---------------------------------------------------------------- đầu trang */
.top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 16px;
}
.back {
  color: var(--fire-2);
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}
.back:hover { color: #ffd08a; }
.title { min-width: 0; text-align: center; }
.title .vs { font-size: 1.15rem; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title .vs b:first-child { color: var(--side0); }
.title .vs b:last-child { color: var(--side1); }
.title .x { margin: 0 8px; color: var(--parchment-2); font-weight: 700; font-size: .9rem; }
.title small { display: block; color: var(--parchment-2); font-size: .85rem; }
.mode {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .8rem; font-weight: 800; letter-spacing: .03em;
  white-space: nowrap;
  border: 2px solid var(--stone);
  color: var(--parchment-2);
}
.mode .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--stone); }
.mode.live { border-color: var(--fire); color: var(--fire-2); }
.mode.live .dot { background: var(--fire); animation: blink 1s infinite; }
.mode.replay { border-color: var(--leaf); color: #a6d36f; }
.mode.replay .dot { background: var(--leaf); }
@keyframes blink { 50% { opacity: .2; } }

/* ---------------------------------------------------------------- màn chơi */
.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px 24px;
}
.stage-wrap {
  width: min(100%, 960px, calc((100vh - 250px) * 4 / 3));
  min-width: min(100%, 320px);
  margin: 0 auto;
}
.stage {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #000;
  border: 4px solid var(--wood);
  border-radius: 10px;
  box-shadow: 0 6px 0 var(--wood-dark), 0 12px 30px rgba(0, 0, 0, .5);
  overflow: hidden;
}
.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
  background: rgba(20, 12, 5, .78);
  transition: opacity .3s;
}
.overlay[hidden] { display: none; }
.overlay.result { background: rgba(20, 12, 5, .55); }
.card {
  max-width: 360px;
  padding: 16px 20px;
  text-align: center;
  color: var(--ink);
  background: linear-gradient(180deg, var(--parchment), var(--parchment-2));
  border: 3px solid var(--wood);
  border-radius: 12px;
  box-shadow: 0 4px 0 var(--wood-dark);
}
.card p { margin: 4px 0; }
.card .big { font-size: 1.2rem; font-weight: 800; }
.card .count { font-size: 2.2rem; font-weight: 800; color: var(--blood); font-variant-numeric: tabular-nums; line-height: 1.1; }
.spinner {
  width: 34px; height: 34px;
  margin: 2px auto 8px;
  border: 4px solid rgba(122, 75, 34, .3);
  border-top-color: var(--fire);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.actions:empty { display: none; }
.actions a, .actions button {
  padding: 5px 14px;
  border: none;
  border-radius: 999px;
  font-weight: 800;
  text-decoration: none;
  color: #2d1a08;
  background: linear-gradient(180deg, var(--fire-2), var(--fire));
  box-shadow: 0 2px 0 #2d1a08;
}
.actions .alt { color: #fff3cf; background: linear-gradient(180deg, var(--stone), var(--stone-dark)); }
.pill {
  position: absolute; left: 50%; bottom: 8px;
  transform: translateX(-50%);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: .78rem; font-weight: 700;
  color: var(--parchment);
  background: rgba(20, 12, 5, .75);
  white-space: nowrap;
}
.pill[hidden] { display: none; }

.timeline {
  display: flex; align-items: center; gap: 10px;
  margin-top: 12px;
  font-size: .85rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--parchment-2);
}
.timeline[hidden] { display: none; }
.track { flex: 1; height: 8px; border-radius: 4px; background: rgba(236, 220, 174, .18); overflow: hidden; }
.fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--fire), var(--fire-2)); }
/* xem lại: chọn / kéo trên thanh để tua */
.timeline.seekable { cursor: pointer; touch-action: none; user-select: none; }
.timeline.seekable .track { height: 12px; border-radius: 6px; overflow: visible; position: relative; }
.timeline.seekable .fill { border-radius: 6px; position: relative; }
.timeline.seekable .fill::after {
  content: ""; position: absolute; right: -8px; top: 50%; width: 16px; height: 16px; margin-top: -8px;
  border-radius: 50%; background: var(--parchment); border: 3px solid var(--fire); box-sizing: border-box;
}

/* ---------------------------------------------------------------- nút */
.controls {
  display: grid;
  grid-template-columns: auto auto 1fr;
  grid-template-areas: "sides speed guide";
  align-items: center;
  gap: 12px 20px;
  width: min(100%, 960px);
  margin: 16px auto 0;
}
.sides { grid-area: sides; display: flex; gap: 10px; }
.side {
  display: inline-flex; align-items: center; gap: 8px;
  min-width: 120px; max-width: 220px;
  padding: 8px 16px;
  border: 3px solid var(--wood);
  border-radius: 12px;
  font-weight: 800;
  color: var(--parchment);
  background: var(--bg-2);
  box-shadow: 0 4px 0 var(--wood-dark);
  overflow: hidden;
}
.side span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .sdot { flex: none; width: 12px; height: 12px; border-radius: 50%; }
.side.s0 .sdot { background: var(--side0); }
.side.s1 .sdot { background: var(--side1); }
.side.active { color: var(--ink); border-color: var(--fire); background: linear-gradient(180deg, var(--parchment), var(--parchment-2)); }
.side:active, .dpad button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--wood-dark); }
.speed { grid-area: speed; display: flex; gap: 4px; }
.speed[hidden] { display: none; }
.speed button {
  padding: 6px 12px;
  border: 2px solid var(--stone-dark);
  border-radius: 10px;
  font-weight: 800;
  color: var(--parchment-2);
  background: transparent;
}
.speed button.active { color: #2d1a08; border-color: var(--fire); background: var(--fire-2); }
.guide { grid-area: guide; font-size: .9rem; color: var(--parchment-2); }
.guide p { margin: 2px 0; }
.guide .soft { opacity: .75; font-size: .82rem; }
kbd {
  display: inline-block;
  min-width: 22px;
  margin: 0 1px;
  padding: 0 5px;
  border-radius: 5px;
  font: 700 .8rem var(--font);
  text-align: center;
  color: var(--ink);
  background: var(--parchment);
  box-shadow: 0 2px 0 var(--wood);
}

.dpad {
  grid-area: dpad;
  display: none;
  grid-template-columns: repeat(3, 62px);
  grid-template-rows: repeat(3, 62px);
  grid-template-areas: ". up ." "left . right" ". down .";
  gap: 6px;
  justify-content: center;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.dpad button {
  border: 3px solid var(--wood);
  border-radius: 14px;
  font-size: 1.4rem;
  color: var(--parchment);
  background: var(--bg-2);
  box-shadow: 0 4px 0 var(--wood-dark);
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.dpad button.on { color: var(--ink); background: var(--fire-2); }
.dpad .up { grid-area: up; }
.dpad .down { grid-area: down; }
.dpad .left { grid-area: left; }
.dpad .right { grid-area: right; }

/* điện thoại / máy tính bảng cảm ứng: màn chơi ở trên, nút ở dưới */
@media (hover: none) and (pointer: coarse), (max-width: 700px) {
  .stage-wrap { width: 100%; }
  .controls {
    grid-template-columns: 1fr;
    grid-template-areas: "sides" "speed" "dpad";
    justify-items: center;
  }
  .sides { width: 100%; }
  .side { flex: 1; max-width: none; min-width: 0; justify-content: center; }
  .dpad { display: grid; }
  .guide { display: none; }
}
@media (max-width: 480px) {
  .top { padding: 8px 12px; gap: 4px 8px; grid-template-columns: auto 1fr auto; }
  .top .mode { grid-column: 1 / -1; justify-self: center; font-size: .72rem; padding: 1px 9px; }
  .top::after { content: ""; width: 1.3rem; grid-row: 1; grid-column: 3; }
  .back span { display: none; }
  .back { font-size: 1.3rem; }
  .main { padding: 0 12px 20px; }
  .stage { border-width: 3px; }
  .dpad { grid-template-columns: repeat(3, 58px); grid-template-rows: repeat(3, 58px); }
}
