/* ============================================================
   game.css — Lanna River Race
   Pixel-art racing game · Navy #0d1b3e · Gold #C9A84C
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:   #0d1b3e;
  --navyd:  #080f22;
  --gold:   #C9A84C;
  --goldf:  #f4d03f;
  --cream:  #f5f0e8;
  --red:    #e05555;
  --green:  #4caf7d;
  --blue:   #1565c0;
  --river:  #1976d2;

  --hud-h:  48px;
  --act-h:  56px;
  --nav-h:  54px;

  --font-px:    'Press Start 2P', monospace;
  --font-title: 'Cormorant Garamond', serif;
  --font-body:  'Montserrat', sans-serif;
}

html, body {
  height: 100%;
  background: radial-gradient(ellipse at 50% 0%, #0b1e40 0%, var(--navy) 60%);
  color: var(--cream);
  font-family: var(--font-body);
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.px { font-family: var(--font-px) !important; }

/* ══ HUD ════════════════════════════════════════════════════ */
.rh {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--hud-h);
  background: rgba(5,10,24,.98);
  border-bottom: 2px solid rgba(201,168,76,.38);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  z-index: 100;
  box-shadow: 0 2px 24px rgba(21,101,192,.2), 0 1px 0 rgba(201,168,76,.1);
}

.rh-hp-group {
  display: flex; align-items: center; gap: 4px; flex: 1.2;
}
.rh-lbl  { font-size: 7px; color: var(--gold); letter-spacing: 1px; }
.rh-bar  {
  flex: 1; max-width: 60px; height: 7px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 2px; overflow: hidden;
}
.rh-hp-fill {
  height: 100%; width: 100%;
  background: var(--green);
  transition: width .25s, background .3s;
}
.rh-val  { font-size: 8px; color: var(--cream); min-width: 22px; }

.rh-center {
  flex: 1; text-align: center;
  display: flex; align-items: baseline; justify-content: center; gap: 2px;
}
.rh-pos  { font-size: 13px; color: var(--gold); }

.rh-right {
  display: flex; align-items: center; gap: 6px;
  font-size: 9px; color: var(--goldf);
}
.rh-coin-icon { font-size: 13px; }
.rh-hero-buff {
  display: flex; align-items: center; gap: 3px;
  padding: 2px 6px; border-radius: 6px;
  background: rgba(201,168,76,.15); border: 1px solid rgba(201,168,76,.3);
}
.rh-hero-buff-lbl { font-size: 5px; color: var(--goldf); font-family: var(--font-px); }

/* ══ RACE CANVAS WRAP ═══════════════════════════════════════ */
.race-wrap {
  position: fixed;
  top: var(--hud-h);
  bottom: calc(var(--act-h) + var(--nav-h));
  left: 0; right: 0;
  overflow: hidden;
}

#rc {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Lane controls overlay (bottom of canvas) */
.lane-ctrl {
  position: absolute;
  bottom: 8px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  background: rgba(5,10,24,.88);
  border: 1px solid rgba(201,168,76,.35);
  border-radius: 20px;
  padding: 5px 12px;
  z-index: 10;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 20px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.06);
}
.lane-btn {
  width: 28px; height: 24px;
  background: rgba(201,168,76,.18);
  border: 1px solid rgba(201,168,76,.4);
  border-radius: 6px;
  color: var(--gold); font-size: .65rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s;
}
.lane-btn:hover  { background: rgba(201,168,76,.32); }
.lane-btn:active { transform: scale(.9); }
.lane-lbl { font-size: 7px; color: var(--cream); min-width: 52px; text-align: center; }

/* Week timer + rank chip (top-right) */
.race-info-chip {
  position: absolute;
  top: 8px; right: 8px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
  z-index: 10;
  pointer-events: none;
}
.race-info-chip span {
  font-size: 6px; color: rgba(245,240,232,.55);
  background: rgba(8,15,34,.75);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px;
  padding: 3px 7px;
}
.rank-chip {
  color: var(--gold) !important;
  border-color: rgba(201,168,76,.35) !important;
  font-size: 8px !important;
}
.stats-chip-btn {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 8px;
  color: var(--cream); font-size: .85rem;
  width: 28px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0;
  transition: background .12s;
  pointer-events: all;
}
.stats-chip-btn:hover { background: rgba(255,255,255,.14); }

