/* Mossgate — NNPlays 3D menu standard, themed: moss stone, lantern amber,
   cold sigil teal, carved Cinzel capitals. */
:root {
  --accent: #ffb04a;            /* lantern */
  --accent2: #3dffc4;           /* sigil */
  --moss: #6f8f45;
  --text: #ece6d8;
  --muted: #a39d8c;
  --panel: rgba(14, 16, 14, .72);
  --line: rgba(220, 200, 150, .16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; background: #030406; color: var(--text); font-family: "DM Sans", system-ui, sans-serif; overscroll-behavior: none; }
button { font-family: inherit; color: inherit; cursor: pointer; }

.game-shell { width: 100%; height: 100%; display: flex; flex-direction: column; background: #030406; }
.game-bar { height: 52px; flex-shrink: 0; display: flex; align-items: center; gap: .6rem; padding: max(6px, var(--safe-top)) max(12px, var(--safe-right)) 6px max(12px, var(--safe-left));
  background: linear-gradient(180deg, rgba(10, 12, 9, .92), rgba(10, 12, 9, .7)); border-bottom: 1px solid var(--line); z-index: 30; }
.back-link { display: inline-flex; align-items: center; gap: .3rem; text-decoration: none; color: var(--muted); font-weight: 700; font-size: .82rem; }
.back-link:hover { color: var(--text); }
.game-bar-title { flex: 1; font: 800 .9rem/1 Cinzel, Georgia, serif; letter-spacing: .18em; text-transform: uppercase; color: var(--accent); text-shadow: 0 0 14px rgba(255, 160, 60, .35); }
.player-pill { font-size: .72rem; font-weight: 700; color: var(--muted); background: rgba(255, 255, 255, .05); border: 1px solid var(--line); padding: .25rem .6rem; border-radius: 999px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, .04); font-size: 1rem; display: grid; place-items: center; }
.icon-btn:active { transform: scale(.94); }

.game-wrap { flex: 1; position: relative; overflow: hidden; background: #000; touch-action: none; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
body.playing #game-canvas { cursor: crosshair; }

/* ── atmosphere overlays (cheap: CSS instead of post-processing) ── */
.fx { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.vignette { background: radial-gradient(ellipse at 50% 55%, transparent 38%, rgba(0, 0, 0, .55) 78%, rgba(0, 0, 0, .9) 100%); }
.dark { background: #000; opacity: .1; transition: opacity 1.2s ease; }
.danger { background: radial-gradient(ellipse at 50% 50%, transparent 35%, rgba(120, 0, 10, .55) 85%, rgba(60, 0, 0, .9) 100%); opacity: 0; transition: opacity .25s linear; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { filter: brightness(1.35); } }
.grain { opacity: .5; mix-blend-mode: overlay; background-size: 96px 96px; animation: grain .5s steps(4) infinite; }
@keyframes grain { 0% { background-position: 0 0; } 25% { background-position: 31px 57px; } 50% { background-position: 73px 13px; } 75% { background-position: 19px 81px; } }
.flash { background: radial-gradient(circle, rgba(255, 240, 240, .2), rgba(160, 0, 0, .75)); opacity: 0; }
.flash.show { animation: flash 1.5s ease-out forwards; }
@keyframes flash { 0% { opacity: 1; } 12% { opacity: .2; } 20% { opacity: .9; } 100% { opacity: .65; background: #000; } }
.reduced .grain, .reduced .danger { animation: none; }
/* lightning: a cold blue-white stutter over the whole view */
.storm { background: radial-gradient(ellipse at 40% 0%, rgba(220, 235, 255, .55), rgba(150, 175, 230, .18) 60%, transparent); opacity: 0; mix-blend-mode: screen; }
.storm.show { animation: bolt 0.9s ease-out forwards; }
@keyframes bolt { 0% { opacity: .9; } 8% { opacity: .15; } 16% { opacity: 1; } 30% { opacity: .35; } 100% { opacity: 0; } }
.reduced .storm.show { animation: none; }
/* gate compass (after all three sigils) */
.gate-arrow { position: absolute; left: 50%; top: 92px; width: 54px; height: 54px; transform: translate(-50%, -50%); opacity: 0; transition: opacity .6s; pointer-events: none; }
.gate-arrow.show { opacity: 1; }
.gate-arrow i { position: absolute; left: 50%; top: 2px; width: 0; height: 0; margin-left: -9px; border: 9px solid transparent; border-bottom: 18px solid var(--accent2); filter: drop-shadow(0 0 8px var(--accent2)); transform-origin: 9px 25px; }
.gate-arrow b { position: absolute; left: 50%; top: 34px; transform: translateX(-50%); font: 700 .7rem/1 "DM Sans", sans-serif; color: #bfffe9; text-shadow: 0 0 8px #000; white-space: nowrap; }

/* ── HUD ── */
.hud { position: absolute; inset: 0; z-index: 12; pointer-events: none; padding: 10px max(12px, var(--safe-right)) max(10px, var(--safe-bottom)) max(12px, var(--safe-left)); }
.hud.hidden { display: none; }
.hud-top { display: flex; align-items: center; gap: 10px; }
.oil { display: flex; align-items: center; gap: .45rem; padding: .35rem .65rem; border-radius: 12px; background: rgba(10, 10, 8, .55); border: 1px solid var(--line); backdrop-filter: blur(6px); }
.oil-ico { font-size: 1rem; filter: drop-shadow(0 0 6px rgba(255, 160, 60, .7)); }
.oil-bar { width: clamp(70px, 18vw, 150px); height: 8px; border-radius: 6px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.oil-bar i { display: block; height: 100%; background: linear-gradient(90deg, #a8521a, var(--accent)); transform-origin: left; box-shadow: 0 0 10px rgba(255, 160, 60, .6); transition: transform .25s linear; }
.oil b { font-size: .78rem; font-variant-numeric: tabular-nums; min-width: 3ch; }
.oil.low .oil-bar i { background: linear-gradient(90deg, #8a1a0a, #ff6a2a); animation: blink .6s ease-in-out infinite; }
.oil.out { border-color: rgba(255, 60, 40, .5); }
.oil.out b { color: #ff6a50; }
@keyframes blink { 50% { opacity: .35; } }
.sigils { display: flex; gap: 8px; margin: 0 auto; }
.sigils i { width: 18px; height: 18px; transform: rotate(45deg); border: 2px solid rgba(61, 255, 196, .35); border-radius: 3px; background: rgba(0, 0, 0, .35); transition: all .35s; }
.sigils i.on { background: var(--accent2); border-color: #bfffe9; box-shadow: 0 0 14px var(--accent2); }
.hud-btn { pointer-events: all; width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--line); background: rgba(10, 10, 8, .55); font-weight: 900; }
.crosshair { position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px; border-radius: 50%; background: rgba(255, 240, 210, .55); box-shadow: 0 0 6px rgba(255, 200, 120, .6); }
.stamina-wrap { position: absolute; left: 50%; top: calc(50% + 22px); width: 64px; height: 3px; margin-left: -32px; border-radius: 3px; background: rgba(255, 255, 255, .1); opacity: 0; transition: opacity .4s; overflow: hidden; }
.stamina-wrap.show { opacity: 1; }
.stamina-wrap i { display: block; height: 100%; background: #e8e0c8; transform-origin: left; }
.toast { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); max-width: min(88vw, 560px); text-align: center; font: 600 clamp(.95rem, 2.4vw, 1.2rem)/1.35 Cinzel, Georgia, serif; letter-spacing: .03em;
  color: #f3ead2; text-shadow: 0 2px 12px #000, 0 0 24px rgba(0, 0, 0, .9); opacity: 0; }
.toast.show { animation: toast 3.4s ease forwards; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, 8px); } 10% { opacity: 1; transform: translate(-50%, 0); } 80% { opacity: 1; } 100% { opacity: 0; } }

/* touch controls (only on touch devices) */
.stick { position: absolute; width: 112px; height: 112px; margin: -56px 0 0 -56px; border-radius: 50%; border: 2px solid rgba(255, 230, 190, .22); background: rgba(0, 0, 0, .18); display: none; }
.stick.show { display: block; }
.stick i { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px; border-radius: 50%; background: rgba(255, 230, 190, .28); }
.touch-btns { position: absolute; right: max(14px, var(--safe-right)); bottom: max(18px, calc(var(--safe-bottom) + 12px)); display: none; flex-direction: column; align-items: center; gap: 12px; }
.tbtn { pointer-events: all; width: 58px; height: 58px; border-radius: 50%; border: 2px solid rgba(255, 230, 190, .25); background: rgba(10, 10, 8, .5); font-size: 1.4rem; display: grid; place-items: center; backdrop-filter: blur(4px); touch-action: none; }
.tbtn.big { width: 76px; height: 76px; font-size: 1.6rem; line-height: 1; }
.tbtn small { display: block; font-size: .56rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.tbtn.on { background: rgba(255, 176, 74, .3); border-color: var(--accent); }
@media (pointer: coarse) { .touch-btns { display: flex; } .crosshair { opacity: .5; } }

/* ── screens / menu (NNPlays 3D menu standard) ── */
.screen { position: absolute; inset: 0; z-index: 20; display: none; place-items: center; padding: 16px max(16px, var(--safe-right)) max(16px, var(--safe-bottom)) max(16px, var(--safe-left)); overflow-y: auto; }
.screen-active { display: grid; }
#screen-menu { background: linear-gradient(90deg, rgba(0, 0, 0, .55), transparent 70%); place-items: center start; padding-left: max(5vw, 16px); }
.panel { width: min(470px, 100%); padding: 26px 24px 22px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(10px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 230, 180, .06); }
.panel.panel-sm { width: min(360px, 100%); text-align: center; }
.panel.readable { width: min(620px, 100%); }
.eyebrow { font-size: .66rem; letter-spacing: .32em; color: var(--moss); font-weight: 700; text-transform: uppercase; filter: brightness(1.5); }
h1 { font: 800 clamp(2.6rem, 9vw, 4.2rem)/.95 Cinzel, Georgia, serif; letter-spacing: .04em; margin: .35rem 0 .5rem; color: #e9e1cc; text-shadow: 0 4px 24px rgba(0, 0, 0, .8); }
h1 span { color: var(--accent); text-shadow: 0 0 26px rgba(255, 150, 50, .45); }
h2 { font: 800 1.6rem/1.1 Cinzel, Georgia, serif; margin: .3rem 0 .9rem; }
.subtitle { color: #cfc6b0; font-size: .98rem; line-height: 1.5; margin-bottom: 1rem; }
.stat-strip { display: flex; flex-wrap: wrap; gap: .45rem; margin-bottom: 1rem; }
.stat-strip span { font-size: .74rem; color: var(--muted); background: rgba(255, 255, 255, .04); border: 1px solid var(--line); border-radius: 999px; padding: .28rem .65rem; }
.stat-strip b { color: var(--text); }
.diff-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: .35rem; }
.diff-row button { min-height: 40px; padding: .55rem .3rem; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, .03); font: 700 .78rem/1 "DM Sans", sans-serif; letter-spacing: .04em; color: var(--muted); }
.diff-row button.on { color: #1a0f04; background: linear-gradient(135deg, #ffcf7a, var(--accent)); border-color: transparent; box-shadow: 0 0 18px rgba(255, 160, 60, .35); }
.diff-row button[data-diff="nightmare"].on { color: #fff; background: linear-gradient(135deg, #7a1020, #c62a2a); box-shadow: 0 0 18px rgba(200, 30, 30, .45); }
.diff-note { font-size: .76rem; color: var(--muted); margin-bottom: 1rem; min-height: 1.1em; }
.menu-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.menu-actions button { padding: .8rem .6rem; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, .045); font-weight: 700; font-size: .9rem; }
.menu-actions button:hover { background: rgba(255, 255, 255, .08); }
.menu-actions button.primary { grid-column: 1 / -1; padding: 1rem; font: 800 1.05rem/1 Cinzel, Georgia, serif; letter-spacing: .06em; color: #1c1004; border: 0;
  background: linear-gradient(135deg, #ffd58a, var(--accent) 55%, #d9741c); box-shadow: 0 0 30px rgba(255, 150, 50, .35), inset 0 1px 0 rgba(255, 255, 255, .4); }
.menu-actions button.primary:hover { filter: brightness(1.08); }
.menu-actions.compact { margin-top: 1rem; }
.tip { margin-top: .9rem; font-size: .72rem; color: var(--muted); text-align: center; letter-spacing: .06em; }
.tip .rating { display: inline-block; margin-right: .4rem; padding: .12rem .45rem; border: 1px solid rgba(200, 60, 60, .55); border-radius: 6px; color: #f1b3a8; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; font-size: .62rem; }
.menu-actions button[data-action="calm"][aria-pressed="true"] { border-color: rgba(125, 255, 207, .45); color: #bff5df; }
.muted { color: var(--muted); }
.how-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.how-grid div { background: rgba(255, 255, 255, .03); border: 1px solid var(--line); border-radius: 12px; padding: .7rem .8rem; }
.how-grid b { display: block; font-family: Cinzel, Georgia, serif; margin-bottom: .25rem; color: var(--accent); }
.how-grid span { font-size: .84rem; line-height: 1.45; color: #d6cdb6; }
kbd { font: 700 .72rem/1 "DM Sans", sans-serif; padding: .12rem .35rem; border-radius: 5px; border: 1px solid var(--line); background: rgba(255, 255, 255, .06); }
.leaderboard-list { display: grid; gap: 6px; max-height: 50vh; overflow: auto; }
.lb-row { display: grid; grid-template-columns: 2rem 1fr auto; align-items: center; gap: .5rem; padding: .5rem .7rem; border-radius: 10px; background: rgba(255, 255, 255, .035); border: 1px solid var(--line); }
.lb-row .rk { color: var(--accent); font-weight: 800; }
.over-panel { text-align: center; }
.over-panel .stat-strip { justify-content: center; }
.final-score { font: 800 clamp(2.4rem, 8vw, 3.4rem)/1 Cinzel, Georgia, serif; color: var(--accent); text-shadow: 0 0 26px rgba(255, 150, 50, .4); margin: .4rem 0 .2rem; }
.newbest { font-size: .8rem; letter-spacing: .14em; text-transform: uppercase; color: var(--accent2); margin-bottom: .9rem; }
body.won #screen-over .panel { background: linear-gradient(180deg, rgba(40, 60, 50, .8), rgba(14, 16, 14, .8)); }
body.won #screen-over h1 span { color: var(--accent2); text-shadow: 0 0 26px rgba(61, 255, 196, .45); }

@media (max-width: 560px) {
  #screen-menu { place-items: end center; padding-left: 16px; background: linear-gradient(0deg, rgba(0, 0, 0, .7), transparent 75%); }
  .panel { padding: 20px 16px 16px; }
  .how-grid { grid-template-columns: 1fr; }
  .game-bar-title { font-size: .78rem; letter-spacing: .12em; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .panel { padding: 14px 16px; }
  h1 { font-size: 2.2rem; margin: .1rem 0 .3rem; }
  .subtitle { margin-bottom: .5rem; font-size: .85rem; }
  .tip, .diff-note { display: none; }
  .menu-actions button { padding: .55rem; }
  .menu-actions button.primary { padding: .7rem; }
}
