:root {
  --panel: rgba(16, 21, 27, 0.9);
  --paper: #eef2f4;
  --muted: #98a8b0;
  --yuzu: #ffcf3f;
  --onsen: #2fd6c3;
  --ember: #ff7a45;
  --display: 'Baloo 2', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; background: #aebfc6; }
body { font-family: var(--mono); color: var(--paper); -webkit-user-select: none; user-select: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { position: fixed; inset: 0; pointer-events: none; }
#overlay > * { pointer-events: auto; }

.editor {
  position: absolute; top: 14px; left: 14px; width: 268px; max-height: calc(100vh - 28px);
  display: flex; flex-direction: column; overflow: hidden;
  border-radius: 14px; background: var(--panel);
  border: 1px solid rgba(255,255,255,0.10);
  box-shadow: 0 18px 50px rgba(0,0,0,0.45); backdrop-filter: blur(7px);
}
.editor-head { padding: 14px 16px 10px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.editor-title { font-family: var(--display); font-weight: 800; font-size: 19px; color: var(--yuzu); letter-spacing: 1px; }
.editor-sub { font-size: 10px; color: var(--muted); margin-top: 2px; }
.editor-body { overflow-y: auto; padding: 6px; }

.sec { border-radius: 10px; margin: 6px 4px; background: rgba(255,255,255,0.025); border: 1px solid rgba(255,255,255,0.06); }
.sec-head { display: flex; justify-content: space-between; align-items: center; padding: 9px 11px; cursor: pointer; }
.sec-title-wrap { display: flex; align-items: center; gap: 8px; }
.sec-title { font-family: var(--display); font-weight: 700; font-size: 13px; color: var(--paper); text-transform: uppercase; letter-spacing: 0.5px; }
.sec-key { font-size: 10px; color: var(--onsen); border: 1px solid rgba(47,214,195,0.35); border-radius: 5px; padding: 1px 5px; }
.sec-body { padding: 4px 11px 11px; display: flex; flex-direction: column; gap: 7px; }

.ctrl { display: flex; align-items: center; gap: 8px; font-size: 11px; }
.ctrl-label { flex: 0 0 84px; color: var(--muted); }
.ctrl-range { flex: 1; accent-color: var(--yuzu); }
.ctrl-val { flex: 0 0 30px; text-align: right; color: var(--paper); }
.ctrl-num { width: 100%; background: rgba(0,0,0,0.3); color: var(--paper); border: 1px solid rgba(255,255,255,0.12); border-radius: 6px; padding: 4px 6px; font-family: var(--mono); font-size: 11px; }
.ctrl-color { width: 38px; height: 22px; padding: 0; border: 1px solid rgba(255,255,255,0.12); border-radius: 6px; background: none; }
.ctrl-toggle { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--paper); cursor: pointer; }
.ctrl-toggle input { accent-color: var(--onsen); }
.ctrl-btn { font-family: var(--mono); font-size: 11px; cursor: pointer; padding: 7px 10px; border-radius: 8px; color: var(--paper); background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12); transition: transform .1s, border-color .1s, background .1s; }
.ctrl-btn:hover { transform: translateY(-1px); border-color: var(--yuzu); background: rgba(255,207,63,0.08); }

.hintline { font-size: 10px; color: var(--muted); line-height: 1.5; }
.sel-name { font-family: var(--display); font-weight: 700; font-size: 13px; color: var(--ember); }
.sel-xyz { display: flex; gap: 6px; }
.sel-cell { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: 10px; color: var(--muted); }
.sel-cell input { background: rgba(0,0,0,0.3); color: var(--paper); border: 1px solid rgba(255,255,255,0.12); border-radius: 5px; padding: 3px 4px; font-family: var(--mono); font-size: 10px; width: 100%; }

.help-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(7,10,14,0.55); backdrop-filter: blur(3px); }
.help-card { width: min(360px, 90vw); padding: 22px 24px; border-radius: 16px; background: var(--panel); border: 1px solid rgba(255,207,63,0.2); display: flex; flex-direction: column; gap: 8px; }
.help-title { font-family: var(--display); font-weight: 800; font-size: 20px; color: var(--yuzu); margin-bottom: 4px; }
.help-row { display: flex; justify-content: space-between; font-size: 12px; }
.help-row .hk { color: var(--onsen); }
.help-row .hv { color: var(--muted); }

.stats { position: absolute; bottom: 14px; left: 14px; font-size: 11px; color: var(--paper); background: var(--panel); padding: 7px 12px; border-radius: 9px; border: 1px solid rgba(255,255,255,0.1); }