/* ══ ACTION BAR ═════════════════════════════════════════════ */
.game-actions {
  position: fixed;
  bottom: var(--nav-h); left: 0; right: 0;
  height: var(--act-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px;
  background: rgba(5,10,24,.97);
  border-top: 1px solid rgba(201,168,76,.22);
  z-index: 50;
  box-shadow: 0 -2px 20px rgba(0,0,0,.3);
}

.game-roll-btn {
  flex: 1; height: 42px;
  background: linear-gradient(135deg, rgba(201,168,76,.3), rgba(201,168,76,.15));
  border: 1.5px solid rgba(201,168,76,.7);
  border-radius: 10px;
  color: var(--gold);
  cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  transition: background .15s, transform .1s, box-shadow .15s;
  box-shadow: 0 0 16px rgba(201,168,76,.12), inset 0 1px 0 rgba(255,255,255,.06);
}
.game-roll-btn:active   { transform: scale(.97); }
.game-roll-btn:disabled { opacity: .38; cursor: not-allowed; transform: none; }

.roll-dice-icon { font-size: 1.1rem; letter-spacing: -2px; }
.roll-label     { font-size: 8px; }
.roll-info      { display: flex; flex-direction: column; gap: 2px; }
.roll-cost      { font-size: 6px; opacity: .75; }

.game-act-btn {
  height: 42px; min-width: 58px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  color: var(--cream);
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: .9rem; padding: 0 8px;
  transition: background .15s;
}
.game-act-btn span { font-size: .52rem; opacity: .7; font-family: var(--font-body); }
.game-act-btn:hover { background: rgba(255,255,255,.1); }

/* ══ BOTTOM NAV ═════════════════════════════════════════════ */
.game-bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: rgba(5,10,25,.98);
  border-top: 1px solid rgba(201,168,76,.12);
  display: flex; align-items: center; justify-content: space-around;
  z-index: 50;
}
.gbn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  color: rgba(245,240,232,.42); font-size: 1.1rem;
  text-decoration: none; transition: color .15s;
}
.gbn span { font-size: .52rem; font-family: var(--font-body); }
.gbn:hover, .gbn-active { color: var(--gold); }
button.gbn { background: none; border: none; cursor: pointer; }

/* ══ GAMES HUB POPUP ════════════════════════════════════════ */
.ghp-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(4,8,22,.6); backdrop-filter: blur(4px);
}
.games-hub-popup {
  position: fixed;
  bottom: calc(var(--nav-h) + 8px);
  left: 50%; transform: translateX(-50%);
  width: min(340px, calc(100vw - 24px));
  background: rgba(8,15,34,.98);
  border: 1px solid rgba(201,168,76,.3);
  border-radius: 16px;
  padding: 16px;
  z-index: 201;
  box-shadow: 0 -4px 40px rgba(201,168,76,.12);
}
.ghp-title { font-size: 8px; color: var(--gold); text-align: center; margin-bottom: 14px; letter-spacing: 2px; }
.ghp-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.ghp-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 5px; padding: 12px 6px; border-radius: 10px;
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.07);
  color: rgba(245,240,232,.7); text-decoration: none; font-size: 1.4rem;
  transition: all .15s;
}
.ghp-item span { font-size: .52rem; font-family: var(--font-body); color: rgba(245,240,232,.6); }
.ghp-item:hover, .ghp-item.ghp-active {
  background: rgba(201,168,76,.12); border-color: rgba(201,168,76,.35); color: var(--gold);
}
.ghp-item.ghp-active span { color: var(--gold); }
.ghp-close {
  display: block; width: 100%; margin-top: 12px; padding: 8px;
  background: rgba(255,255,255,.06); border: none; border-radius: 8px;
  color: rgba(245,240,232,.5); cursor: pointer; font-size: .75rem;
  font-family: var(--font-body); transition: background .15s;
}
.ghp-close:hover { background: rgba(255,255,255,.12); }

