/* ============================================================
   ANIMAL ALLIANCE — "Torchlit Kingdom" theme
   Palette: pine-dark table, parchment tiles, antique gold, ember red
   ============================================================ */
:root {
  --pine:      #0e1912;
  --moss:      #1a2b20;
  --moss-2:    #223829;
  --parchment: #e9dcbc;
  --parch-dim: #cdbd97;
  --ink:       #2b2317;
  --gold:      #c9a227;
  --gold-hi:   #eecd5e;
  --ember:     #b3452f;
  --ember-hi:  #e06a4f;
  --mist:      #8fb3a6;
  --line:      rgba(201,162,39,.25);
  --tile: 84px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }
body {
  background:
    radial-gradient(1200px 700px at 50% -10%, #16281d 0%, var(--pine) 60%),
    var(--pine);
  color: var(--parchment);
  font-family: 'Spectral', Georgia, serif;
  font-size: 16px;
  overflow-x: hidden;
}
.vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,.55) 100%);
}

h1,h2,h3,.btn,.phase-badge,.game-code { font-family: 'Cinzel', serif; }

/* ---------- Screens ---------- */
.screen { display: none; position: relative; z-index: 1; min-height: 100vh; padding: 32px 18px 40px; max-width: 560px; margin: 0 auto; }
.screen.active { display: block; }

.crest { text-align: center; }
.crest img { width: 110px; height: 110px; object-fit: contain; filter: drop-shadow(0 4px 12px rgba(0,0,0,.6)); }

.title {
  text-align: center; font-weight: 900; letter-spacing: .04em;
  font-size: clamp(2.1rem, 8vw, 3.2rem); margin-top: 10px; line-height: 1.05;
  text-shadow: 0 2px 0 #000, 0 6px 24px rgba(201,162,39,.25);
}
.title span { color: var(--gold-hi); display: block; }
.tagline { text-align: center; color: var(--mist); font-style: italic; margin: 10px 0 26px; }
.subtitle { font-weight: 700; letter-spacing: .05em; font-size: 1.4rem; }
.foot { text-align: center; margin-top: 26px; color: rgba(233,220,188,.4); font-size: .85rem; letter-spacing: .08em; }

/* ---------- Panels & forms ---------- */
.panel {
  background: linear-gradient(180deg, var(--moss-2), var(--moss));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.05);
}
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: .8rem; letter-spacing: .1em; text-transform: uppercase; color: var(--mist); margin-bottom: 6px; }
input {
  width: 100%; padding: 12px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: rgba(0,0,0,.35);
  color: var(--parchment); font-family: inherit; font-size: 1rem;
}
input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.code-input { text-transform: uppercase; letter-spacing: .35em; font-family: 'Cinzel', serif; text-align: center; }
.join-row { display: flex; gap: 10px; }
.join-row .btn { flex-shrink: 0; }

.btn {
  display: inline-block; cursor: pointer; border: 1px solid var(--line);
  background: linear-gradient(180deg, #2b4433, #223829);
  color: var(--parchment); border-radius: 8px; padding: 12px 18px;
  font-size: .95rem; font-weight: 700; letter-spacing: .05em;
  transition: transform .12s, box-shadow .12s, filter .12s;
  width: 100%; text-align: center; text-decoration: none;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
.btn.gold {
  background: linear-gradient(180deg, var(--gold-hi), var(--gold));
  color: var(--ink); border-color: rgba(0,0,0,.3);
  box-shadow: 0 4px 16px rgba(201,162,39,.35);
}
.btn.danger { background: linear-gradient(180deg, var(--ember-hi), var(--ember)); color: #fff; }
.btn.big { padding: 15px 22px; font-size: 1.05rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.hidden { display: none !important; }

.divider { display: flex; align-items: center; gap: 12px; margin: 16px 0; color: var(--mist); font-size: .8rem; letter-spacing: .1em; text-transform: uppercase; }
.divider::before, .divider::after { content: ''; height: 1px; flex: 1; background: var(--line); }

.err { color: var(--ember-hi); min-height: 1.2em; margin-top: 10px; text-align: center; font-size: .9rem; }
.hint { color: var(--mist); font-size: .85rem; margin-top: 8px; }

/* ---------- Lobby ---------- */
.lobby-head { text-align: center; margin-bottom: 22px; }
.game-code { margin-top: 8px; font-size: 1.1rem; }
.game-code strong { color: var(--gold-hi); letter-spacing: .3em; font-size: 1.4rem; }
.section-label { font-size: .8rem; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); margin: 18px 0 10px; }

.animal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px,1fr)); gap: 10px; }
.animal-card {
  background: linear-gradient(180deg, var(--moss-2), var(--moss));
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 10px;
  text-align: center; cursor: pointer; transition: transform .12s, border-color .12s;
}
.animal-card:hover { transform: translateY(-2px); border-color: var(--gold); }
.animal-card.selected { border-color: var(--gold-hi); box-shadow: 0 0 0 2px var(--gold), 0 6px 18px rgba(201,162,39,.25); }
.animal-card.taken { opacity: .35; pointer-events: none; }
.animal-card img { width: 56px; height: 56px; object-fit: contain; }
.animal-card .a-emoji { font-size: 2.2rem; line-height: 56px; }
.animal-card .a-name { font-family: 'Cinzel', serif; font-weight: 700; margin-top: 4px; }
.animal-card .a-stats { font-size: .75rem; color: var(--mist); margin-top: 3px; }
.animal-card .a-ability { font-size: .72rem; color: var(--parch-dim); font-style: italic; margin-top: 4px; }

