/* RisiKo! — Edizione La Ciociara. Military-green board aesthetic. */

:root {
  --board: #8f9455;
  --board-dark: #6f7440;
  --ink: #23241c;
  --paper: #f4efdf;
  --paper-dark: #e6dfc8;
  --accent: #b03a2e;
  --gold: #c9a227;
  --panel: #2e3020;
  --panel-ink: #ece7d3;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  background: repeating-linear-gradient(45deg, #75793f 0 14px, #7c8045 14px 28px);
  color: var(--ink);
}
.hidden { display: none !important; }

/* ---------- splash ---------- */
.splash {
  position: fixed; inset: 0; z-index: 50;
  background: var(--board);
  display: flex; align-items: center; justify-content: center;
}
.splash-inner { text-align: center; color: var(--paper); }
.splash-title { font-size: 64px; font-weight: 900; letter-spacing: 2px; color: #d43f2f; text-shadow: 2px 2px 0 #40220c; }
.splash-sub { font-size: 22px; margin-top: 4px; }
.splash-quip { margin-top: 26px; font-style: italic; opacity: .85; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 14px; background: var(--panel); color: var(--panel-ink);
  border-bottom: 3px solid var(--gold);
}
.brand { font-weight: 900; font-size: 20px; color: #e35b4c; }
.brand-sub { color: var(--panel-ink); font-weight: 600; font-size: 14px; }
.top-right { display: flex; gap: 10px; align-items: center; }
.room-chip {
  background: var(--gold); color: #2b2b1f; font-weight: 800;
  padding: 4px 10px; border-radius: 6px; letter-spacing: 2px; cursor: pointer;
}
.lang-select { padding: 4px 6px; border-radius: 6px; border: none; font-size: 14px; }

/* ---------- generic ---------- */
.view { padding: 18px; }
.card-panel {
  background: var(--paper); border: 2px solid var(--board-dark);
  border-radius: 12px; padding: 18px; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
button {
  font: inherit; cursor: pointer; border: none; border-radius: 8px;
  padding: 9px 16px; font-weight: 700; background: var(--accent); color: #fff;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondary { background: var(--board-dark); }
button.ghost { background: transparent; color: var(--ink); border: 2px solid var(--board-dark); }
input[type=text] {
  font: inherit; padding: 9px 12px; border-radius: 8px;
  border: 2px solid var(--board-dark); width: 100%;
}

/* ---------- home ---------- */
.home-wrap { max-width: 520px; margin: 6vh auto; display: flex; flex-direction: column; gap: 16px; }
.home-title { text-align: center; color: var(--paper); }
.home-title h1 { font-size: 46px; margin: 0; color: #d43f2f; text-shadow: 2px 2px 0 #40220c; }
.home-title p { margin: 6px 0 0; color: #f2eeda; }
.home-row { display: flex; gap: 10px; }
.home-row > * { flex: 1; }
.field-label { font-weight: 700; font-size: 14px; margin-bottom: 4px; display: block; }

/* ---------- lobby ---------- */
.lobby-wrap { max-width: 640px; margin: 3vh auto; display: flex; flex-direction: column; gap: 14px; }
.share-box { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.share-code { font-size: 30px; font-weight: 900; letter-spacing: 6px; color: var(--accent); }
.player-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-bottom: 1px dashed var(--board-dark);
}
.player-row:last-child { border-bottom: none; }
.chip { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #2b2b1f; flex: none; }
.player-name { font-weight: 700; flex: 1; }
.badge-ciociara {
  background: var(--gold); color: #2b2b1f; border-radius: 6px;
  font-size: 12px; padding: 2px 7px; font-weight: 800;
}
.muted { opacity: .6; font-size: 13px; }
.color-picker { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  border: 3px solid transparent;
}
.swatch.mine { border-color: var(--gold); box-shadow: 0 0 0 2px #2b2b1f; }
.swatch.taken { opacity: .25; cursor: not-allowed; }
.lobby-settings { display: flex; flex-direction: column; gap: 8px; }
.lobby-settings label { display: flex; align-items: center; gap: 8px; }

/* ---------- game layout ---------- */
.view-game {
  display: grid; grid-template-columns: 1fr 340px; gap: 12px;
  padding: 10px; height: calc(100vh - 54px);
}
.map-wrap {
  background: var(--board); border: 4px solid #2b2b1f; border-radius: 10px;
  overflow: hidden; position: relative; display: flex;
}
.board { width: 100%; height: 100%; }
.sidebar {
  display: flex; flex-direction: column; gap: 10px; overflow-y: auto;
  padding-right: 2px;
}
.panel {
  background: var(--paper); border: 2px solid var(--board-dark);
  border-radius: 10px; padding: 10px 12px;
}
.panel h3 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; }

.turn-banner { font-weight: 800; font-size: 16px; }
.turn-banner.mine { color: var(--accent); }
.phase-label { font-size: 13px; opacity: .8; margin-top: 2px; }
.hint { font-size: 13px; font-style: italic; margin: 8px 0; opacity: .85; }
.reinf-banner {
  font-weight: 800; font-size: 16px; margin: 6px 0; padding: 8px 10px;
  border-radius: 8px; text-align: center;
}
.reinf-banner.pending { background: #f6e6c8; color: #8a3b12; border: 2px solid var(--accent); }
.reinf-banner.ready { background: #dff0d8; color: #1e6b2f; border: 2px solid #1e8449; }
.locked-note { color: var(--accent); opacity: 1; font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* players mini list */
.pl-row { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 3px 0; }
.pl-row .chip { width: 16px; height: 16px; }
.pl-dead { text-decoration: line-through; opacity: .5; }
.pl-turn { font-weight: 800; }
.pl-off { opacity: .45; }

/* cards */
.hand { display: flex; flex-wrap: wrap; gap: 6px; }
.tcard {
  width: 74px; border: 2px solid var(--board-dark); border-radius: 8px;
  background: #fff; padding: 5px; text-align: center; cursor: pointer; user-select: none;
}
.tcard.sel { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.tcard .sym { font-size: 22px; }
.tcard .tname { font-size: 9px; line-height: 1.15; min-height: 21px; }
.tcard.owned-t { background: #fdf6d9; }

/* objective */
.objective-box { font-size: 14px; background: #23241c; color: #f3edd8; border-radius: 8px; padding: 10px; }
.objective-box .mut { color: var(--gold); font-weight: 700; display: block; margin-top: 6px; }

/* log & chat */
.log-list { max-height: 200px; overflow-y: auto; font-size: 13px; display: flex; flex-direction: column; gap: 3px; }
.log-line .who { font-weight: 700; }
.log-quip { font-style: italic; opacity: .75; font-size: 12px; padding-left: 12px; }
.chat-list { max-height: 150px; overflow-y: auto; font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
.chat-line .who { font-weight: 700; }
.chat-form { display: flex; gap: 6px; margin-top: 6px; }
.chat-form input { flex: 1; padding: 6px 9px; }
.chat-form button { padding: 6px 12px; }

/* image-backed board: markers overlaid on the board image */
.board { background: #efe6cf; }
.territory { cursor: pointer; }
.t-hit { fill: transparent; }
.t-halo { fill: transparent; stroke: none; pointer-events: none; transition: all .12s; }
.territory:hover .t-halo { fill: rgba(255,255,255,.28); }
.territory.usable .t-halo { fill: rgba(255,255,255,.12); stroke: #fff; stroke-width: 3; stroke-dasharray: 5 5; }
.territory.sel .t-halo { fill: rgba(201,162,39,.35); stroke: var(--gold); stroke-width: 5; }
.territory.target .t-halo {
  fill: rgba(212,63,47,.28); stroke: #d43f2f; stroke-width: 5; stroke-dasharray: 9 6;
  animation: targetpulse .8s ease-in-out infinite alternate;
}
@keyframes targetpulse { from { opacity: .6; } to { opacity: 1; } }
.t-count { font-size: 22px; font-weight: 900; text-anchor: middle; pointer-events: none; }
.t-badge { stroke: #fff; stroke-width: 2.5; paint-order: stroke; }

/* dice tray */
.dice-tray {
  position: fixed; left: 18px; bottom: 18px; z-index: 30;
  background: rgba(35,36,28,.92); border: 2px solid var(--gold);
  border-radius: 12px; padding: 10px 14px; color: #fff;
}
.dice-row { display: flex; gap: 6px; align-items: center; margin: 3px 0; }
.die {
  width: 34px; height: 34px; border-radius: 7px; display: inline-flex;
  align-items: center; justify-content: center; font-size: 21px; font-weight: 900;
  animation: roll .35s ease;
}
.die.att { background: #d43f2f; color: #fff; }
.die.def { background: #2960a8; color: #fff; }
.dice-caption { font-size: 12px; opacity: .8; }
@keyframes roll { from { transform: rotate(-160deg) scale(.4); } to { transform: none; } }

/* modals */
.modal-back {
  position: fixed; inset: 0; background: rgba(20,20,12,.55);
  display: flex; align-items: center; justify-content: center; z-index: 40;
}
.modal {
  background: var(--paper); border: 3px solid var(--board-dark); border-radius: 14px;
  padding: 20px; max-width: 440px; width: 92%; box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.modal h3 { margin-top: 0; }
.modal .actions { justify-content: flex-end; }
.countdown { font-weight: 800; color: var(--accent); }
input[type=range] { width: 100%; }
.range-val { font-weight: 900; font-size: 20px; text-align: center; }

/* win overlay */
.win-overlay {
  position: fixed; inset: 0; z-index: 45; display: flex; align-items: center; justify-content: center;
  background: rgba(24,24,14,.82);
}
.win-box {
  text-align: center; background: var(--paper); border: 4px solid var(--gold);
  border-radius: 18px; padding: 34px 44px; max-width: 560px;
}
.win-box h1 { margin: 0 0 6px; font-size: 34px; }
.win-box .obj { font-style: italic; margin: 10px 0 4px; }
.win-box .quip-line { color: var(--board-dark); font-weight: 700; margin-bottom: 16px; }

/* final ranking */
.ranking { text-align: left; margin: 4px 0 18px; }
.ranking h3 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; text-align: center; }
.rank-row {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px;
  border-radius: 8px; font-size: 15px;
}
.rank-row:nth-child(even) { background: rgba(0,0,0,.04); }
.rank-row.winner { background: rgba(201,162,39,.22); font-weight: 800; }
.rank-row.dead { opacity: .55; }
.rank-row.dead .rank-name { text-decoration: line-through; }
.rank-pos { width: 24px; text-align: center; font-weight: 800; }
.rank-name { flex: 1; }
.rank-terr { font-size: 13px; opacity: .8; white-space: nowrap; }

/* confetti overlay (above everything, clicks pass through) */
.confetti-canvas { position: fixed; inset: 0; z-index: 80; pointer-events: none; }

/* home scoreboard (stats + recent games) */
.history-panel { margin-top: 14px; }
.history-panel h3 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; }
.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; border-bottom: 1px dashed var(--board-dark); font-size: 15px; }
.stat-row:last-child { border-bottom: none; }
.stat-name { font-weight: 700; }
.stat-nums { font-size: 13px; opacity: .8; white-space: nowrap; }
.game-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--board-dark); }
.game-row:last-child { border-bottom: none; }
.game-info { flex: 1; min-width: 0; }
.game-win { font-weight: 700; }
.game-players { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-date { font-size: 12px; white-space: nowrap; }

/* Ciociarometro */
.ciociarometro h3 { color: var(--accent); }
.ciociaro-share { font-size: 13px; opacity: .8; margin-bottom: 6px; }
.ciociaro-track {
  height: 20px; background: var(--paper-dark); border: 2px solid var(--board-dark);
  border-radius: 11px; overflow: hidden;
}
.ciociaro-fill {
  height: 100%; min-width: 20px; border-radius: 9px;
  background: linear-gradient(90deg, var(--gold), var(--accent));
  transition: width .5s ease; display: flex; align-items: center; justify-content: flex-end;
}
.ciociaro-mark { font-size: 14px; padding-right: 2px; }
.ciociaro-label { font-size: 13px; font-style: italic; font-weight: 700; color: var(--board-dark); margin-top: 6px; }

/* tools panel (rules + sound) */
.tools-panel { display: flex; gap: 8px; }
.tools-panel button { flex: 1; }

/* rules modal */
.rules-modal { max-width: 560px; }
.rules-body { max-height: 60vh; overflow-y: auto; margin: 4px 0 12px; }
.rules-h { font-weight: 800; margin: 12px 0 3px; color: var(--accent); }
.rules-p { font-size: 14px; line-height: 1.5; }

/* turn alert — strong "it's your turn" signal */
.turn-alert {
  position: fixed; top: 0; left: 0; right: 0; z-index: 70;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 22px 16px; cursor: pointer;
  background: linear-gradient(180deg, rgba(176,58,46,.97), rgba(201,162,39,.95));
  color: #fff; text-align: center;
  box-shadow: 0 6px 30px rgba(0,0,0,.5);
  animation: turnpulse 0.7s ease-in-out infinite alternate, turndrop .3s ease;
}
.turn-alert-big { font-size: 34px; font-weight: 900; letter-spacing: 1px; text-shadow: 2px 2px 0 #5a1c14; }
.turn-alert-sub { font-size: 16px; margin-top: 4px; opacity: .95; }
@keyframes turnpulse { from { filter: brightness(1); } to { filter: brightness(1.25); } }
@keyframes turndrop { from { transform: translateY(-100%); } to { transform: none; } }

/* toasts */
#toast-root { position: fixed; top: 66px; right: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #b03a2e; color: #fff; font-weight: 700; border-radius: 8px;
  padding: 10px 14px; box-shadow: 0 4px 14px rgba(0,0,0,.4); animation: fadein .2s ease;
  max-width: 320px;
}
.toast.info { background: #2e3020; border: 1px solid var(--gold); }
@keyframes fadein { from { opacity: 0; transform: translateY(-6px); } }

/* responsive */
@media (max-width: 900px) {
  .view-game { grid-template-columns: 1fr; height: auto; }
  .map-wrap { height: 58vw; min-height: 300px; }
  .sidebar { max-height: none; }
  .dice-tray { position: static; margin: 8px; }
}
