:root {
  --ink: #d9dcd6;
  --ink-dim: #9aa0a0;
  --paper: #d8d2c2;
  --paper-ink: #2a2620;
  --red: #b8392d;
  --warm: #d9a35b;
  --font: "Courier New", "Nanum Gothic Coding", "D2Coding", "Noto Serif KR", "Nanum Myeongjo", "Batang", "AppleMyungjo", serif;
  --serif: "Noto Serif KR", "Nanum Myeongjo", "Batang", "AppleMyungjo", Georgia, serif;
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: #1c2026; color: var(--ink); font-family: var(--font);
  touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
#game { position: fixed; inset: 0; overflow: hidden; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#aimlayer { position: absolute; inset: 0; touch-action: none; }
.hidden { display: none !important; }

/* ---------- scope / overlays ---------- */
#scope { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#cover-shade {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 40%, rgba(10,12,14,.55), rgba(5,6,8,.85));
  display: flex; align-items: center; justify-content: center;
}
#cover-shade span { font-size: 15px; letter-spacing: .4em; color: var(--ink-dim); margin-top: 18vh; }
#damage {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, rgba(120,0,0,0) 45%, rgba(140,10,10,.85) 100%);
}
#fade { position: absolute; inset: 0; pointer-events: none; background: #050607; opacity: 0; transition: opacity 1.2s; }
#crosshair {
  position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px 0 0 -2px;
  border-radius: 50%; background: rgba(230,230,220,.55); pointer-events: none;
  box-shadow: 0 0 2px rgba(0,0,0,.8);
}

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; text-shadow: 0 1px 2px rgba(0,0,0,.85); font-size: 14px; }
#hud-obj { position: absolute; left: calc(16px + var(--sl)); top: calc(14px + var(--st)); max-width: 46vw; }
#obj-text { font-size: 15px; letter-spacing: .03em; }
#obj-sub { color: var(--ink-dim); font-size: 13px; margin-top: 3px; }
#obj-timer { margin-top: 6px; font-size: 22px; color: var(--warm); letter-spacing: .08em; }
#obj-timer.urgent { color: #ff6a55; }
#hud-wind { position: absolute; right: calc(16px + var(--sr)); top: calc(12px + var(--st)); display: flex; align-items: center; gap: 6px; text-align: left; line-height: 1.1; }
#hud-wind small { color: var(--ink-dim); }
#hud-wind svg { color: var(--ink); filter: drop-shadow(0 1px 1px #000); }
#hud-zoom { position: absolute; right: calc(18px + var(--sr)); top: calc(64px + var(--st)); font-size: 16px; color: var(--ink-dim); }
#hud-status { position: absolute; left: calc(16px + var(--sl)); bottom: calc(16px + var(--sb)); }
#hud-ammo { display: flex; align-items: flex-end; gap: 8px; }
#ammo-icons { display: flex; gap: 3px; flex-wrap: wrap; max-width: 220px; }
#ammo-icons i { display: block; width: 5px; height: 18px; border-radius: 2.5px 2.5px 1px 1px; background: linear-gradient(#c9a560 0 35%, #8d6b33 35%); box-shadow: 0 1px 2px #000; }
#ammo-icons i.spent { background: rgba(255,255,255,.12); box-shadow: none; }
#ammo-num { font-size: 20px; }
#hud-hp { margin-top: 8px; display: flex; gap: 6px; }
#hud-hp .pip { width: 14px; height: 14px; border: 1.5px solid var(--ink); transform: rotate(45deg); box-shadow: 0 1px 2px #000; }
#hud-hp .pip.on { background: #a33a2c; }
#hud-decoy { margin-top: 6px; color: var(--ink-dim); }
#hud-bars { position: absolute; left: 50%; bottom: calc(18px + var(--sb)); transform: translateX(-50%); width: min(300px, 34vw); }
.bar-row { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.bar-row label { width: 44px; text-align: right; font-size: 12px; color: var(--ink-dim); }
.bar { flex: 1; height: 6px; background: rgba(0,0,0,.45); border: 1px solid rgba(220,220,210,.35); }
.bar i { display: block; height: 100%; width: 0%; background: #c9c3b0; }
#bar-exp i { background: linear-gradient(90deg, #8f8a76, #d0a050); }
#bar-exp.spotted i { background: #c8372a; }
#bar-breath i { background: #9fb6c8; }
#bar-breath.tired i { background: #a35a4a; }
#spotted { color: #ff5a45; font-size: 13px; letter-spacing: .1em; animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { opacity: .3; } }
#hud-hit { position: absolute; left: 50%; top: 58%; transform: translateX(-50%); font-size: 18px; letter-spacing: .25em; opacity: 0; transition: opacity .5s; color: #eee; }
#hud-hit.show { opacity: 1; transition: none; }
#hud-hit.head { color: var(--warm); }
#hud-msg { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); font-family: var(--serif); font-size: 22px; text-align: center; opacity: 0; transition: opacity .8s; width: 90vw; letter-spacing: .05em; }
#hud-msg.show { opacity: 1; transition: opacity .25s; }
#hud-hint { position: absolute; left: 50%; top: 33%; transform: translateX(-50%); font-size: 15px; color: var(--warm); background: rgba(0,0,0,.35); padding: 6px 14px; border-radius: 3px; }
#hud-keys { position: absolute; right: calc(14px + var(--sr)); bottom: calc(12px + var(--sb)); font-size: 11px; color: rgba(210,214,208,.5); max-width: min(330px, 28vw); text-align: right; line-height: 1.5; }
#debug { position: absolute; left: 50%; top: calc(6px + var(--st)); transform: translateX(-50%); font-size: 12px; color: #9f9; background: rgba(0,0,0,.5); padding: 2px 8px; white-space: pre; }

/* ---------- touch ---------- */
#touch { position: absolute; inset: 0; pointer-events: none; }
.tbtn {
  position: absolute; pointer-events: auto; touch-action: none;
  border-radius: 50%; border: 2px solid rgba(225,225,215,.55); background: rgba(20,24,28,.35);
  color: var(--ink); font-family: var(--font); font-size: 15px; padding: 0;
  display: flex; align-items: center; justify-content: center; text-shadow: 0 1px 2px #000;
  -webkit-user-select: none; user-select: none; outline: none;
}
.tbtn.active, .tbtn.on { background: rgba(200,190,160,.35); border-color: #e8e2cc; }
.tbtn.disabled { opacity: .35; }
#t-fire { width: 112px; height: 112px; right: calc(26px + var(--sr)); bottom: calc(26px + var(--sb)); font-size: 18px; border-width: 3px; background: rgba(120,30,25,.35); }
#t-scope { width: 80px; height: 80px; right: calc(150px + var(--sr)); bottom: calc(36px + var(--sb)); }
#t-zoom { width: 64px; height: 64px; right: calc(46px + var(--sr)); bottom: calc(150px + var(--sb)); }
#t-breath { width: 92px; height: 92px; left: calc(26px + var(--sl)); bottom: calc(26px + var(--sb)); }
#t-cover { width: 76px; height: 76px; left: calc(132px + var(--sl)); bottom: calc(40px + var(--sb)); }
#t-decoy { width: 66px; height: 66px; left: calc(40px + var(--sl)); bottom: calc(136px + var(--sb)); }
#t-pause { width: 48px; height: 48px; left: calc(50% - 56px); top: calc(8px + var(--st)); border-radius: 8px; font-size: 18px; }
#t-full { width: 48px; height: 48px; left: calc(50% + 8px); top: calc(8px + var(--st)); border-radius: 8px; font-size: 20px; }

/* touch layout: move status cluster to the top so thumbs don't cover it */
body.touch #hud-status { left: auto; right: calc(16px + var(--sr)); bottom: auto; top: calc(64px + var(--st)); text-align: right; }
body.touch #hud-ammo { justify-content: flex-end; }
body.touch #hud-hp { justify-content: flex-end; }
body.touch #hud-zoom { top: auto; right: calc(150px + var(--sr)); bottom: calc(126px + var(--sb)); }
body.touch #hud-bars { bottom: auto; top: calc(62px + var(--st)); }
body.touch .desk-only { display: none !important; }
body.touch #debug { top: auto; bottom: calc(6px + var(--sb)); }
body:not(.touch) .touch-only { display: none !important; }
body:not(.m3) .m3-only { display: none; }

/* ---------- screens ---------- */
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(rgba(18,22,27,.55), rgba(10,12,15,.8));
  padding: calc(12px + var(--st)) calc(12px + var(--sr)) calc(12px + var(--sb)) calc(12px + var(--sl));
  overflow-y: auto; touch-action: pan-y;
}
.screen.dim { background: rgba(8,10,12,.72); }
#screen-loading { background: #1c2026; }
.title-block { text-align: center; }
.title-block h1 { font-family: var(--serif); font-size: clamp(64px, 14vw, 132px); margin: 0; letter-spacing: .32em; text-indent: .32em; font-weight: 700; color: #e4e2da; text-shadow: 0 4px 30px rgba(0,0,0,.7); }
.title-block .sub { font-family: var(--serif); font-size: clamp(16px, 2.6vw, 22px); letter-spacing: .5em; text-indent: .5em; color: var(--ink-dim); margin: 6px 0 0; }
#load-bar { width: min(320px, 70vw); height: 3px; background: rgba(255,255,255,.12); margin-top: 40px; }
#load-bar i { display: block; height: 100%; width: 0; background: var(--ink); transition: width .2s; }
#load-text { color: var(--ink-dim); font-size: 13px; }
.menu { display: flex; flex-direction: column; gap: 10px; margin-top: 34px; align-items: stretch; min-width: 220px; }
.btn {
  font-family: var(--font); font-size: 16px; color: var(--ink); background: rgba(20,24,28,.6);
  border: 1px solid rgba(220,220,210,.45); padding: 11px 24px; min-height: 46px; cursor: pointer; letter-spacing: .08em;
}
.btn:hover { background: rgba(70,72,70,.6); }
.btn.primary { border-color: #e2dccb; background: rgba(110,95,70,.45); }
.btn.small { font-size: 13px; padding: 6px 14px; min-height: 36px; }
.btn:disabled { opacity: .35; cursor: default; }
.foot { color: var(--ink-dim); font-size: 13px; margin-top: 26px; text-align: center; }
.panel { background: rgba(16,19,23,.88); border: 1px solid rgba(220,220,210,.25); padding: 22px 26px; max-width: 640px; width: 100%; max-height: 100%; overflow-y: auto; }
.panel.wide { max-width: 780px; }
.panel h2 { font-family: var(--serif); margin: 0 0 12px; font-weight: 700; letter-spacing: .1em; }
.panel h3 { font-family: var(--serif); margin: 18px 0 6px; font-size: 16px; }
.panel p { line-height: 1.6; margin: 6px 0; font-size: 14px; }
.panel .btn { margin-top: 14px; }
.panel .row { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.panel.paper { background: #d6cfbd; color: var(--paper-ink); border: none; box-shadow: 0 10px 50px rgba(0,0,0,.6); }
.panel.paper .btn { color: var(--paper-ink); background: rgba(255,255,255,.25); border-color: rgba(40,35,28,.5); }
.panel.paper .btn.primary { background: #3a342b; color: #e8e2d2; }
#brief-time { color: #6b6253; margin-top: -6px; }
#brief-text { font-family: var(--font); white-space: pre-wrap; font-size: 15px; line-height: 1.7; min-height: 12em; margin: 10px 0; }
#brief-text .cursor { animation: blink .7s steps(2) infinite; }
#mission-list { display: flex; flex-direction: column; gap: 10px; }
.mission { display: flex; align-items: center; gap: 14px; border: 1px solid rgba(220,220,210,.3); padding: 12px 14px; cursor: pointer; background: rgba(30,34,38,.6); }
.mission:hover { background: rgba(60,62,60,.6); }
.mission.locked { opacity: .4; cursor: default; }
.mission .num { font-family: var(--serif); font-size: 30px; width: 40px; text-align: center; }
.mission .info { flex: 1; }
.mission .name { font-size: 17px; }
.mission .time { color: var(--ink-dim); font-size: 13px; }
.mission .rank { font-family: var(--serif); font-size: 26px; width: 44px; text-align: center; color: var(--warm); }
#res-title { font-size: 26px; }
#res-reason { font-family: var(--serif); }
#res-rank { font-family: var(--serif); font-size: 64px; text-align: center; line-height: 1; margin: 6px 0 4px; }
#res-table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 8px 0; }
#res-table td { padding: 4px 6px; border-bottom: 1px solid rgba(40,35,28,.2); }
#res-table td:last-child { text-align: right; }
#res-epilogue { font-family: var(--serif); font-style: italic; }
.sens { display: flex; align-items: center; gap: 10px; justify-content: center; font-size: 14px; color: var(--ink-dim); margin-top: 6px; }
.sens input { width: 150px; }

#rotate { display: none; position: absolute; inset: 0; background: #14171b; z-index: 50; align-items: center; justify-content: center; text-align: center; font-size: 20px; font-family: var(--serif); }
#rotate span { font-size: 54px; display: inline-block; margin-top: 16px; }
@media (orientation: portrait) {
  body.touch #rotate { display: flex; }
}
#error { position: absolute; left: 10px; right: 10px; bottom: 10px; background: rgba(90,10,10,.9); color: #fff; padding: 10px; font-size: 13px; z-index: 60; white-space: pre-wrap; }

@media (max-height: 460px) {
  .title-block h1 { font-size: 60px; }
  .menu { margin-top: 16px; gap: 6px; }
  .btn { min-height: 40px; padding: 8px 18px; }
  .panel { padding: 14px 18px; }
  #brief-text { font-size: 13px; min-height: 8em; }
  #res-rank { font-size: 44px; }
}