.player-list { list-style: none; }
.player-list li {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-bottom: 1px solid rgba(201,162,39,.12); font-size: .95rem;
}
.player-list li:last-child { border-bottom: 0; }
.player-list .p-animal { color: var(--gold-hi); }
.player-list .p-host { font-size: .7rem; color: var(--mist); letter-spacing: .1em; text-transform: uppercase; }
.player-list.compact li { padding: 6px 8px; font-size: .88rem; }
.player-list .p-hp { margin-left: auto; color: var(--ember-hi); font-size: .85rem; }
.player-list .dead { opacity: .4; text-decoration: line-through; }
.player-list .turn-now { color: var(--gold-hi); }
.lobby-actions { margin-top: 22px; text-align: center; }

/* ---------- Game layout ---------- */
body.in-game { overflow: hidden; height: 100vh; }
.game-topbar {
  position: relative; z-index: 3; display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: rgba(10,18,13,.92); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(4px);
}
.phase-badge {
  font-size: .72rem; letter-spacing: .12em; text-transform: uppercase;
  padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--mist);
  white-space: nowrap;
}
.phase-badge.competitive { color: #fff; background: var(--ember); border-color: var(--ember-hi); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100%{ box-shadow: 0 0 0 0 rgba(179,69,47,.5);} 50%{ box-shadow: 0 0 0 7px rgba(179,69,47,0);} }
.turn-banner { flex: 1; text-align: center; font-family: 'Cinzel', serif; font-weight: 700; font-size: .95rem; }
.turn-banner.mine { color: var(--gold-hi); }
.tiles-left { font-size: .75rem; color: var(--mist); white-space: nowrap; }

.game-layout { position: relative; z-index: 1; display: flex; height: calc(100vh - 47px); }
.board-wrap {
  flex: 1; overflow: auto; position: relative;
  background:
    radial-gradient(700px 500px at 50% 40%, rgba(201,162,39,.06), transparent 70%);
  touch-action: pan-x pan-y;
}
.board { position: relative; width: 3000px; height: 3000px; }

/* Tiles */
.tile {
  position: absolute; width: var(--tile); height: var(--tile);
  border-radius: 8px; border: 1px solid rgba(43,35,23,.6);
  background: linear-gradient(160deg, var(--parchment), var(--parch-dim));
  color: var(--ink); font-size: .62rem; text-align: center;
  box-shadow: 0 4px 10px rgba(0,0,0,.5);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  animation: tile-in .35s ease-out;
}
@keyframes tile-in { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.path-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.path-arm rect, .path-hub { fill: rgba(43,35,23,.5); }
.tile .t-icon { position: relative; z-index: 1; font-size: 1.4rem; line-height: 1; }
.tile .t-icon img { width: 38px; height: 38px; object-fit: contain; }

.tile.t-start          { background: linear-gradient(160deg, #f2e8cf, #ddc98f); }
.tile.t-straight,
.tile.t-corner,
.tile.t-t,
.tile.t-intersection   { background: linear-gradient(160deg, #e6d9b6, #c9b98c); }
.tile.t-chest_corner,
.tile.t-chest_straight { background: linear-gradient(160deg, #f5e3a8, #e2c565); }
.tile.t-slime          { background: linear-gradient(160deg, #bfe0a8, #86b96a); }
.tile.t-slime .path-arm rect, .tile.t-slime .path-hub { fill: rgba(38,82,32,.55); }
.tile.t-spike          { background: linear-gradient(160deg, #e0b6ad, #c07f70); }
.tile.t-spike .path-arm rect, .tile.t-spike .path-hub { fill: rgba(96,32,22,.5); }
.tile.t-tunnel         { background: linear-gradient(160deg, #cfc6b8, #9b917f); }
.tile.t-tunnel .path-arm rect, .tile.t-tunnel .path-hub { fill: rgba(20,16,10,.65); }
.tile.t-crown          { background: linear-gradient(160deg, #f0cf9e, #cf9e52); box-shadow: 0 0 18px rgba(201,162,39,.55); }
.tile.t-throne         { background: linear-gradient(160deg, #ffe9a8, #e8b93e); box-shadow: 0 0 22px rgba(238,205,94,.7); }
.tile.pickable { outline: 2px dashed var(--gold-hi); cursor: pointer; }
.tile.pickable:hover { outline-color: #fff; }

.place-preview { display: flex; justify-content: center; margin: 10px 0; }
.preview-tile-inner { position: relative; width: 120px; height: 120px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(43,35,23,.6); box-shadow: 0 6px 16px rgba(0,0,0,.5); }

.tile.ghost {
  background: rgba(201,162,39,.08); border: 2px dashed var(--gold);
  color: var(--gold-hi); cursor: pointer; box-shadow: none; font-size: 1.4rem;
}
.tile.ghost:hover { background: rgba(201,162,39,.2); }

/* Player pawns */
.pawn {
  position: absolute; width: 34px; height: 34px; border-radius: 50%;
  border: 2px solid var(--gold); background: var(--moss-2);
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
  z-index: 2; transition: left .35s ease, top .35s ease;
  box-shadow: 0 3px 8px rgba(0,0,0,.6);
}
.pawn img { width: 26px; height: 26px; object-fit: contain; border-radius: 50%; }
.pawn.me { border-color: var(--gold-hi); box-shadow: 0 0 12px rgba(238,205,94,.7); }
.pawn.dead { filter: grayscale(1); opacity: .4; }
.pawn .crown-mark { position: absolute; top: -14px; font-size: .9rem; }

/* Sidebar */
.sidebar {
  width: 330px; flex-shrink: 0; overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 12px;
  background: rgba(10,18,13,.85); border-left: 1px solid var(--line);
}
.sidebar .panel { padding: 14px; }
.sidebar .section-label { margin-top: 0; }

.my-card { display: flex; gap: 12px; align-items: center; }
.my-card .mc-avatar { font-size: 2.4rem; width: 60px; height: 60px; display:flex; align-items:center; justify-content:center;
  background: rgba(0,0,0,.3); border: 1px solid var(--line); border-radius: 10px; }
.my-card .mc-avatar img { width: 52px; height: 52px; object-fit: contain; }
.my-card .mc-name { font-family: 'Cinzel', serif; font-weight: 700; }
.my-card .mc-stats { font-size: .82rem; color: var(--mist); margin-top: 2px; }
.hp-bar { height: 8px; border-radius: 999px; background: rgba(0,0,0,.4); margin-top: 6px; overflow: hidden; }
.hp-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--ember), var(--ember-hi)); transition: width .3s; }
.my-card .mc-ability { font-size: .75rem; font-style: italic; color: var(--parch-dim); margin-top: 4px; }

.dpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.dpad .dir { padding: 10px 0; }
.dpad .dir[data-dy="-1"] { grid-column: 2; }
.dpad .dir[data-dx="-1"] { grid-column: 1; grid-row: 2; }
.dpad .dir[data-dx="1"]  { grid-column: 3; grid-row: 2; }
.dpad .dir[data-dy="1"]  { grid-column: 2; grid-row: 3; }
.action-grid .btn { margin-bottom: 8px; }

.resource-list { display: flex; flex-direction: column; gap: 8px; }
.res-card {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: rgba(0,0,0,.3); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px;
  font-size: .85rem;
}
.res-card .r-name { color: var(--gold-hi); font-weight: 600; }
.res-card .r-desc { color: var(--mist); font-size: .76rem; }
.res-card .btn { width: auto; padding: 6px 10px; font-size: .78rem; }

.quest-box { font-size: .88rem; }
.quest-box .q-name { color: var(--gold-hi); font-family: 'Cinzel', serif; font-weight: 700; }
.quest-box .q-bar { height: 7px; border-radius: 999px; background: rgba(0,0,0,.4); margin: 8px 0 4px; overflow: hidden; }
.quest-box .q-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold-hi)); transition: width .3s; }
.quest-box .q-done { color: var(--gold-hi); }
.quest-box .q-reward { color: var(--mist); font-size: .78rem; margin-top: 4px; }

.log { max-height: 220px; overflow-y: auto; font-size: .82rem; display: flex; flex-direction: column; gap: 5px; }
.log p { color: var(--parch-dim); border-left: 2px solid rgba(201,162,39,.3); padding-left: 8px; }
.log p:last-child { color: var(--parchment); }

/* Modals */
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { max-width: 420px; width: 100%; max-height: 85vh; overflow-y: auto; }
.modal-card.center { text-align: center; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.crown-big { font-size: 4rem; animation: bob 2s ease-in-out infinite; }
@keyframes bob { 0%,100%{ transform: translateY(0);} 50%{ transform: translateY(-8px);} }
.target-opt, .card-opt {
  display: flex; align-items: center; gap: 10px; padding: 10px; margin-bottom: 8px;
  background: rgba(0,0,0,.3); border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.target-opt.selected, .card-opt.selected { border-color: var(--gold-hi); box-shadow: 0 0 0 1px var(--gold); }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  :root { --tile: 68px; }
  .game-layout { flex-direction: column; }
  .board-wrap { height: 46vh; flex: none; }
  .sidebar { width: 100%; flex: 1; border-left: 0; border-top: 1px solid var(--line); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}


/* ---------- Landing redesign ---------- */
.landing { max-width: 640px; display: flex; flex-direction: column; }
.hero { text-align: center; margin-bottom: 24px; }
.hero .tagline { margin-bottom: 16px; }
.char-strip {
  display: flex; justify-content: center; gap: 6px; flex-wrap: wrap;
  font-size: 1.5rem; filter: drop-shadow(0 3px 6px rgba(0,0,0,.6));
}
.char-strip span {
  display: inline-block; animation: strip-bob 2.6s ease-in-out infinite;
}
.char-strip span:nth-child(2n) { animation-delay: .4s; }
.char-strip span:nth-child(3n) { animation-delay: .9s; }
.char-strip span:nth-child(5n) { animation-delay: 1.4s; }
@keyframes strip-bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

.landing-form { padding: 22px; }
.landing-form .field { margin-bottom: 18px; }
.landing-form .field input { font-size: 1.05rem; padding: 14px 16px; }

.choice-cards { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: stretch; }
.choice-card {
  background: rgba(0,0,0,.28); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; display: flex; flex-direction: column; gap: 14px; justify-content: space-between;
}
.choice-head { display: flex; gap: 12px; align-items: flex-start; }
.choice-icon {
  font-size: 1.6rem; width: 46px; height: 46px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, var(--moss-2), var(--moss));
  border: 1px solid var(--line); border-radius: 10px;
}
.choice-title { font-family: 'Cinzel', serif; font-weight: 700; font-size: 1.05rem; color: var(--gold-hi); }
.choice-sub { font-size: .82rem; color: var(--mist); margin-top: 3px; line-height: 1.35; }
.choice-or { display: flex; align-items: center; justify-content: center; }
.choice-or span {
  color: var(--mist); font-size: .75rem; letter-spacing: .12em; text-transform: uppercase;
  padding: 6px 4px;
}
.landing .join-row { margin-top: auto; }
.landing .code-input { font-size: 1.15rem; }

.landing-facts {
  display: flex; justify-content: center; gap: 10px; margin-top: 22px; flex-wrap: wrap;
}
.fact {
  display: flex; flex-direction: column; align-items: center; min-width: 84px;
  padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: rgba(0,0,0,.25);
}
.fact b { font-family: 'Cinzel', serif; font-size: 1.25rem; color: var(--gold-hi); }
.fact span { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--mist); }

@media (max-width: 560px) {
  .choice-cards { grid-template-columns: 1fr; }
  .choice-or span { padding: 0; }
  .landing-facts { gap: 8px; }
  .fact { min-width: 72px; padding: 8px 10px; }
}


/* Leave buttons */
.leave-btn { margin-top: 14px; width: auto; padding: 9px 16px; font-size: .82rem; opacity: .85; }
.topbar-leave { width: auto; padding: 6px 10px; font-size: .95rem; flex-shrink: 0; }