/* ══ MODALS ═════════════════════════════════════════════════ */
.gmodal-overlay {
  position: fixed; inset: 0;
  background: rgba(4,8,22,.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; padding: 20px;
  animation: gFade .15s ease;
}
@keyframes gFade { from { opacity: 0; } to { opacity: 1; } }

.gmodal {
  background: linear-gradient(160deg, #101f3e, #0a1628);
  border: 1px solid rgba(201,168,76,.35);
  border-radius: 20px;
  padding: 22px 18px;
  width: 100%; max-width: 340px;
  text-align: center;
  animation: gPop .22s cubic-bezier(.34,1.56,.64,1);
  box-shadow: 0 20px 60px rgba(0,0,0,.5), 0 0 40px rgba(201,168,76,.06), inset 0 1px 0 rgba(255,255,255,.05);
}
@keyframes gPop {
  from { transform: scale(.88); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.gmodal-title {
  font-family: var(--font-px);
  font-size: .75rem; color: var(--cream);
  margin-bottom: 16px; line-height: 1.6;
}
.gmodal-title.px { font-size: .7rem; }

/* Dice row */
.gmodal-dice-row {
  display: flex; align-items: center; justify-content: center;
  gap: 14px; margin-bottom: 12px;
}
.gm-die {
  width: 62px; height: 62px; border-radius: 12px;
  background: rgba(201,168,76,.1);
  border: 2px solid rgba(201,168,76,.4);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.9rem; color: var(--gold);
}
.gm-die.rolling { animation: dShake .08s linear infinite; }
@keyframes dShake {
  0%,100% { transform: rotate(0); }
  25%     { transform: rotate(-8deg) scale(1.05); }
  75%     { transform: rotate( 8deg) scale(1.05); }
}
.gm-plus { font-size: 1.3rem; color: rgba(245,240,232,.3); }
.gmodal-total    { font-size: .8rem; color: var(--gold); margin-bottom: 5px; }
.gmodal-cost-note { font-size: .7rem; color: rgba(245,240,232,.45); margin-bottom: 14px; }

.gmodal-btns { display: flex; gap: 10px; justify-content: center; }
.gmbtn-confirm, .gmbtn-cancel {
  padding: 10px 20px; border-radius: 22px;
  font-family: var(--font-body); font-size: .8rem; font-weight: 700;
  cursor: pointer; border: none;
  transition: background .15s, transform .1s;
}
.gmbtn-confirm:active, .gmbtn-cancel:active { transform: scale(.96); }
.gmbtn-confirm {
  background: linear-gradient(135deg, #C9A84C, #e8c660);
  color: var(--navy); flex: 1;
}
.gmbtn-confirm:hover { background: linear-gradient(135deg, #d4b355, #f0d070); }
.gmbtn-cancel {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  color: rgba(245,240,232,.6);
}
.gmbtn-cancel:hover { background: rgba(255,255,255,.1); }

/* Event modal */
.gmodal--event .gmodal-event-icon {
  font-size: 3.6rem; line-height: 1; margin-bottom: 10px;
  animation: iPop .4s cubic-bezier(.34,1.56,.64,1);
}
@keyframes iPop { from { transform: scale(0); } to { transform: scale(1); } }
.gmodal-desc { font-size: 1rem; font-weight: 600; color: var(--gold); margin-bottom: 18px; }

/* Stats modal */
.gmodal--stats { max-width: 360px; text-align: left; }
.stats-rows { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.stat-row { display: flex; align-items: center; gap: 8px; }
.stat-ico { font-size: 1rem; width: 20px; text-align: center; }
.stat-nm  { font-size: .72rem; width: 60px; color: rgba(245,240,232,.7); }
.stat-bar { flex: 1; height: 6px; background: rgba(255,255,255,.08); border-radius: 3px; overflow: hidden; }
.stat-bar-fill { height: 100%; border-radius: 3px; transition: width .5s ease; }
.stat-bar-fill.acc  { background: linear-gradient(90deg,#ff9933,#ffcc44); }
.stat-bar-fill.eva  { background: linear-gradient(90deg,#44aaff,#88ddff); }
.stat-bar-fill.luck { background: linear-gradient(90deg,#44dd88,#aaff88); }
.stat-vl { font-size: .7rem; font-weight: 700; color: var(--gold); width: 36px; text-align: right; }
.stats-inv-title { font-size: .72rem; color: rgba(245,240,232,.5); margin-bottom: 6px; }
.stats-inv {
  font-size: .75rem; min-height: 36px; color: rgba(245,240,232,.6);
  background: rgba(255,255,255,.04); border-radius: 10px;
  padding: 8px 10px; margin-bottom: 14px;
}

/* Died modal */
.gmodal--died .gmodal-event-icon { font-size: 3.6rem; margin-bottom: 10px; }

/* Items modal */
.gmodal--items { max-width: 380px; }
.items-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.itab {
  flex: 1; padding: 6px; border-radius: 8px; font-size: .68rem; font-weight: 600;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.1);
  color: rgba(245,240,232,.6); cursor: pointer; transition: all .15s;
}
.itab.active { background: rgba(201,168,76,.18); border-color: rgba(201,168,76,.4); color: var(--gold); }
.items-grid {
  display: grid; grid-template-columns: repeat(2,1fr);
  gap: 8px; max-height: 270px; overflow-y: auto; margin-bottom: 12px;
}
.item-card {
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px; padding: 10px; text-align: center;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.item-card:hover { border-color: rgba(201,168,76,.4); background: rgba(201,168,76,.08); }
.item-card-icon { font-size: 1.8rem; line-height: 1; margin-bottom: 4px; }
.item-card-name { font-size: .65rem; font-weight: 600; color: var(--cream); margin-bottom: 2px; }
.item-card-desc { font-size: .56rem; color: rgba(245,240,232,.45); margin-bottom: 6px; line-height: 1.4; }
.item-card-cost { font-size: .68rem; font-weight: 700; color: var(--gold); }
.item-card-qty  { font-size: .6rem; color: var(--green); margin-top: 2px; }
.item-card--broke { opacity: .45; }
.gm-loading { text-align: center; color: rgba(245,240,232,.35); font-size: .78rem; padding: 16px; }

/* Rank modal */
.gmodal--rank { max-width: 360px; }
.rank-week-label {
  font-size: .65rem; color: rgba(245,240,232,.4);
  margin-bottom: 8px; text-align: center;
}
.rank-prizes {
  display: flex; justify-content: center; gap: 12px;
  font-size: .62rem; color: var(--gold);
  margin-bottom: 12px; padding-bottom: 10px;
  border-bottom: 1px solid rgba(201,168,76,.15);
}
.rank-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid rgba(201,168,76,.07);
  font-size: .78rem;
}
.rank-no   { width: 22px; font-weight: 700; color: rgba(245,240,232,.4); text-align: center; }
.rank-no.top3 { color: var(--gold); }
.rank-ava  {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--gold); color: var(--navy);
  font-weight: 700; font-size: .72rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; overflow: hidden;
}
.rank-ava img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.rank-name { flex: 1; font-weight: 500; }
.rank-pos  { color: var(--gold); font-weight: 700; font-size: .72rem; }

/* Target modal */
.gmodal--target { max-width: 340px; }
.target-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 210px; overflow-y: auto; margin-bottom: 4px;
}
.target-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 10px;
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.1);
  cursor: pointer; transition: all .15s;
}
.target-row:hover { background: rgba(201,168,76,.12); border-color: rgba(201,168,76,.4); }
.target-row-ava {
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255,255,255,.2); color: var(--cream);
  font-weight: 700; font-size: .72rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; overflow: hidden;
}
.target-row-ava img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.target-row-info { flex: 1; text-align: left; }
.target-row-name { font-size: .75rem; font-weight: 600; color: var(--cream); }
.target-row-pos  { font-size: .6rem; color: rgba(245,240,232,.45); margin-top: 1px; }
.target-empty    { font-size: .75rem; color: rgba(245,240,232,.35); padding: 16px; text-align: center; }

/* ══ LOGIN WALL ═════════════════════════════════════════════ */
.game-login-wall {
  position: fixed; inset: 0;
  background: var(--navy);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
}
.glw-card { text-align: center; padding: 32px; }
.glw-icon  { font-size: 4rem; margin-bottom: 14px; }
.glw-title {
  font-family: var(--font-px);
  font-size: 1.1rem; color: var(--gold);
  margin-bottom: 10px; line-height: 1.8;
}
.glw-sub   { font-size: .8rem; color: rgba(245,240,232,.5); margin-bottom: 22px; }
.glw-btn {
  display: inline-block; padding: 12px 32px;
  background: linear-gradient(135deg, var(--gold), #e8c660);
  color: var(--navy); font-weight: 700; font-size: .88rem;
  border-radius: 22px; text-decoration: none;
  transition: transform .15s;
}
.glw-btn:hover { transform: scale(1.04); }

/* ══ ATTACK TOAST ═══════════════════════════════════════════ */
.attack-toast {
  position: fixed;
  top: calc(var(--hud-h) + 8px); left: 50%; transform: translateX(-50%);
  z-index: 600;
  background: rgba(140,20,20,.97);
  border: 1px solid rgba(255,100,100,.35);
  border-radius: 12px; padding: 10px 16px;
  font-size: .76rem; font-weight: 600; color: #fff;
  white-space: nowrap; max-width: calc(100vw - 24px);
  text-align: center;
  animation: gFade .2s ease;
}

/* ══ LIVE FEED ══════════════════════════════════════════════ */
.game-feed {
  position: absolute;
  left: 8px; top: 36px;
  width: min(180px, 44vw);
  max-height: 120px;
  overflow: hidden;
  pointer-events: none;
  display: flex; flex-direction: column-reverse; gap: 3px;
  z-index: 5;
}
.feed-item {
  background: rgba(8,15,34,.82);
  border: 1px solid rgba(201,168,76,.15);
  border-radius: 7px; padding: 3px 7px;
  font-size: .6rem; color: rgba(245,240,232,.7);
  animation: feedIn .3s ease;
}
@keyframes feedIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; } }

/* ══ RESPONSIVE ═════════════════════════════════════════════ */
@media (max-width: 360px) {
  .rh-pos { font-size: 11px; }
  .lane-lbl { font-size: 6px; min-width: 44px; }
}
@media (min-width: 600px) {
  .game-actions, .game-bottom-nav {
    max-width: 480px; left: 50%; transform: translateX(-50%);
  }
}

/* ══ FOCUS / MOTION ═════════════════════════════════════════ */
.gmbtn-confirm:focus-visible,
.gmbtn-cancel:focus-visible,
.game-roll-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .gm-die.rolling,
  .gmodal { animation: none !important; }
}
