/* ============================================================
   Cờ Cá Ngựa — Visual layout
   Fonts: Grenze (logo), Averia Serif Libre (headings), Poppins (body)
   The square size is set on #board-wrap by board.js as --cell and
   --horse, since it depends on how much room there is.

   The board is painted warm and bright, the way a real cá ngựa
   board is; the panel keeps the arcade's dark chrome so the game
   still belongs to the set.
   ============================================================ */

:root {
  --bg: #0f1726;
  --panel: #18233b;
  --panel-line: rgba(255,255,255,0.08);
  --text: #e8eef9;
  --muted: #93a3c0;
  --accent: #10b981;
  --gold: #f4c150;
  --field: #0f1726;

  --c0: #e0403a;   /* red    */
  --c1: #2f9e51;   /* green  */
  --c2: #d9a213;   /* yellow */
  --c3: #2f6fd0;   /* blue   */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Poppins", system-ui, sans-serif;
  font-weight: 300;
  color: var(--text);
  background: radial-gradient(1200px 600px at 50% -10%, #16213a 0%, var(--bg) 60%);
  min-height: 100vh;
}

/* ---------- Header ---------- */
.app-header { text-align: center; padding: 28px 16px 12px; }
.logo {
  font-family: "Grenze", serif; font-weight: 700; font-size: 52px;
  letter-spacing: 1px; margin: 0; color: var(--gold);
  text-shadow: 0 2px 0 #0b1220, 0 0 26px rgba(244, 193, 80, 0.22);
}
.tagline { color: var(--muted); margin: 6px 0 0; letter-spacing: 2px; text-transform: uppercase; font-size: 12px; }
.back-link { color: #f5d98a; font-size: 13px; text-decoration: none; }
.back-link:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.app-main {
  display: flex; gap: 28px; justify-content: center; align-items: flex-start;
  padding: 18px 16px 48px; flex-wrap: wrap;
}

/* ---------- Board ---------- */
.board-panel {
  background: linear-gradient(160deg, #6b4520, #4a2f14);
  padding: 12px; border-radius: 14px; max-width: 100%;
  box-shadow: 0 18px 40px rgba(0,0,0,0.5), inset 0 0 0 2px #8a5a24;
}
.board-wrap { position: relative; border-radius: 6px; overflow: hidden; max-width: 100%; }
.board-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.horse-layer { position: absolute; inset: 0; }

/* ---------- Horses ---------- */
.horse {
  position: absolute;
  width: var(--horse, 26px); height: var(--horse, 26px);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--horse, 26px) * 0.62);
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0,0,0,0.45);
  border: 2px solid rgba(255,255,255,0.85);
  box-shadow: 0 2px 5px rgba(0,0,0,0.4);
  transition: left 0.22s ease, top 0.22s ease;
  pointer-events: none;
  user-select: none;
}
.horse.c0 { background: var(--c0); }
.horse.c1 { background: var(--c1); }
.horse.c2 { background: var(--c2); color: #4a3a05; text-shadow: none; }
.horse.c3 { background: var(--c3); }
.horse.home { box-shadow: 0 0 0 2px rgba(255,255,255,0.5), 0 2px 5px rgba(0,0,0,0.4); }

/* A horse you can actually move asks to be clicked. */
.horse.movable {
  pointer-events: auto; cursor: pointer;
  animation: horse-pulse 1.05s ease-in-out infinite;
  z-index: 3;
}
.horse.movable:hover { transform: translate(-50%, -50%) scale(1.14); }
@keyframes horse-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0.85), 0 2px 5px rgba(0,0,0,0.4); }
  50%      { box-shadow: 0 0 0 5px rgba(255,255,255,0.12), 0 2px 5px rgba(0,0,0,0.4); }
}
.horse.just-moved { z-index: 2; filter: drop-shadow(0 0 6px rgba(255,220,120,0.95)); }

/* Where each movable horse would land. */
.target {
  position: absolute;
  width: calc(var(--cell, 30px) * 0.42); height: calc(var(--cell, 30px) * 0.42);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(30, 30, 30, 0.28);
  border: 2px dashed rgba(255,255,255,0.75);
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .horse { transition: none; }
  .horse.movable { animation: none; box-shadow: 0 0 0 4px rgba(255,255,255,0.5), 0 2px 5px rgba(0,0,0,0.4); }
}

