:root {
  color-scheme: dark;
  --ink: #f1eee4;
  --muted: #aeb9b7;
  --faint: #778783;
  --cyan: #8fe5dc;
  --amber: #ffc277;
  --danger: #ff806c;
  --panel: rgba(9, 18, 25, .96);
  --line: rgba(185, 214, 211, .2);
  --hud-side-gap: 12px;
  --hud-phone-top: max(42px, calc(env(safe-area-inset-top, 0px) + 34px));
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #071119;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #071119;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body { position: fixed; inset: 0; }

#game-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(ellipse at 50% 53%, rgba(69, 102, 100, .2), transparent 52%),
    radial-gradient(ellipse at 50% 100%, rgba(193, 145, 91, .08), transparent 40%),
    linear-gradient(155deg, #0b1821, #071119 72%);
}

#scene {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.brand-mark, .desktop-hint, .corner-note {
  position: absolute;
  z-index: 2;
  color: rgba(207, 221, 218, .57);
  font: 500 10px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .12em;
  pointer-events: none;
}

.brand-mark {
  top: max(22px, env(safe-area-inset-top));
  left: max(24px, env(safe-area-inset-left));
  display: flex;
  gap: 10px;
  align-items: center;
}

.brand-mark b { color: var(--cyan); font-weight: 600; }
.brand-symbol { color: var(--cyan); font-size: 21px; line-height: .6; transform: rotate(-17deg); }

.desktop-hint {
  top: max(24px, env(safe-area-inset-top));
  right: max(24px, env(safe-area-inset-right));
  display: flex;
  gap: 5px;
  align-items: center;
  letter-spacing: .04em;
}

kbd {
  min-width: 18px;
  padding: 3px 4px 2px;
  border: 1px solid rgba(174, 208, 203, .2);
  border-radius: 4px;
  color: #d6e1de;
  background: rgba(179, 215, 211, .07);
  text-align: center;
  font: inherit;
  font-size: 9px;
}

.desktop-hint span { margin-left: 2px; color: rgba(207, 221, 218, .46); }
.desktop-hint i { width: 1px; height: 14px; margin: 0 7px; background: rgba(174, 208, 203, .18); }

.corner-note {
  right: max(24px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  color: rgba(207, 221, 218, .35);
}

.corner-note span { color: var(--amber); padding: 0 4px; }

.screen-card {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 50%;
  width: min(510px, calc(100vw - 36px));
  padding: clamp(25px, 5vw, 40px);
  transform: translate(-50%, -50%);
  border: 1px solid rgba(174, 221, 211, .28);
  border-radius: 20px;
  background:
    radial-gradient(ellipse at 0 0, rgba(127, 189, 177, .12), transparent 48%),
    linear-gradient(145deg, rgba(22, 39, 44, .98), rgba(8, 18, 26, .985) 68%),
    var(--panel);
  box-shadow: 0 28px 96px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(227, 250, 244, .1), 0 0 48px rgba(95, 162, 152, .06);
  backdrop-filter: blur(18px);
  touch-action: pan-y;
  overscroll-behavior: contain;
}

.screen-card::before, .screen-card::after {
  position: absolute;
  width: 16px;
  height: 16px;
  content: '';
  border-color: rgba(143, 229, 220, .6);
}

.screen-card::before { top: -1px; left: 18px; border-top: 2px solid; }
.screen-card::after { right: 18px; bottom: -1px; border-bottom: 2px solid; }

.eyebrow {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #8faaa9;
  font: 500 10px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .15em;
}

.eyebrow-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 12px rgba(143, 229, 220, .75);
}

h1, h2 {
  margin: 21px 0 0;
  color: #f0f1eb;
  font-size: clamp(34px, 8vw, 53px);
  font-weight: 800;
  letter-spacing: .045em;
  line-height: .98;
}