/* ---- game mode HUD + end card ---- */
.game-hud { position: fixed; left: 0; right: 0; top: 0; pointer-events: none; display: flex; flex-direction: column; align-items: center; gap: 7px; padding-top: 16px; z-index: 40; }
.gh-top { display: flex; align-items: baseline; gap: 10px; }
.gh-dist { font-family: var(--display, 'Baloo 2'), system-ui; font-weight: 800; font-size: 44px; color: #fff; text-shadow: 0 3px 14px rgba(0,0,0,.6), 0 1px 0 #c98a36; line-height: 1; }
.gh-dist i { font-style: normal; font-size: 20px; color: #ffce6b; margin-left: 3px; }
.gh-bar-wrap { width: min(340px, 60vw); height: 7px; border-radius: 99px; background: rgba(0,0,0,.45); border: 1px solid rgba(255,206,107,.25); overflow: hidden; }
.gh-bar { height: 100%; width: 0%; border-radius: 99px; background: linear-gradient(90deg, #8db84a, #ffce6b); transition: width .2s linear; }
.gh-bar.gold { background: linear-gradient(90deg, #ffce6b, #ffe9b0); box-shadow: 0 0 12px rgba(255,206,107,.8); }
.gh-bar.red { background: linear-gradient(90deg, #d2452f, #ff8a5c); }
.gh-bar-wrap.boost { height: 9px; border-color: rgba(255,206,107,.6); animation: boostPulse .5s ease-in-out infinite alternate; }
.gh-bar-wrap.red { border-color: rgba(220,80,60,.6); width: min(260px, 50vw); }
@keyframes boostPulse { from { box-shadow: 0 0 4px rgba(255,206,107,.4); } to { box-shadow: 0 0 16px rgba(255,206,107,.9); } }
.gh-melon { font-family: 'JetBrains Mono', monospace; font-size: 15px; color: #e8e2d2; background: rgba(10,14,8,.55); border: 1px solid rgba(255,206,107,.2); border-radius: 99px; padding: 4px 14px 4px 8px; display: flex; align-items: center; gap: 7px; }
.gh-melon b { color: #fff; }
.melon-dot { width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #b8e36a, #4f8f33 60%, #2f5c20); box-shadow: inset 0 -2px 3px rgba(0,0,0,.3); }
.gh-threat { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 4px; }
.gh-threat-label { font-family: var(--display, 'Baloo 2'), system-ui; font-weight: 800; font-size: 15px; letter-spacing: 2px; color: #ff8a5c; text-shadow: 0 2px 10px rgba(160,30,10,.8); animation: threatBlink .7s steps(2) infinite; }
@keyframes threatBlink { 50% { opacity: .45; } }
.threat-vignette { position: fixed; inset: 0; pointer-events: none; z-index: 35; box-shadow: inset 0 0 140px 50px rgba(170, 30, 10, .45); transition: opacity .4s ease; animation: vignettePulse 1s ease-in-out infinite alternate; }
@keyframes vignettePulse { from { box-shadow: inset 0 0 120px 40px rgba(170,30,10,.38); } to { box-shadow: inset 0 0 170px 64px rgba(170,30,10,.55); } }
.gh-hint { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: rgba(255,255,255,.55); }
.game-end { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at center, rgba(6,9,5,.45), rgba(4,6,3,.78)); backdrop-filter: blur(4px); animation: fadeIn .5s ease both; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes cardUp { from { opacity: 0; transform: translateY(26px) scale(.97); } }
.ge-card { background: linear-gradient(165deg, rgba(18,26,12,.97), rgba(9,13,7,.98)); border: 1px solid rgba(255,206,107,.32); border-radius: 22px; padding: 38px 52px 30px; text-align: center; box-shadow: 0 30px 90px rgba(0,0,0,.7), inset 0 1px 0 rgba(255,206,107,.16); min-width: min(380px, 86vw); max-width: min(460px, 92vw); animation: cardUp .55s cubic-bezier(.2,.9,.3,1.2) both .15s; }
.ge-dist { font-family: var(--display, 'Baloo 2'), system-ui; font-weight: 800; font-size: 58px; color: #fff; line-height: 1; margin-top: 10px; text-shadow: 0 4px 18px rgba(0,0,0,.6); }
.ge-dist i { font-style: normal; font-size: 26px; color: #ffce6b; margin-left: 4px; }
.ge-title { font-family: var(--display, 'Baloo 2'), system-ui, sans-serif; font-weight: 800; font-size: 44px; letter-spacing: 2px; line-height: 1; }
.ge-title.win { color: #ffce6b; text-shadow: 0 0 26px rgba(255,206,107,.5), 0 3px 0 #8a5a16; }
.ge-title.lose { color: #ff6a4a; text-shadow: 0 0 26px rgba(220,60,30,.5), 0 3px 0 #6e1d0c; }
.ge-sub { font-family: 'JetBrains Mono', monospace; font-size: 12px; letter-spacing: 2px; text-transform: uppercase; color: rgba(255,212,121,.75); margin-top: 8px; }
.ge-btns { display: flex; gap: 12px; margin-top: 26px; justify-content: center; }
.ge-btn { font-family: var(--display, 'Baloo 2'), system-ui, sans-serif; font-weight: 800; font-size: 14px; letter-spacing: 1.5px; color: #2a1d08; background: linear-gradient(180deg, #ffd98c, #ffc14f); border: 0; border-radius: 99px; padding: 13px 26px; cursor: pointer; box-shadow: 0 8px 22px rgba(255,193,79,.25), inset 0 1px 0 rgba(255,255,255,.5); transition: transform .1s ease, box-shadow .15s ease, filter .12s ease; }
.ge-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(255,193,79,.4), inset 0 1px 0 rgba(255,255,255,.5); }
.ge-btn:active { transform: translateY(0); }
.ge-btn.ghost { background: transparent; color: #ffe9c4; border: 1.5px solid rgba(255,206,107,.4); box-shadow: none; }
.ge-btn.ghost:hover { border-color: #ffce6b; background: rgba(255,206,107,.1); box-shadow: none; }

/* ---- game shell: loading, menu, intro, redesigned HUD ---- */
.shell { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.loading { background: radial-gradient(120% 120% at 50% 30%, #18230f 0%, #0b1107 55%, #050803 100%); opacity: 1; transition: opacity .45s ease; }
.loading.out { opacity: 0; pointer-events: none; }
.load-title { font-family: var(--display, 'Baloo 2'), system-ui; font-weight: 800; font-size: 30px; letter-spacing: 4px; color: #ffce6b; opacity: .92; }
.load-bar { margin-top: 18px; width: 220px; height: 6px; border-radius: 6px; background: rgba(255,255,255,.12); overflow: hidden; }
.load-fill { height: 100%; width: 30%; border-radius: 6px; background: linear-gradient(90deg, #ffce6b, #ff9f5b); animation: loadpulse 1.1s ease-in-out infinite; }
@keyframes loadpulse { 0%{transform:translateX(-100%)} 100%{transform:translateX(330%)} }
.load-sub { margin-top: 14px; font-family: 'JetBrains Mono', monospace; font-size: 11px; color: rgba(255,255,255,.55); }

.menu { background: linear-gradient(180deg, rgba(8,7,14,.30) 0%, rgba(8,7,14,.05) 45%, rgba(8,7,14,.55) 100%); }
.menu-title { font-family: var(--display, 'Baloo 2'), system-ui; font-weight: 800; font-size: clamp(54px, 11vw, 132px); letter-spacing: 4px; color: #fff; text-shadow: 0 6px 30px rgba(0,0,0,.55), 0 2px 0 #c98a36; line-height: .92; }
.menu-title span { color: #ffce6b; }
.menu-sub { font-family: 'JetBrains Mono', monospace; font-size: 13px; letter-spacing: 2px; color: rgba(255,255,255,.7); margin-top: 6px; text-transform: uppercase; }
.menu-btns { display: flex; flex-direction: column; gap: 12px; margin-top: 40px; width: 280px; }
.menu-btn { font-family: var(--display, 'Baloo 2'), system-ui; font-weight: 800; font-size: 17px; letter-spacing: 2.5px; color: #2a1d08; background: linear-gradient(180deg, #ffd98c, #ffc14f); border: 0; border-radius: 99px; padding: 16px 22px; cursor: pointer; transition: transform .1s ease, box-shadow .18s ease; box-shadow: 0 12px 32px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.5); }
.menu-btn:hover { transform: translateY(-3px) scale(1.02); box-shadow: 0 16px 40px rgba(255,193,79,.35), inset 0 1px 0 rgba(255,255,255,.5); }
.menu-btn:active { transform: translateY(-1px) scale(1); }
.menu-btn.ghost { background: rgba(10,14,8,.55); color: #ffe9c4; border: 1.5px solid rgba(255,206,107,.35); box-shadow: 0 8px 24px rgba(0,0,0,.3); backdrop-filter: blur(4px); }
.menu-btn.ghost:hover { border-color: #ffce6b; background: rgba(255,206,107,.12); }
.menu-btn.ghost { background: rgba(255,255,255,.08); color: #fff; border: 1px solid rgba(255,255,255,.22); box-shadow: none; backdrop-filter: blur(6px); }
.menu-btn.soon { opacity: .5; cursor: default; }
.menu-btn.soon:hover { filter: none; transform: none; }
.menu-foot { position: absolute; bottom: 16px; font-family: 'JetBrains Mono', monospace; font-size: 11px; color: rgba(255,255,255,.45); }

.intro-skip { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 55; font-family: 'JetBrains Mono', monospace; font-size: 12px; color: rgba(255,255,255,.8); background: rgba(15,13,26,.4); padding: 6px 14px; border-radius: 20px; backdrop-filter: blur(4px); pointer-events: none; }

/* redesigned HUD */
.gh-top { display: flex; align-items: baseline; gap: 10px; }
.gh-dist { font-family: 'Baloo 2', system-ui, sans-serif; font-weight: 800; font-size: 42px; color: #fff; text-shadow: 0 2px 12px rgba(0,0,0,.6); }
.gh-unit { font-family: 'JetBrains Mono', monospace; font-size: 14px; color: rgba(255,255,255,.7); }
.gh-melon { font-family: 'Baloo 2', system-ui, sans-serif; font-weight: 700; font-size: 18px; color: #ff7b8a; background: rgba(15,13,26,.4); padding: 5px 14px; border-radius: 20px; backdrop-filter: blur(4px); }
.gh-melon b { color: #fff; }

/* credits */
.credits-panel { display: flex; flex-direction: column; align-items: center; gap: 16px; background: linear-gradient(165deg, rgba(16,24,11,.92), rgba(8,12,7,.94)); border: 1px solid rgba(255, 206, 107, .32); border-radius: 20px; padding: 28px 36px; max-width: min(520px, 88vw); box-shadow: 0 26px 80px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,206,107,.14); backdrop-filter: blur(8px); animation: cardUp .45s cubic-bezier(.2,.9,.3,1.15) both; }
.credits-title { position: relative; padding-bottom: 12px; }
.credits-title::after { content: ''; position: absolute; left: 50%; transform: translateX(-50%); bottom: 0; width: 56px; height: 3px; border-radius: 3px; background: linear-gradient(90deg, transparent, #ffce6b, transparent); }
.credits-title { font-family: var(--display, 'Baloo 2'), system-ui; font-weight: 800; font-size: 30px; color: #ffce6b; letter-spacing: 2px; }
.credits-body { display: flex; flex-direction: column; gap: 6px; max-height: 44vh; overflow: auto; }
.credits-line { color: #e8e2d2; font-size: 14px; }
.credits-line b { color: #fff; margin-right: 8px; }
.credits-line i { opacity: .55; font-size: 12px; }
.credits-line.dim { opacity: .6; margin-top: 8px; font-size: 12px; }

/* settings */
.settings-body { display: flex; flex-direction: column; gap: 12px; min-width: min(380px, 76vw); }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.settings-label { color: #e8e2d2; font-size: 14px; }
.settings-row input[type=range] { flex: 1; max-width: 200px; accent-color: #ffce6b; }
.settings-row input[type=checkbox] { accent-color: #ffce6b; width: 18px; height: 18px; }

/* map select */
.map-list { display: flex; flex-direction: column; gap: 8px; min-width: min(420px, 80vw); }
.map-btn { display: flex; flex-direction: column; gap: 2px; text-align: left; background: rgba(255,255,255,.05); border: 1px solid rgba(255,206,107,.18); border-radius: 10px; padding: 10px 14px; color: #e8e2d2; cursor: pointer; font-family: inherit; }
.map-btn:hover { background: rgba(255,206,107,.1); }
.map-btn.sel { border-color: #ffce6b; background: rgba(255,206,107,.16); }
.map-btn b { color: #fff; font-size: 15px; }
.map-btn span { font-size: 12px; opacity: .75; }
.map-btn i { font-size: 11px; opacity: .5; font-style: normal; }
.diff-row { display: flex; gap: 10px; justify-content: center; }
.diff-btn { background: rgba(255,255,255,.06); border: 1px solid rgba(255,206,107,.2); border-radius: 8px; color: #e8e2d2; padding: 8px 16px; cursor: pointer; font-family: inherit; letter-spacing: 1px; }
.diff-btn.sel { border-color: #ffce6b; color: #ffce6b; background: rgba(255,206,107,.14); }

/* menu readability + title glow */
.menu-title { animation: titleBreathe 4s ease-in-out infinite alternate; }
@keyframes titleBreathe { from { text-shadow: 0 6px 30px rgba(0,0,0,.55), 0 2px 0 #c98a36; } to { text-shadow: 0 6px 44px rgba(255,206,107,.4), 0 2px 0 #c98a36; } }
.menu-sub { color: rgba(255,255,255,.78); font-style: italic; letter-spacing: 1px; }
.menu-foot { background: rgba(8,12,7,.5); border-radius: 99px; padding: 5px 16px; }
.intro-skip { font-family: 'JetBrains Mono', monospace; background: rgba(8,12,7,.6); border: 1px solid rgba(255,206,107,.2); border-radius: 99px; padding: 7px 18px; }
.load-title { animation: titleBreathe 2.2s ease-in-out infinite alternate; }

/* multiplayer */
.mp-form { display: flex; gap: 10px; }
.mp-input { background: rgba(255,255,255,.07); border: 1px solid rgba(255,206,107,.25); border-radius: 9px; color: #fff; padding: 10px 12px; font-family: 'JetBrains Mono', monospace; font-size: 14px; width: 160px; }
.mp-input.code { width: 90px; text-transform: uppercase; letter-spacing: 3px; text-align: center; }
.mp-input:focus { outline: none; border-color: #ffce6b; }
.mp-status { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: rgba(255,255,255,.65); }
.mp-lobby { display: flex; flex-direction: column; gap: 5px; min-width: 220px; }
.mp-player { background: rgba(255,255,255,.06); border-radius: 8px; padding: 6px 12px; color: #e8e2d2; font-size: 14px; }
.mp-player.you { border: 1px solid rgba(255,206,107,.45); color: #ffce6b; }
.ge-results { margin-top: 12px; display: flex; flex-direction: column; gap: 3px; font-family: 'JetBrains Mono', monospace; font-size: 13px; color: #e8e2d2; }
.ge-results .you { color: #ffce6b; }

/* live standings + placements */
.mp-standings { position: fixed; top: 80px; right: 18px; z-index: 41; display: flex; flex-direction: column; gap: 4px; background: rgba(8,12,7,.55); border: 1px solid rgba(255,206,107,.2); border-radius: 12px; padding: 10px 12px; backdrop-filter: blur(4px); pointer-events: none; }
.mp-stand-row { display: flex; align-items: center; gap: 8px; font-family: 'JetBrains Mono', monospace; font-size: 12px; color: #e8e2d2; }
.mp-stand-row b { color: #ffce6b; width: 14px; }
.mp-stand-row span { margin-left: auto; opacity: .7; }
.mp-stand-row.you { color: #ffce6b; }
.ge-place { display: flex; align-items: center; gap: 10px; font-family: 'JetBrains Mono', monospace; font-size: 13px; color: #e8e2d2; padding: 4px 0; }
.ge-place b { width: 18px; color: rgba(255,255,255,.55); }
.ge-place.p1 b { color: #ffce6b; } .ge-place.p2 b { color: #cfd6dd; } .ge-place.p3 b { color: #d0945f; }
.ge-place i { margin-left: auto; font-style: normal; opacity: .65; font-size: 12px; }
.ge-place.you span { color: #ffce6b; }

/* multiplayer stepped flow */
.mp-view { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.mp-input.wide { width: 240px; text-align: center; }
.mp-hint { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: rgba(255,255,255,.6); text-align: center; max-width: 320px; line-height: 1.5; }
.mp-code-big { font-family: var(--display, 'Baloo 2'), system-ui; font-weight: 800; font-size: 52px; letter-spacing: 14px; padding: 8px 18px 8px 32px; color: #ffce6b; background: rgba(255,206,107,.08); border: 1.5px dashed rgba(255,206,107,.45); border-radius: 14px; cursor: pointer; transition: background .15s ease; }
.mp-code-big:hover { background: rgba(255,206,107,.16); }
.mp-count { font-family: 'JetBrains Mono', monospace; font-size: 13px; color: #cdebb0; }
.menu-btn:disabled { opacity: .4; cursor: not-allowed; transform: none !important; box-shadow: 0 8px 24px rgba(0,0,0,.3) !important; }