/* ---------- Side panel ---------- */
.side-panel {
  width: 286px; background: var(--panel);
  border: 1px solid var(--panel-line); border-radius: 14px;
  padding: 18px 20px 24px; box-shadow: 0 18px 40px rgba(0,0,0,0.4);
}
.panel-title {
  font-family: "Averia Serif Libre", serif; font-weight: 700; font-size: 16px;
  color: #f5d98a; margin: 18px 0 10px;
  border-bottom: 1px solid var(--panel-line); padding-bottom: 6px;
}
.panel-title:first-child { margin-top: 0; }

/* ---------- Turn + dice ---------- */
.turn-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.turn-label { font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 7px; flex: 1; }

.die {
  width: 46px; height: 46px; flex: none;
  border-radius: 9px; background: #fdfcf5;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.12), 0 3px 7px rgba(0,0,0,0.4);
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  padding: 6px; opacity: 0; transform: scale(0.7); transition: opacity 0.15s, transform 0.15s;
}
.die.show { opacity: 1; transform: scale(1); animation: die-in 0.28s ease-out; }
@keyframes die-in {
  0%   { transform: scale(0.6) rotate(-25deg); }
  60%  { transform: scale(1.12) rotate(8deg); }
  100% { transform: scale(1) rotate(0); }
}
.die i { width: 8px; height: 8px; border-radius: 50%; background: #2b2b2b; align-self: center; justify-self: center; }
.die.d1 i:nth-child(1) { grid-area: 2/2; }
.die.d2 i:nth-child(1) { grid-area: 1/1; } .die.d2 i:nth-child(2) { grid-area: 3/3; }
.die.d3 i:nth-child(1) { grid-area: 1/1; } .die.d3 i:nth-child(2) { grid-area: 2/2; } .die.d3 i:nth-child(3) { grid-area: 3/3; }
.die.d4 i:nth-child(1) { grid-area: 1/1; } .die.d4 i:nth-child(2) { grid-area: 1/3; }
.die.d4 i:nth-child(3) { grid-area: 3/1; } .die.d4 i:nth-child(4) { grid-area: 3/3; }
.die.d5 i:nth-child(1) { grid-area: 1/1; } .die.d5 i:nth-child(2) { grid-area: 1/3; }
.die.d5 i:nth-child(3) { grid-area: 2/2; }
.die.d5 i:nth-child(4) { grid-area: 3/1; } .die.d5 i:nth-child(5) { grid-area: 3/3; }
.die.d6 i:nth-child(1) { grid-area: 1/1; } .die.d6 i:nth-child(2) { grid-area: 2/1; } .die.d6 i:nth-child(3) { grid-area: 3/1; }
.die.d6 i:nth-child(4) { grid-area: 1/3; } .die.d6 i:nth-child(5) { grid-area: 2/3; } .die.d6 i:nth-child(6) { grid-area: 3/3; }

.chip { width: 12px; height: 12px; border-radius: 50%; flex: none; display: inline-block; border: 1px solid rgba(255,255,255,0.5); }
.chip.c0 { background: var(--c0); } .chip.c1 { background: var(--c1); }
.chip.c2 { background: var(--c2); } .chip.c3 { background: var(--c3); }

.note { font-size: 12px; color: #f5d98a; min-height: 17px; font-style: italic; margin-bottom: 6px; }

/* ---------- Seats ---------- */
.seat-list { list-style: none; margin: 0; padding: 0; }
.seat {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: 7px; font-size: 13px;
  border: 1px solid transparent;
}
.seat.active { background: rgba(244,193,80,0.10); border-color: rgba(244,193,80,0.4); }
.seat-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-home { color: var(--muted); font-size: 12px; }

.result {
  margin-top: 12px; font-family: "Averia Serif Libre", serif; font-size: 15px;
  color: #ffdf95; opacity: 0; transition: opacity 0.2s ease;
}
.result.show {
  opacity: 1; padding: 10px 12px; border-radius: 9px;
  border: 1px solid rgba(244,193,80,0.4); background: rgba(244,193,80,0.09);
}
.result .rank { font-family: "Poppins", sans-serif; font-size: 12px; color: var(--muted); }

/* ---------- Controls ---------- */
.controls { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.btn {
  font-family: "Poppins", sans-serif; font-weight: 600; font-size: 14px;
  color: #06281e; background: var(--accent); border: none; border-radius: 11px;
  padding: 9px 14px; cursor: pointer; transition: filter 0.12s ease, transform 0.06s ease;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.4; cursor: default; filter: none; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--panel-line); }
.btn-ghost:hover { color: #f5d98a; border-color: #f5d98a; }
.btn-roll { font-size: 16px; padding: 12px 14px; }
.ctl { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.ctl select {
  margin-left: auto; width: 150px; background: var(--field); color: var(--text);
  border: 1px solid var(--panel-line); border-radius: 6px; padding: 3px 6px;
  font-family: "Poppins", sans-serif;
}
.hint { font-size: 11.5px; color: var(--muted); line-height: 1.5; font-style: italic; }

/* ---------- Online ---------- */
.tn-entry { display: flex; gap: 6px; margin-bottom: 8px; }
.tn-entry input, #ol-name {
  flex: 1; min-width: 0; width: 100%;
  background: var(--field); color: var(--text);
  border: 1px solid var(--panel-line); border-radius: 6px;
  padding: 6px 8px; font-family: "Poppins", sans-serif; font-size: 13px; margin-bottom: 8px;
}
.tn-actions { display: flex; gap: 6px; margin-bottom: 10px; }
.tn-actions .btn { flex: 1; }
.tn-body { font-size: 13px; }
.tn-result { font-family: "Averia Serif Libre", serif; font-size: 15px; color: #f5d98a; margin-bottom: 6px; }
.tn-sub { color: var(--muted); margin: 6px 0 4px; font-size: 12px; }
.tn-hint { color: var(--muted); font-style: italic; font-size: 12px; }
.tn-queue { margin: 0 0 8px; padding-left: 22px; max-height: 150px; overflow-y: auto; }
.tn-queue li { margin: 3px 0; }
.tn-queue .chip { vertical-align: -1px; margin-right: 4px; }

/* ---------- Move log ---------- */
.log { margin: 0; padding-left: 0; list-style: none; max-height: 190px; overflow-y: auto; font-size: 12.5px; }
.log li { display: flex; align-items: center; gap: 7px; padding: 3px 4px; border-radius: 4px; }
.log li:nth-child(odd) { background: rgba(255,255,255,0.03); }
.lg-die {
  flex: none; min-width: 17px; height: 17px; border-radius: 4px;
  background: #fdfcf5; color: #2b2b2b; font-size: 11px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}
.log .kick { color: #ff9a90; }

/* ---------- Help modal ---------- */
.help-btn { margin-top: 12px; }
.help-overlay {
  position: fixed; inset: 0; background: rgba(6,10,18,0.74);
  display: none; align-items: center; justify-content: center; z-index: 50; padding: 24px;
}
.help-overlay.open { display: flex; }
.help-card {
  position: relative; background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: 14px; max-width: 700px; width: 100%; max-height: 86vh; overflow-y: auto;
  padding: 26px 30px 24px; box-shadow: 0 24px 70px rgba(0,0,0,0.6);
}
.help-card h2 { font-family: "Averia Serif Libre", serif; color: #f5d98a; margin: 0 36px 6px 0; font-size: 22px; }
.help-card h3 { font-family: "Averia Serif Libre", serif; color: #f5d98a; font-size: 15px; margin: 18px 0 6px; }
.help-card p { font-size: 14px; line-height: 1.55; margin: 6px 0; }
.help-card b { color: #f3e6d3; }
.help-card ol, .help-card ul { font-size: 14px; line-height: 1.6; padding-left: 20px; }
.help-card li { margin: 4px 0; }
.help-close {
  position: absolute; top: 14px; right: 16px; background: transparent; border: none;
  color: var(--muted); font-size: 28px; line-height: 1; cursor: pointer; padding: 0 6px;
}
.help-close:hover { color: #f5d98a; }
.help-actions { text-align: right; margin-top: 20px; }
.move-guide { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin: 8px 0 14px; }
.mg-tile { background: rgba(255,255,255,0.03); border: 1px solid var(--panel-line); border-radius: 10px; padding: 10px; }
.mg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.mg-name { font-size: 14px; font-weight: 600; }
.mg-cap { font-size: 12px; color: var(--muted); margin: 8px 0 0; line-height: 1.5; }

@media (max-width: 900px) { .app-main { gap: 18px; } .side-panel { width: min(100%, 420px); } }
@media (max-width: 720px) {
  .logo { font-size: 34px; }
  .help-card { padding: 20px 18px; }
  .btn { padding: 11px 14px; }
  .board-panel { padding: 8px; }
}
