:root {
  --green-900: #0d2a12;
  --green-700: #1b5e20;
  --green-500: #2e7d32;
  --gold: #d9a93a;
  --gold-soft: #f3d98b;
  --cream: #fbf6e9;
  --ink: #1d2a1f;
  --muted: #5d6b5f;
  --hud: rgba(12, 24, 14, 0.72);
  --radius: 18px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--green-900); color: var(--ink); font-family: 'Noto Sans Malayalam', 'Segoe UI', system-ui, sans-serif; }
button { font: inherit; cursor: pointer; }
h1, h2 { font-family: 'Baloo Chettan 2', 'Noto Sans Malayalam', sans-serif; margin: 0; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: none; overflow: auto; padding: 16px; }
.screen.active { display: flex; }
#screen-start, #screen-district, #screen-place {
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(243, 217, 139, 0.25), transparent 60%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.025) 0 14px, transparent 14px 28px),
    radial-gradient(circle at 70% 120%, #2e7d32 0%, #14401a 50%, var(--green-900) 100%);
}
.panel {
  margin: auto; width: min(880px, 100%);
  background: var(--cream); border-radius: var(--radius);
  padding: 28px; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
  position: relative; overflow: hidden;
}
/* kasavu border */
.panel::before { content: ''; position: absolute; inset: 0 0 auto 0; height: 10px; background: linear-gradient(var(--gold) 0 60%, #b8862a 60% 70%, var(--gold) 70%); }
.panel.wide { width: min(1080px, 100%); }

.brand { display: flex; gap: 16px; align-items: center; margin: 6px 0 20px; }
.logo { width: 64px; height: 64px; border-radius: 16px; display: grid; place-items: center; font-size: 36px; background: var(--green-700); box-shadow: inset 0 0 0 3px var(--gold); }
h1 { font-size: clamp(30px, 5vw, 44px); color: var(--green-700); line-height: 1.1; }
.sub { margin: 4px 0 0; color: var(--muted); }

.start-grid { display: grid; grid-template-columns: 280px 1fr; gap: 24px; }
#preview { height: 360px; border-radius: 16px; background: linear-gradient(#cfe8f5, #f6f0dc); overflow: hidden; }
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 8px; font-weight: 600; font-size: 14px; color: var(--green-700); }
.field input { font: inherit; font-size: 17px; padding: 12px 14px; border-radius: 12px; border: 2px solid #d8cfb5; background: #fff; outline: none; }
.field input:focus { border-color: var(--green-500); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { padding: 8px 16px; border-radius: 999px; border: 2px solid #d8cfb5; background: #fff; color: var(--ink); }
.chip.on { background: var(--green-700); border-color: var(--green-700); color: #fff; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 2px solid rgba(0, 0, 0, 0.15); padding: 0; }
.swatch.on { outline: 3px solid var(--gold); outline-offset: 2px; }
.primary { margin-top: 6px; padding: 14px 18px; border: 0; border-radius: 14px; font-size: 19px; font-weight: 700; color: #fff; background: linear-gradient(135deg, var(--green-500), var(--green-700)); box-shadow: 0 6px 0 #0f3d13; transition: transform 0.08s; }
.primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #0f3d13; }

/* ---------- district & place grids ---------- */
.head { display: flex; align-items: center; gap: 14px; margin: 6px 0 20px; }
.head h2 { font-size: clamp(24px, 4vw, 34px); color: var(--green-700); }
.head h2 small { display: block; font-family: 'Noto Sans Malayalam', sans-serif; font-size: 14px; color: var(--muted); font-weight: 500; }
.back { width: 44px; height: 44px; border-radius: 12px; border: 2px solid #d8cfb5; background: #fff; font-size: 20px; flex: none; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.grid.places { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card { text-align: left; display: flex; flex-direction: column; gap: 4px; padding: 16px; border-radius: 16px; border: 2px solid #e7dcc0; background: #fff; transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s; animation: rise 0.35s both; animation-delay: calc(var(--i, 0) * 25ms); }
.card:hover, .card:focus-visible { transform: translateY(-3px); border-color: var(--gold); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12); outline: none; }
.card .num { font-size: 12px; font-weight: 700; color: var(--gold); letter-spacing: 1px; }
.card .ml { font-family: 'Baloo Chettan 2', sans-serif; font-size: 22px; font-weight: 800; color: var(--green-700); line-height: 1.2; }
.card .en { font-size: 13px; color: var(--muted); }
.card .count { margin-top: 6px; font-size: 12px; color: #9a9a9a; }
.card .count.live { color: #2e9e3a; font-weight: 700; }
.card.place .icon { font-size: 40px; }
.card.place .desc { font-size: 14px; color: var(--ink); margin-top: 4px; }
.card.place .go { margin-top: 10px; font-weight: 700; color: var(--green-500); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------- game ---------- */
#screen-game { padding: 0; overflow: hidden; background: #000; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hud { position: absolute; color: #fff; background: var(--hud); backdrop-filter: blur(6px); border-radius: 14px; border: 1px solid rgba(243, 217, 139, 0.25); }
.hud-top { top: 12px; left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: transparent; border: 0; backdrop-filter: none; pointer-events: none; }
.hud-top > div { background: var(--hud); padding: 8px 14px; border-radius: 12px; border: 1px solid rgba(243, 217, 139, 0.25); }
#place-label { font-family: 'Baloo Chettan 2', sans-serif; font-size: 22px; font-weight: 800; color: var(--gold-soft); }
#place-sub { font-size: 12px; opacity: 0.85; }
.ghost { pointer-events: auto; padding: 10px 14px; border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.3); background: var(--hud); color: #fff; }
.hud-players { top: 86px; right: 12px; width: 230px; max-height: 40vh; overflow: auto; padding: 10px; }
.hud-title { font-weight: 700; font-size: 13px; color: var(--gold-soft); margin-bottom: 6px; }
#player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
#player-list li { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 6px; border-radius: 8px; background: rgba(255, 255, 255, 0.06); }
#player-list li.me { color: #9ccc65; }
.pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini { border: 0; background: rgba(255, 255, 255, 0.12); border-radius: 6px; padding: 2px 6px; font-size: 13px; }
.hud-chat { left: 12px; bottom: 12px; width: min(380px, calc(100% - 24px)); padding: 10px; }
#chat-log { height: 170px; overflow-y: auto; font-size: 14px; line-height: 1.45; padding-right: 4px; }
.msg { margin-bottom: 2px; word-wrap: break-word; }
.msg.sys { color: var(--gold-soft); font-size: 12px; font-style: italic; }
#chat-form { display: flex; gap: 6px; margin-top: 8px; }
#chat-input { flex: 1; min-width: 0; font: inherit; padding: 9px 12px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, 0.25); background: rgba(255, 255, 255, 0.1); color: #fff; outline: none; }
#chat-input:focus { border-color: var(--gold); background: rgba(255, 255, 255, 0.16); }
#chat-form button { border: 0; border-radius: 10px; padding: 0 14px; background: var(--green-500); color: #fff; font-weight: 700; }
.hud-actions { right: 12px; bottom: 12px; display: flex; gap: 6px; padding: 8px; }
.hud-actions button { border: 0; border-radius: 10px; padding: 10px 12px; background: rgba(255, 255, 255, 0.12); color: #fff; font-size: 16px; }
.hud-actions button:hover { background: rgba(255, 255, 255, 0.22); }
#btn-mic.on { background: #c62828; }
.help { position: absolute; left: 50%; transform: translateX(-50%); bottom: 14px; font-size: 12px; color: #fff; background: rgba(0, 0, 0, 0.45); padding: 6px 12px; border-radius: 999px; white-space: nowrap; pointer-events: none; }

/* touch d-pad (phones / tablets) */
.dpad { display: none; position: absolute; right: 16px; bottom: 90px; width: 170px; height: 170px; }
.dpad button { position: absolute; width: 56px; height: 56px; border-radius: 14px; border: 0; background: rgba(0, 0, 0, 0.45); color: #fff; font-size: 20px; touch-action: none; user-select: none; }
.dpad .up { left: 57px; top: 0; } .dpad .down { left: 57px; bottom: 0; }
.dpad .left { left: 0; top: 57px; } .dpad .right { right: 0; top: 57px; }
.dpad .run { left: 57px; top: 57px; font-size: 12px; background: rgba(217, 169, 58, 0.6); }
body.touch .dpad { display: block; }
body.touch .help { display: none; }

#toast { position: fixed; left: 50%; top: 20px; transform: translate(-50%, -80px); background: #102814; color: #fff; padding: 12px 18px; border-radius: 12px; border: 1px solid var(--gold); transition: transform 0.25s; z-index: 50; max-width: 90vw; }
#toast.show { transform: translate(-50%, 0); }

@media (max-width: 720px) {
  .panel { padding: 20px 16px; }
  .start-grid { grid-template-columns: 1fr; }
  #preview { height: 240px; }
  .hud-players { top: auto; bottom: 280px; right: auto; left: 12px; width: 190px; max-height: 22vh; }
  #chat-log { height: 110px; }
  .hud-chat { width: calc(100% - 210px); }
  .hud-actions { bottom: auto; top: 76px; }
  .help { display: none; }
  .grid { grid-template-columns: repeat(2, 1fr); }
}
