:root {
  color-scheme: dark;
  font-family: Inter, Pretendard, system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  background: #071713;
  color: #f8fafc;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-width: 320px; min-height: 100%; margin: 0; overflow: hidden; }
body { background: #071713; }
button { min-height: 44px; border: 0; border-radius: 7px; font: inherit; font-weight: 850; letter-spacing: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 3px solid #facc15; outline-offset: 2px; }
button:disabled { cursor: wait; opacity: .42; }

#app { display: grid; grid-template-rows: auto minmax(0, 1fr); width: 100vw; height: 100vh; height: 100dvh; padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left); background: radial-gradient(circle at 50% 0, #123b30 0, #071713 55%); }
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 58px; padding: 8px clamp(10px, 2vw, 24px); border-bottom: 1px solid #2c5448; background: rgba(5, 20, 16, .94); }
.brand { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.brand span { color: #facc15; font-size: .72rem; font-weight: 950; }
.brand strong { overflow: hidden; color: #fff; font-size: clamp(.85rem, 2vw, 1.15rem); text-overflow: ellipsis; white-space: nowrap; }
.turn-chip { padding: 7px 12px; border: 1px solid #4f7d70; border-radius: 999px; color: #d1fae5; background: #102a23; font-size: .82rem; font-weight: 850; }
.top-actions { display: flex; justify-content: flex-end; gap: 7px; }
.icon-btn { width: 42px; min-height: 42px; padding: 0; border: 1px solid #42685d; background: #102a23; color: #f8fafc; font-size: 1.2rem; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) clamp(280px, 27vw, 390px); min-height: 0; }
.board-area { display: grid; min-width: 0; min-height: 0; place-items: center; padding: clamp(8px, 1.5vw, 20px); }
#board { display: block; width: min(100%, calc(100dvh - 94px)); height: auto; max-height: 100%; aspect-ratio: 1; border: 1px solid #3d6c5e; border-radius: 8px; background: #0b221c; box-shadow: 0 24px 70px rgba(0, 0, 0, .42); touch-action: none; }

.control-rail { display: grid; grid-template-rows: auto auto minmax(90px, 1fr) minmax(80px, .7fr); min-height: 0; gap: 10px; padding: 12px; border-left: 1px solid #2c5448; background: rgba(7, 23, 19, .88); }
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.player { min-width: 0; padding: 10px; border: 1px solid #31594e; border-radius: 7px; background: #102a23; }
.player.active { border-color: currentColor; box-shadow: inset 0 -3px currentColor; }
.player--one { color: #ff8798; }
.player--two { color: #79e4e7; }
.player h2 { margin: 0 0 5px; overflow: hidden; color: currentColor; font-size: .82rem; text-overflow: ellipsis; white-space: nowrap; }
.player strong { display: block; color: #fff; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.player span { color: #a7c8bd; font-size: .7rem; }

.turn-panel { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 8px 10px; align-items: center; padding-block: 2px; }
.dice { display: flex; gap: 6px; grid-row: span 2; }
.dice span { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 6px; background: #f8fafc; color: #102a23; font-size: 1rem; font-weight: 950; box-shadow: inset 0 -4px #cbd5e1; }
#actionText { min-height: 34px; margin: 0; color: #cbe4dc; font-size: .8rem; line-height: 1.35; }
.primary { width: 100%; background: #facc15; color: #1c1917; }
.decision { display: grid; grid-column: 1 / -1; grid-template-columns: 1fr 1fr; gap: 8px; }
.decision .buy { background: #34d399; color: #062d23; }
.decision .pass { background: #334155; color: #f8fafc; }
.hidden { display: none !important; }

.assets-panel { min-height: 0; overflow: hidden; }
.assets-panel h2 { margin: 0 0 7px; color: #facc15; font-size: .74rem; text-transform: uppercase; }
.asset-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: calc(100% - 24px); gap: 6px; overflow: auto; }
.asset { min-width: 0; padding: 7px 8px; border-left: 4px solid var(--city); background: #102a23; }
.asset strong, .asset span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset strong { font-size: .75rem; }
.asset span { color: #9dc3b7; font-size: .66rem; }
.empty { color: #789b90; font-size: .75rem; }
.game-log { min-height: 0; margin: 0; padding: 8px 8px 8px 26px; overflow: auto; border-top: 1px solid #31594e; color: #92b8ac; font-size: .68rem; line-height: 1.5; }

.modal { position: fixed; inset: 0; z-index: 20; display: grid; padding: calc(var(--safe-top) + 16px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 16px) calc(var(--safe-left) + 16px); place-items: center; background: rgba(2, 12, 9, .74); backdrop-filter: blur(8px); }
.modal-panel { display: grid; width: min(480px, 100%); max-height: 100%; gap: 16px; padding: clamp(18px, 4vw, 28px); overflow: auto; border: 1px solid #4a7669; border-radius: 8px; background: #0d251f; box-shadow: 0 30px 80px rgba(0, 0, 0, .5); }
.eyebrow { margin: 0; color: #facc15; font-size: .7rem; font-weight: 950; }
.modal h1, .modal h2 { margin: 0; letter-spacing: 0; }
.modal h1 { font-size: clamp(1.8rem, 7vw, 2.8rem); }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode-option { display: grid; min-height: 90px; align-content: center; gap: 6px; padding: 10px; border: 1px solid #31594e; background: #102a23; color: #f8fafc; }
.mode-option.selected { border-color: #facc15; background: #263a25; }
.mode-option span { color: #a7c8bd; font-size: .72rem; font-weight: 650; }
.difficulty { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 5px; background: #071713; }
.difficulty button { background: #263d36; color: #d9eee7; }
.difficulty button.selected { background: #52d3d8; color: #062b2d; }
.modal-heading { display: flex; align-items: center; justify-content: space-between; }
.rules-panel ul { display: grid; gap: 10px; margin: 0; padding-left: 20px; color: #cbe4dc; font-size: .9rem; line-height: 1.5; }

@media (max-width: 820px) {
  .topbar { grid-template-columns: 1fr auto; }
  .turn-chip { position: fixed; z-index: 5; left: 50%; bottom: calc(var(--safe-bottom) + 10px); transform: translateX(-50%); box-shadow: 0 6px 20px #0008; }
  .game-layout { grid-template-columns: 1fr; grid-template-rows: minmax(0, 56dvh) minmax(0, 44dvh); overflow: hidden; }
  .board-area { padding: 6px; }
  #board { width: min(100%, 55dvh); }
  .control-rail { grid-template-columns: 1fr 1fr; grid-template-rows: auto minmax(0, 1fr); padding: 8px 8px calc(var(--safe-bottom) + 54px); border-top: 1px solid #2c5448; border-left: 0; }
  .players, .turn-panel { min-width: 0; }
  .turn-panel { grid-template-columns: 66px minmax(0, 1fr); }
  .assets-panel, .game-log { display: none; }
}

@media (max-width: 480px) {
  .topbar { min-height: 52px; padding: 6px 8px; }
  .brand span { display: none; }
  .game-layout { grid-template-rows: minmax(0, 53dvh) minmax(0, 47dvh); }
  #board { width: min(100%, 52dvh); }
  .control-rail { grid-template-columns: 1fr; grid-template-rows: auto auto; gap: 6px; }
  .player { padding: 7px 8px; }
  .turn-panel { grid-template-columns: 66px minmax(0, 1fr); }
  .mode-grid { grid-template-columns: 1fr; }
}
