:root {
  --gold: #d8a948;
  --gold-soft: #f6d989;
  --blue: #4aa3ff;
  --green: #63d37b;
  --panel: rgba(28, 21, 15, .88);
  font-family: Georgia, 'Noto Serif SC', 'Songti SC', serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; min-height: 100%; background: #080604; color: #f7edd2; }
body { overflow: hidden; }
button { font: inherit; color: #1c1208; cursor: pointer; }
.game-root {
  min-height: 100dvh; min-height: 100svh; overflow: hidden; overscroll-behavior: none;
  display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: clamp(10px, 1.6vw, 22px);
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 78% 18%, rgba(60, 128, 255, .18), transparent 31%),
    radial-gradient(circle at 12% 84%, rgba(151, 22, 16, .25), transparent 34%),
    linear-gradient(135deg, rgba(20, 36, 24, .94), rgba(16, 11, 9, .96) 50%, rgba(39, 25, 14, .96));
}
.hero-panel, .battlefield-shell, .codex, .modal {
  border: 2px solid rgba(216, 169, 72, .56);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.45), 0 18px 60px rgba(0,0,0,.38);
  background: var(--panel);
}
.hero-panel { display: flex; flex-direction: column; min-height: 0; padding: clamp(14px, 2vw, 24px); gap: 18px; }
.brand { display: flex; gap: 14px; align-items: flex-start; }
.crest { width: 52px; height: 52px; display: grid; place-items: center; flex: 0 0 auto; border: 2px solid var(--gold); background: radial-gradient(circle, #61461d, #17100a); color: var(--gold-soft); font-size: 28px; text-shadow: 0 2px 0 #000; }
h1 { margin: 0; font-size: clamp(24px, 3vw, 38px); line-height: 1.05; color: var(--gold-soft); text-shadow: 0 3px 0 #000; }
p { margin: 7px 0 0; color: #d9caa5; line-height: 1.45; }
.hud { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hud-card { padding: 12px; background: rgba(0,0,0,.28); border: 1px solid rgba(216,169,72,.3); }
.hud-card span { display: block; color: #b9a67e; font-size: 13px; }
.hud-card strong { font-size: 26px; color: #fff2bf; letter-spacing: .02em; }
.actions { display: grid; gap: 10px; margin-top: auto; }
.actions button, .modal button { min-height: 46px; border: 2px solid #724d1b; background: linear-gradient(#f8d889, #b9852c 48%, #7c4a19); box-shadow: inset 0 1px 0 rgba(255,255,255,.55), 0 4px 0 #261307; font-weight: 800; }
.actions button:active, .modal button:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255,255,255,.55), 0 2px 0 #261307; }
.battlefield-shell { min-width: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; padding: clamp(10px, 1.4vw, 18px); gap: 10px; }
.status-line { min-height: 32px; display: flex; align-items: center; padding: 6px 12px; color: #f5df9b; background: rgba(0,0,0,.24); border-left: 4px solid var(--gold); }
.board-wrap { position: relative; min-height: 0; width: 100%; height: 100%; display: grid; place-items: center; touch-action: none; user-select: none; overflow: hidden; }
.board { --cell: 78px; display: grid; grid-template-columns: repeat(8, var(--cell)); grid-template-rows: repeat(8, var(--cell)); gap: 7px; padding: 9px; background: rgba(0,0,0,.22); border: 1px solid rgba(246,217,137,.25); }
.tile { position: relative; border: 2px solid #594329; background: #17110b; color: #fff; padding: 0; min-width: 0; min-height: 0; overflow: hidden; box-shadow: inset 0 0 0 2px rgba(255,255,255,.06), 0 4px 8px rgba(0,0,0,.35); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; filter: saturate(1.05) contrast(1.03); }
.tile::before { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 44%, rgba(0,0,0,.78)); pointer-events: none; }
.tile .name { position: absolute; left: 3px; right: 3px; bottom: 3px; z-index: 1; font-size: clamp(10px, 1.25vw, 13px); line-height: 1; color: #ffe7a4; text-shadow: 0 2px 2px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.selected { border-color: #79c4ff; box-shadow: 0 0 0 3px rgba(74,163,255,.45), 0 0 22px rgba(74,163,255,.7); transform: translateY(-2px); }
.tile.hint { border-color: #78ff9b; box-shadow: 0 0 0 3px rgba(99,211,123,.5), 0 0 22px rgba(99,211,123,.7); }
.tile.bad { animation: reject .24s ease-in-out 2; }
.tile.removing { animation: vanish .32s ease forwards; }
@keyframes reject { 0%,100%{transform:translateX(0)} 33%{transform:translateX(-5px)} 66%{transform:translateX(5px)} }
@keyframes vanish { to { opacity: 0; transform: scale(.2) rotate(8deg); filter: brightness(1.8); } }
.path-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }
.path-layer polyline { fill: none; stroke: #71d6ff; stroke-width: 5; stroke-linecap: square; stroke-linejoin: bevel; filter: drop-shadow(0 0 8px #71d6ff); }
.codex { padding: 10px 12px; background: rgba(0,0,0,.24); }
.codex strong { color: #fff1b8; }
.codex p { margin-top: 3px; font-size: 14px; }
.overlay { position: fixed; inset: 0; display: none; place-items: center; background: rgba(0,0,0,.68); z-index: 20; padding: 18px; }
.overlay.show { display: grid; }
.modal { max-width: 520px; padding: 26px; text-align: center; background: linear-gradient(180deg, rgba(47,35,23,.97), rgba(14,10,7,.97)); }
.modal h2 { margin: 0; color: #fff0b8; font-size: 30px; }
.modal p { margin: 12px 0 20px; }
.modal button { min-width: 180px; }
@media (max-width: 1100px) {
  .game-root { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); gap: 8px; }
  .hero-panel { padding: 10px; gap: 8px; }
  .brand { align-items: center; }
  .crest { width: 38px; height: 38px; font-size: 21px; }
  h1 { font-size: 22px; }
  .brand p, .codex { display: none; }
  .hud { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .hud-card { padding: 6px; text-align: center; }
  .hud-card span { font-size: 11px; }
  .hud-card strong { font-size: 18px; }
  .actions { grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 0; }
  .actions button { min-height: 40px; padding: 4px; font-size: 12px; }
  .battlefield-shell { padding: 8px; }
  .status-line { font-size: 13px; min-height: 28px; }
  .board { gap: 4px; padding: 5px; }
  .tile .name { font-size: 10px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .game-root { grid-template-rows: auto minmax(0, 1fr); padding: 4px; gap: 4px; }
  .hero-panel { display: grid; grid-template-columns: .9fr 1fr 1.5fr; align-items: center; padding: 4px; gap: 5px; }
  .brand { gap: 5px; }
  .crest { display: none; }
  h1 { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .hud { gap: 4px; }
  .hud-card { padding: 3px; }
  .hud-card span { display: none; }
  .hud-card strong { font-size: 14px; }
  .actions { gap: 4px; }
  .actions button { min-height: 26px; font-size: 10px; }
  .battlefield-shell { padding: 4px; gap: 3px; }
  .status-line { display: none; }
  .board { gap: 3px; padding: 4px; }
  .tile .name { display: none; }
}
@media (max-width: 520px) and (orientation: portrait) {
  .actions { grid-template-columns: 1fr 1fr; }
  .hud { grid-template-columns: repeat(2, 1fr); }
  .status-line { display: none; }
}