h2 { font-size: clamp(25px, 6vw, 38px); line-height: 1.08; }
.subtitle { margin: 10px 0 0; color: #b6cbc2; font-size: 12px; font-weight: 700; letter-spacing: .2em; }
.rule { height: 1px; margin: 22px 0 19px; background: linear-gradient(90deg, rgba(143, 229, 220, .72), rgba(255, 194, 119, .18) 54%, rgba(143, 229, 220, 0)); }
.pitch { margin: 0; color: #d3dbd7; font-size: clamp(14px, 3.5vw, 16px); line-height: 1.7; }
.objective-line { display: flex; align-items: center; gap: 8px; margin: 17px 0 0; color: #a9b8b6; font-size: 12px; line-height: 1.5; }
.objective-line b { color: #e2d9c5; font-weight: 700; }
.objective-icon { color: var(--amber); font-size: 18px; }

.mission-stats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  margin-top: 20px;
  padding: 11px 12px;
  border: 1px solid rgba(176, 215, 201, .12);
  border-radius: 8px;
  color: rgba(214, 226, 216, .63);
  background: linear-gradient(90deg, rgba(160, 207, 191, .065), rgba(255, 194, 119, .035));
  font: 600 8px/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .07em;
  white-space: nowrap;
}

.mission-stats b { color: #d3eadc; font-size: 11px; }
.mission-stats i { width: 1px; height: 14px; flex: 0 0 1px; background: rgba(178, 215, 203, .22); }

.primary-button {
  display: flex;
  width: 100%;
  min-height: 56px;
  margin-top: 20px;
  padding: 0 18px;
  align-items: center;
  justify-content: space-between;
  border: 1px solid rgba(143, 229, 220, .62);
  border-radius: 10px;
  color: #071417;
  background: linear-gradient(110deg, #9debe0, #73c9c0);
  box-shadow: 0 9px 24px rgba(74, 193, 179, .12), inset 0 1px 0 rgba(255,255,255,.5);
  cursor: pointer;
  font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .12em;
  transition: transform .16s ease, filter .16s ease, box-shadow .16s ease;
  touch-action: manipulation;
}

.primary-button:hover { transform: translateY(-1px); filter: brightness(1.07); box-shadow: 0 12px 30px rgba(74, 193, 179, .2); }
.primary-button:active { transform: translateY(1px) scale(.995); }
.primary-button:focus-visible { outline: 3px solid rgba(255, 194, 119, .85); outline-offset: 4px; }
.echo-button:focus-visible { outline: 3px solid rgba(143, 229, 220, .95); outline-offset: 4px; }
.primary-button span { font-size: 18px; font-weight: 500; }
.microcopy { margin: 14px 0 0; color: #75878b; font: 400 9px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .02em; text-align: center; }

.result-card { text-align: left; }
.result-card p:not(.microcopy) { margin: 15px 0 0; color: #c0cbc7; font-size: 14px; line-height: 1.6; }
.result-card[data-result="fail"] .eyebrow-dot { background: var(--danger); box-shadow: 0 0 12px rgba(255,128,108,.7); }
.result-card[data-result="fail"] h2 { color: #ffd0c7; }

.field-hud {
  position: absolute;
  z-index: 4;
  top: var(--hud-desktop-top, 48px);
  left: var(--hud-desktop-left, 54px);
  width: var(--hud-desktop-width, 692px);
  display: grid;
  gap: 5px;
  transform: scale(var(--hud-desktop-scale, 1));
  transform-origin: top left;
  color: #f4f1e7;
  pointer-events: none;
}

.field-hud__top, .field-hud__identity, .field-hud__threat, .field-hud__echo, .field-hud__goal {
  display: flex;
  align-items: center;
}

.field-hud__top { min-height: 27px; gap: 9px; }
.field-hud__identity { min-width: 0; flex: 1; gap: 9px; }
.field-hud__location {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  color: rgba(232, 238, 228, .86);
  font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .055em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.field-hud__phase, .field-hud__threat strong, .field-hud__echo strong, .field-hud__goal strong {
  display: block;
  overflow: hidden;
  font: 800 12px/1.15 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .045em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.field-hud__phase {
  flex: 0 0 auto;
  padding: 5px 7px;
  border: 1px solid rgba(255, 194, 119, .32);
  border-radius: 6px;
  color: #ffcf8b;
  background: rgba(255, 194, 119, .09);
}
.field-hud__phase[data-phase="return"] {
  border-color: rgba(143, 229, 220, .34);
  color: #a8f0e3;
  background: rgba(143, 229, 220, .09);
}
.field-hud__threat, .field-hud__echo {
  flex: 0 0 auto;
  min-height: 26px;
  gap: 7px;
  padding: 5px 8px;
  border: 1px solid rgba(220, 232, 222, .18);
  border-radius: 7px;
  background: rgba(5, 12, 17, .7);
}
.field-hud__threat { color: #c4d0cd; }
.field-hud__threat i {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: #b9c8c4;
}
.field-hud__threat[data-state="investigate"] { color: #a8f0e3; border-color: rgba(143, 229, 220, .3); }
.field-hud__threat[data-state="investigate"] i { border-radius: 2px; background: var(--cyan); transform: rotate(45deg); }
.field-hud__threat[data-state="investigate"] strong { color: #a8f0e3; }
.field-hud__threat[data-state="search"] { color: #ffd391; border-color: rgba(255, 194, 119, .3); }
.field-hud__threat[data-state="search"] i { border-radius: 1px; background: var(--amber); outline: 1px dashed currentColor; outline-offset: 2px; }
.field-hud__threat[data-state="search"] strong { color: #ffd391; }
.field-hud__threat[data-state="lost"] i { border-radius: 2px 50% 50%; transform: rotate(45deg); }
.field-hud__threat[data-state="alert"] { border-color: rgba(255, 128, 108, .52); }
.field-hud__threat[data-state="alert"] i { border-radius: 2px; background: var(--danger); }
.field-hud__threat[data-state="alert"] strong { color: #ffc0b3; }
.field-hud__echo { color: #adf0e5; border-color: rgba(143, 229, 220, .27); }
.field-hud__echo-mark { position: relative; display: grid; width: 19px; height: 19px; flex: 0 0 19px; place-items: center; color: var(--cyan); }
.field-hud__echo-mark svg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; transform: rotate(-90deg); }
.field-hud__echo-track, .field-hud__echo-fill { fill: none; stroke-width: 6; }
.field-hud__echo-track { stroke: rgba(201, 243, 232, .2); }
.field-hud__echo-fill { stroke: var(--cyan); stroke-linecap: round; stroke-dasharray: 276.46; stroke-dashoffset: 0; transition: stroke-dashoffset .08s linear; }
.field-hud__echo-mark b { position: relative; z-index: 1; color: var(--cyan); font: 700 11px/1 system-ui, sans-serif; }
.field-hud__echo[data-state="charging"] { color: #dce9e2; }
.field-hud__echo[data-state="charging"] > span { color: #9cc9c3; }
.field-hud__goal { min-height: 27px; gap: 8px; padding-top: 4px; border-top: 1px solid rgba(185, 214, 211, .18); }
.field-hud__gem { flex: 0 0 auto; color: var(--amber); font-size: 16px; text-shadow: 0 0 12px rgba(255, 194, 119, .42); }
.field-hud__goal strong { color: #ffd391; font-size: 12px; }
.field-hud__goal strong[data-phase="return"] { color: #adf0e5; }

.scene-hint {
  position: absolute;
  z-index: 3;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  left: max(24px, env(safe-area-inset-left));
  margin: 0;
  color: rgba(224, 235, 227, .82);
  font: 600 10px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .06em;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .9);
  pointer-events: none;
}

.touch-controls { display: none; }
.touch-controls.active { display: block; }

.move-zone {
  position: absolute;
  z-index: 3;
  left: max(17px, env(safe-area-inset-left));
  bottom: max(21px, env(safe-area-inset-bottom));
  width: clamp(116px, 31vw, 150px);
  height: clamp(116px, 31vw, 150px);
  display: grid;
  place-items: center;
  touch-action: none;
}

.move-ring {
  position: absolute;
  width: 76%;
  height: 76%;
  display: grid;
  place-items: center;
  border: 1px solid rgba(162, 218, 211, .34);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(101, 157, 153, .17), rgba(14, 30, 36, .45));
  box-shadow: inset 0 0 24px rgba(101, 157, 153, .09), 0 8px 28px rgba(0,0,0,.24);
}

.move-ring::before, .move-ring::after { position: absolute; content: ''; background: rgba(173, 219, 212, .18); }
.move-ring::before { width: 1px; height: 100%; }
.move-ring::after { width: 100%; height: 1px; }

.move-knob {
  position: absolute;
  z-index: 1;
  width: 38%;
  height: 38%;
  border: 1px solid rgba(195, 240, 231, .65);
  border-radius: 50%;
  background: radial-gradient(circle at 36% 32%, rgba(180, 241, 229, .82), rgba(84, 155, 151, .72) 70%);
  box-shadow: 0 0 24px rgba(110, 224, 209, .23), inset 0 1px 0 rgba(255,255,255,.4);
  transform: translate(0, 0);
  pointer-events: none;
}

.move-zone > span {
  position: absolute;
  bottom: 0;
  color: rgba(207, 221, 218, .55);
  font: 500 8px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .13em;
}

.echo-button {
  position: absolute;
  z-index: 3;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(31px, env(safe-area-inset-bottom));
  width: clamp(100px, 27vw, 128px);
  height: clamp(100px, 27vw, 128px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1px solid rgba(143, 229, 220, .68);
  border-radius: 50%;
  color: #effbf5;
  background: radial-gradient(circle at 50% 35%, rgba(45, 112, 108, .82), rgba(12, 34, 39, .95) 72%);
  box-shadow: 0 0 0 7px rgba(143, 229, 220, .055), 0 9px 30px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.14);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-appearance: none;
  appearance: none;
}

.echo-button:active { transform: scale(.96); }
.echo-button[disabled] { opacity: .86; filter: saturate(.7); }
.echo-button__ring { position: absolute; z-index: 0; inset: 2px; display: block; pointer-events: none; }
.echo-button__ring svg { display: block; width: 100%; height: 100%; transform: rotate(-90deg); }
.echo-button__ring-track, .echo-button__ring-fill { fill: none; stroke-width: 2.2; }
.echo-button__ring-track { stroke: rgba(201, 243, 232, .19); }
.echo-button__ring-fill { stroke: var(--cyan); stroke-linecap: round; stroke-dasharray: 276.46; stroke-dashoffset: 0; transition: stroke-dashoffset .08s linear; }
.echo-button > span:not(.echo-button__ring) { position: relative; z-index: 1; }
.echo-button .echo-icon { color: var(--cyan); font-size: 25px; line-height: 1; transform: rotate(-14deg); }
.echo-button__label { color: #e9fff7; font: 800 12px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .13em; }
.echo-button__state { color: #d3e9e1; font: 700 12px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .08em; }

.status-toast {
  position: absolute;
  z-index: 4;
  top: max(132px, calc(env(safe-area-inset-top) + 116px));
  left: 50%;
  max-width: min(90vw, 440px);
  padding: 9px 13px;
  border: 1px solid rgba(255, 194, 119, .32);
  border-radius: 6px;
  color: #f4d7af;
  background: rgba(24, 21, 19, .88);
  box-shadow: 0 6px 24px rgba(0,0,0,.24);
  opacity: 0;
  transform: translate(-50%, -7px);
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
  font: 700 11px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .04em;
  text-align: center;
}

.status-toast.visible { opacity: 1; transform: translate(-50%, 0); }
.field-hud .status-toast {
  position: static;
  top: auto;
  left: auto;
  width: 100%;
  max-width: none;
  max-height: 0;
  margin: 0;
  padding: 0 9px;
  overflow: hidden;
  border-width: 0;
  opacity: 0;
  transform: translateY(-3px);
  visibility: hidden;
  background: rgba(255, 194, 119, .08);
  text-align: left;
}
.field-hud .status-toast.visible {
  max-height: 44px;
  padding: 7px 9px;
  border-width: 1px;
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
}
.field-hud .status-toast[data-tone="echo"] { border-color: rgba(143, 229, 220, .4); color: #c9fff2; background: rgba(143, 229, 220, .09); }
.field-hud .status-toast[data-tone="threat"] { border-color: rgba(255, 128, 108, .46); color: #ffd0c7; background: rgba(255, 128, 108, .1); }
.field-hud .status-toast[data-tone="amber"] { border-color: rgba(255, 194, 119, .42); color: #ffe1b5; background: rgba(255, 194, 119, .09); }
[hidden] { display: none !important; }

@media (pointer: coarse), (max-width: 760px) {
  .touch-controls.active { display: block; }
  .desktop-hint { display: none; }
  .brand-mark { top: max(17px, env(safe-area-inset-top)); left: max(18px, env(safe-area-inset-left)); }
  .corner-note { display: none; }
  .field-hud:not([hidden]) {
    position: absolute;
    z-index: 4;
    top: var(--hud-phone-top);
    right: max(12px, env(safe-area-inset-right));
    left: max(12px, env(safe-area-inset-left));
    width: auto;
    display: grid;
    gap: 5px;
    padding: 8px 10px 7px;
    transform: none;
    border: 1px solid rgba(185, 218, 204, .2);
    border-radius: 13px;
    background: linear-gradient(145deg, rgba(19, 34, 50, .97), rgba(7, 16, 28, .97));
    box-shadow: 0 10px 26px rgba(0, 0, 0, .34), inset 0 1px 0 rgba(236, 246, 233, .07);
    pointer-events: none;
  }
  .field-hud__top { min-height: 28px; gap: 6px; }
  .field-hud__identity { gap: 6px; }
  .field-hud__location { font-size: 9px; }
  .field-hud__phase { padding: 5px 7px; font-size: 12px; }
  .field-hud__threat { min-height: 28px; gap: 6px; padding: 5px 7px; }
  .field-hud__threat strong { font-size: 12px; }
  .field-hud__echo { display: none; }
  .field-hud__goal { min-height: 30px; gap: 8px; padding-top: 4px; border-top-color: rgba(185, 214, 211, .16); }
  .field-hud__goal strong { font-size: 12px; }
  .field-hud .status-toast { padding-inline: 8px; }
  .field-hud .status-toast.visible { max-height: 42px; padding-block: 7px; }
  .scene-hint { display: none; }
  .screen-card { max-height: calc(100dvh - max(28px, env(safe-area-inset-top)) - max(20px, env(safe-area-inset-bottom))); overflow-y: auto; overscroll-behavior: contain; }
}

@media (max-width: 420px) {
  .screen-card { width: calc(100vw - 28px); padding: 23px 19px; border-radius: 17px; }
  h1 { font-size: clamp(37px, 11vw, 46px); }
  .pitch { font-size: 14px; line-height: 1.55; }
  .mission-stats { gap: 6px; padding: 10px 8px; font-size: 7px; letter-spacing: .035em; }
  .mission-stats b { font-size: 10px; }
  .field-hud__location { font-size: 8.5px; }
  .field-hud__threat { gap: 5px; padding-inline: 6px; }
  .field-hud__threat strong, .field-hud__phase { font-size: 12px; }
  .field-hud__goal strong { font-size: 13px; }
  .move-zone { left: max(13px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom)); width: clamp(108px, 31vw, 126px); height: clamp(108px, 31vw, 126px); }
  .echo-button { right: max(15px, env(safe-area-inset-right)); bottom: max(21px, env(safe-area-inset-bottom)); width: clamp(94px, 26vw, 110px); height: clamp(94px, 26vw, 110px); }
}

@media (max-height: 500px) and (orientation: landscape) {
  .move-zone { width: 104px; height: 104px; bottom: 12px; left: 12px; }
  .echo-button { width: 94px; height: 94px; bottom: 16px; right: 16px; }
  .corner-note { display: none; }
  .brand-mark { top: 12px; left: 16px; }
  :root { --hud-phone-top: max(42px, calc(env(safe-area-inset-top, 0px) + 34px)); }
  .field-hud:not([hidden]) { right: max(12px, env(safe-area-inset-right)); left: max(12px, env(safe-area-inset-left)); }
  .field-hud__top { gap: 5px; }
  .field-hud__location { font-size: 9px; }
  .field-hud__phase, .field-hud__threat strong { font-size: 12px; }
  .field-hud__goal strong { font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
