:root {
  --bg: #14101f; --panel: rgba(24, 16, 34, 0.94); --panel2: rgba(46, 30, 58, 0.95); --line: rgba(255, 210, 140, 0.2);
  --ink: #fff4e0; --muted: #c9b8a6; --gold: #ffd23f; --flame: #ff8a1f; --pink: #ff5fa2; --mint: #3ddc84;
  --sat: env(safe-area-inset-top); --sab: env(safe-area-inset-bottom); --sal: env(safe-area-inset-left); --sar: env(safe-area-inset-right);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
body.touch { -webkit-user-select: none; user-select: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; image-rendering: pixelated; image-rendering: crisp-edges; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 12px; }
body.touch .key-only, body:not(.touch) .touch-only { display: none; }
#loading { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: var(--bg); z-index: 50; }
#loading b { font-size: 34px; letter-spacing: 6px; font-weight: 900; color: var(--gold); }
#loading span { color: var(--muted); }
/* pixel-ish panels: hard edges, a double border */
.px { border: 2px solid #f0c27a; box-shadow: 0 0 0 2px #2a1a10, 4px 4px 0 2px rgba(0, 0, 0, 0.35); border-radius: 3px; }

/* ------------------------------------------------------------ HUD */
#hud { position: fixed; inset: 0; z-index: 8; pointer-events: none; }
.h-left { position: absolute; top: max(8px, var(--sat)); left: max(10px, var(--sal)); display: flex; flex-direction: column; gap: 5px; }
.clock { display: flex; align-items: baseline; gap: 8px; background: var(--panel); padding: 4px 10px; border: 2px solid #f0c27a; border-radius: 3px; box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.4); width: max-content; }
.clock b { font-size: 18px; font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; } .clock span { font-size: 12px; color: var(--muted); }
.clock.late b { color: #ff7a5a; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.5; } }
.stats { display: flex; gap: 6px; }
.st { display: flex; align-items: center; gap: 5px; background: var(--panel); padding: 3px 8px; border-radius: 3px; border: 1px solid var(--line); font-size: 14px; }
.st b { font-variant-numeric: tabular-nums; }
.st .bar { width: 46px; height: 6px; background: rgba(0, 0, 0, 0.5); display: block; } .st .bar em { display: block; height: 100%; width: 0; background: var(--gold); transition: width 0.4s; }
.ico-diya, .ico-oil, .ico-rangoli { width: 14px; height: 14px; display: inline-block; image-rendering: pixelated; background-size: 100% 100%; }
.ico-diya { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 7' shape-rendering='crispEdges'%3E%3Crect x='3' y='0' width='1' height='3' fill='%23ffd23f'/%3E%3Crect x='1' y='4' width='5' height='2' fill='%23b4552a'/%3E%3Crect x='0' y='4' width='7' height='1' fill='%23d97a3a'/%3E%3C/svg%3E"); }
.ico-oil { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 5 7' shape-rendering='crispEdges'%3E%3Crect x='1' y='0' width='3' height='1' fill='%238a5a2a'/%3E%3Crect x='0' y='1' width='5' height='6' fill='%23d8e8f0'/%3E%3Crect x='1' y='3' width='3' height='3' fill='%23f0b829'/%3E%3C/svg%3E"); }
.ico-rangoli { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 9' shape-rendering='crispEdges'%3E%3Crect x='3' y='0' width='3' height='9' fill='%23ff5fa2'/%3E%3Crect x='0' y='3' width='9' height='3' fill='%23ff5fa2'/%3E%3Crect x='3' y='3' width='3' height='3' fill='%23ffd23f'/%3E%3C/svg%3E"); }
.h-right { position: absolute; top: max(8px, var(--sat)); right: max(10px, var(--sar)); display: flex; gap: 6px; pointer-events: auto; }
.h-right button { width: 42px; height: 42px; background: var(--panel); border: 2px solid #f0c27a; border-radius: 3px; font-size: 17px; box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.4); }
.toast { position: absolute; top: calc(max(8px, var(--sat)) + 6px); left: 50%; transform: translateX(-50%); max-width: min(480px, 60vw); background: var(--panel); border: 2px solid #f0c27a; border-radius: 3px; padding: 7px 12px; font-weight: 800; font-size: 14px; text-align: center; box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.4); }
.hint { position: absolute; bottom: calc(max(10px, var(--sab)) + 6px); left: 50%; transform: translateX(-50%); font-weight: 800; font-size: 14px; color: var(--ink); text-shadow: 0 2px 0 #000, 0 0 8px #000; white-space: nowrap; }
.dialog { position: absolute; left: 50%; transform: translateX(-50%); bottom: max(14px, var(--sab)); width: min(620px, 92vw); background: var(--panel); border: 2px solid #f0c27a; border-radius: 3px; box-shadow: 0 0 0 2px #2a1a10, 5px 5px 0 2px rgba(0, 0, 0, 0.4); padding: 10px 14px 12px; pointer-events: auto; cursor: pointer; }
.dialog b { color: var(--gold); font-size: 14px; letter-spacing: 1px; text-transform: uppercase; }
.dialog p { margin: 4px 0 0; font-size: 16px; line-height: 1.45; min-height: 46px; }
.dialog .more { position: absolute; right: 12px; bottom: 6px; color: var(--gold); animation: blink 0.8s infinite; font-size: 12px; }
.tpad { display: none; }
body.touch.playing .tpad { display: block; }
.stick { position: absolute; left: calc(max(16px, var(--sal)) + 10px); bottom: calc(max(16px, var(--sab)) + 6px); width: 118px; height: 118px; border-radius: 50%; background: rgba(255, 244, 224, 0.07); border: 2px solid rgba(255, 210, 140, 0.35); pointer-events: auto; touch-action: none; }
.stick i { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; margin: -25px 0 0 -25px; border-radius: 50%; background: rgba(255, 210, 140, 0.35); border: 2px solid rgba(255, 210, 140, 0.6); }
.act { position: absolute; right: calc(max(16px, var(--sar)) + 14px); bottom: calc(max(16px, var(--sab)) + 18px); width: 82px; height: 82px; border-radius: 50%; background: rgba(255, 138, 31, 0.35); border: 3px solid rgba(255, 210, 63, 0.75); font-size: 30px; pointer-events: auto; touch-action: none; }
.act.ready { background: rgba(255, 138, 31, 0.7); box-shadow: 0 0 24px rgba(255, 180, 60, 0.6); }
body.touch .hint { bottom: calc(max(10px, var(--sab)) + 112px); right: calc(max(16px, var(--sar)) + 8px); left: auto; transform: none; font-size: 13px; text-align: right; }
body.touch .dialog { bottom: max(10px, var(--sab)); width: min(520px, calc(100vw - 300px)); }
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(8, 6, 16, 0.6); pointer-events: auto; padding: max(10px, var(--sat)) max(10px, var(--sar)) max(10px, var(--sab)) max(10px, var(--sal)); }
.overlay .panel { background: var(--panel); border: 2px solid #f0c27a; border-radius: 3px; box-shadow: 0 0 0 2px #2a1a10, 6px 6px 0 2px rgba(0, 0, 0, 0.4); padding: 10px 14px 12px; max-width: 94vw; max-height: 100%; overflow: auto; }
.overlay header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; }
.overlay h3 { margin: 0; color: var(--gold); font-size: 17px; } .overlay header button { background: transparent; border: 0; font-size: 18px; }
#mapcv { display: block; image-rendering: pixelated; max-width: 100%; max-height: calc(100vh - 110px); }
.legend { margin: 6px 0 0; font-size: 12px; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; } .legend i { display: inline-block; width: 8px; height: 8px; margin-right: 4px; }
#quests { list-style: none; padding: 0; margin: 0; min-width: min(420px, 80vw); }
#quests li { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; } #quests li b { display: block; } #quests li small { color: var(--muted); }
#quests li.done b { color: var(--mint); text-decoration: line-through; } #quests li.todo b { color: var(--gold); }
#rotate { display: none; position: fixed; inset: 0; z-index: 40; background: var(--bg); flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 24px; }
#rotate b { font-size: 54px; color: var(--gold); } #rotate p { font-size: 17px; max-width: 280px; }
@media (orientation: portrait) and (pointer: coarse) { body.playing #rotate { display: flex; } }

/* ------------------------------------------------------------ screens */
#ui { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.screen { position: absolute; inset: 0; display: none; pointer-events: auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: max(16px, var(--sat)) max(16px, var(--sar)) max(16px, var(--sab)) max(16px, var(--sal)); background: rgba(10, 6, 18, 0.55); }
.screen.active { display: flex; }
.screen > * { margin: auto; }
#title.screen { background: linear-gradient(90deg, rgba(14, 10, 24, 0.94) 0%, rgba(14, 10, 24, 0.66) 46%, rgba(14, 10, 24, 0.05) 100%); gap: 24px; align-items: center; }
.t-main { max-width: 500px; width: 100%; margin: auto auto auto clamp(0px, 5vw, 80px); }
.kicker { color: var(--gold); letter-spacing: 1.5px; text-transform: uppercase; font-size: 12.5px; font-weight: 800; margin: 0; }
.logo { margin: 6px 0 10px; font-size: clamp(54px, 9vw, 100px); line-height: 0.85; font-weight: 900; letter-spacing: 4px; color: #fff4e0;
  text-shadow: 4px 4px 0 #b4552a, 8px 8px 0 rgba(0, 0, 0, 0.4), 0 0 40px rgba(255, 170, 60, 0.45); }
.logo span { color: var(--gold); text-shadow: 4px 4px 0 #8a3a1c, 8px 8px 0 rgba(0, 0, 0, 0.4), 0 0 50px rgba(255, 210, 63, 0.7); }
.lead { color: #f2e4cf; font-size: 15.5px; line-height: 1.5; margin: 0 0 16px; }
.challenge:empty { display: none; }
.challenge { background: rgba(255, 210, 63, 0.12); border: 2px solid rgba(255, 210, 63, 0.5); padding: 8px 12px; border-radius: 3px; margin-bottom: 12px; }
.menu { display: flex; flex-direction: column; gap: 8px; }
.menu .row { display: flex; gap: 8px; } .menu .row button { flex: 1; }
.menu button, .buttons button { background: var(--panel2); border: 2px solid var(--line); border-radius: 3px; padding: 12px 16px; font-size: 17px; font-weight: 800; text-align: left; box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.35); }
.menu button:hover, .buttons button:hover { border-color: var(--gold); }
.menu button:active, .buttons button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.35); }
button.primary { background: linear-gradient(180deg, #ffd23f, #ff9a2a) !important; color: #2a1200 !important; border-color: #fff0b0 !important; }
button.ghost { background: transparent; border: 2px solid var(--line); border-radius: 3px; padding: 6px 12px; color: var(--muted); }
.disclaimer { color: var(--muted); font-size: 12px; margin-top: 14px; line-height: 1.45; } .disclaimer a { color: var(--muted); }
.t-side { width: 320px; max-width: 100%; margin: auto clamp(0px, 4vw, 60px) auto auto; display: flex; flex-direction: column; gap: 10px; }
.t-side > div:empty { display: none; }
.gl-board { background: var(--panel); border: 2px solid var(--line); border-radius: 3px; padding: 10px; }
.sheet { background: var(--panel); border: 2px solid #f0c27a; border-radius: 3px; box-shadow: 0 0 0 2px #2a1a10, 6px 6px 0 2px rgba(0, 0, 0, 0.4); padding: 18px 20px 20px; width: 100%; max-width: 760px; }
.sheet.wide { max-width: 960px; } .sheet.narrow { max-width: 380px; }
.sheet header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.sheet h2 { margin: 0; font-size: 26px; font-weight: 900; }
.sheet h4 { margin: 12px 0 6px; font-size: 12.5px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--gold); }
.help { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.help p { font-size: 14px; line-height: 1.5; color: #f2e4cf; margin: 0 0 10px; }
.srow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.srow input[type=range] { flex: 1; max-width: 170px; accent-color: var(--gold); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: rgba(255, 255, 255, 0.06); border: 2px solid var(--line); border-radius: 3px; padding: 5px 12px; font-weight: 800; font-size: 13.5px; }
.chip.on { background: var(--gold); color: #2a1200; border-color: var(--gold); }
.rh { margin: 2px 0 4px; font-size: 32px; font-weight: 900; }
.pct { font-size: 64px; font-weight: 900; color: var(--gold); line-height: 1; text-shadow: 4px 4px 0 #8a3a1c; } .pct small { font-size: 18px; color: var(--muted); text-shadow: none; margin-left: 8px; }
.rgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 10px; }
.near { color: var(--gold); font-size: 14px; margin: 6px 0 0; }
.kv { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.kv li { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 4px 0; color: var(--muted); } .kv li b { color: var(--ink); }
.kv li.total { color: var(--gold); font-size: 17px; } .kv li.total b { color: var(--gold); }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; } .buttons button { flex: 1 1 140px; text-align: center; }
.e-board:empty { display: none; } .e-board { margin: 12px 0 0; }

@media (max-height: 460px) {
  .clock b { font-size: 15px; } .clock span { display: none; } .st { font-size: 12px; padding: 2px 6px; } .st .bar { width: 34px; }
  .h-right button { width: 36px; height: 36px; font-size: 15px; }
  .stick { width: 100px; height: 100px; } .stick i { width: 42px; height: 42px; margin: -21px 0 0 -21px; } .act { width: 70px; height: 70px; font-size: 26px; }
  body.touch .hint { bottom: calc(max(10px, var(--sab)) + 92px); }
  .dialog p { font-size: 14px; min-height: 0; } .toast { font-size: 12.5px; padding: 5px 10px; }
  #title.screen { gap: 14px; } .logo { font-size: 50px; } .lead { font-size: 13px; margin-bottom: 10px; line-height: 1.4; } .menu button { padding: 8px 14px; font-size: 15px; } .menu { gap: 6px; } .disclaimer { margin-top: 8px; font-size: 11px; }
  .t-side { width: 260px; } .t-side .gl-board { max-height: 62vh; overflow: auto; }
  .sheet { padding: 12px 14px; } .sheet h2 { font-size: 21px; } .help p { font-size: 12.5px; }
  .rh { font-size: 22px; } .pct { font-size: 40px; } .rgrid { gap: 10px; margin-top: 4px; } .kv { font-size: 12.5px; } .kv li { padding: 2px 0; }
  .buttons { position: sticky; bottom: -12px; background: var(--panel); padding: 6px 0; margin-top: 6px; } .buttons button { padding: 8px 10px; font-size: 14px; }
}
@media (max-width: 760px) { .help { grid-template-columns: 1fr; } .rgrid { grid-template-columns: 1fr; } }
@media (orientation: landscape) and (max-height: 460px) { .help { grid-template-columns: repeat(3, 1fr); } .rgrid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) and (orientation: portrait) {
  #title.screen { flex-direction: column; align-items: stretch; background: linear-gradient(180deg, rgba(14, 10, 24, 0.25), rgba(14, 10, 24, 0.94) 40%); }
  .t-main { margin: 30vh 0 0; } .t-side { width: 100%; margin: 0; }
}
body.finale .tpad, body.finale .hint, body.finale .h-right, body.finale .dialog { display: none !important; }
