:root {
  color-scheme: dark;
  --void: #020812;
  --glass: #06121de8;
  --glass-soft: #071521bd;
  --cyan: #58f3ff;
  --cyan-dim: #2197a7;
  --magenta: #ff5bc8;
  --amber: #ffc460;
  --ink: #eaffff;
  --muted: #8eb4bc;
  --line: #58f3ff3d;
  --danger: #ff718e;
  font-family: "Segoe UI Variable", "Bahnschrift", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--void); color: var(--ink); }
button, a { font: inherit; }
button { color: inherit; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  translate: 0 -180%;
  padding: 10px 14px;
  background: #fff;
  color: #000;
}
.skip-link:focus { translate: 0; }

.open-world-shell { position: relative; width: 100%; height: 100%; min-height: 480px; }
#world-canvas { display: block; width: 100%; height: 100%; outline: none; touch-action: none; }
#world-canvas:focus-visible { box-shadow: inset 0 0 0 3px var(--cyan); }

.scanlines {
  pointer-events: none;
  position: absolute;
  inset: 0;
  opacity: .16;
  background: repeating-linear-gradient(0deg, transparent 0 3px, #47ddff19 3px 4px);
  mix-blend-mode: screen;
}

.world-header {
  position: absolute;
  inset: max(14px, env(safe-area-inset-top)) 18px auto 18px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  pointer-events: none;
}
.world-header > div { display: flex; align-items: center; gap: 11px; letter-spacing: .14em; font-size: 13px; }
.world-header p { margin: 3px 0; max-width: 430px; color: var(--muted); text-align: right; font-size: 12px; }
.preview-flag {
  padding: 6px 9px;
  border: 1px solid var(--amber);
  color: #1a1200;
  background: var(--amber);
  font-weight: 950;
  letter-spacing: .08em;
  clip-path: polygon(0 0, 92% 0, 100% 50%, 92% 100%, 0 100%);
}

.zone-card, .echo-radar, .crown-readout, .interaction-card, .controls-card, .status-strip {
  position: absolute;
  border: 1px solid var(--line);
  background: linear-gradient(135deg, var(--glass), var(--glass-soft));
  box-shadow: 0 18px 50px #0008, inset 0 1px #ffffff0b;
  backdrop-filter: blur(12px);
}
.zone-card, .echo-radar, .crown-readout, .interaction-card { clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 0 100%); }

.zone-card { top: 78px; left: 18px; width: min(320px, calc(100vw - 36px)); padding: 15px 17px; }
.zone-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 54px;
  height: 2px;
  background: var(--magenta);
}
.zone-index, .panel-kicker, .dialog-kicker { color: var(--cyan); font-size: 10px; font-weight: 900; letter-spacing: .2em; }
.zone-card h1 { margin: 5px 0 2px; font: 700 24px/1.05 Georgia, serif; color: #fff2d4; }
.zone-card p { margin: 8px 0 0; color: var(--muted); font-size: 12px; }

.echo-radar { top: 78px; right: 18px; width: 275px; padding: 13px; }
.panel-title { display: flex; justify-content: space-between; align-items: center; color: var(--cyan); font-size: 11px; font-weight: 900; letter-spacing: .14em; }
.panel-title button, .controls-card button {
  border: 0;
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
}
.echo-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 9px;
  align-items: center;
  padding: 10px 2px;
  border-bottom: 1px solid #ffffff0d;
}
.echo-row:last-child { border-bottom: 0; }
.echo-signal { width: 8px; height: 8px; border-radius: 50%; background: var(--echo); box-shadow: 0 0 14px var(--echo); }
.echo-row b { display: block; font-size: 12px; }
.echo-row small { color: var(--muted); font-size: 10px; }
.echo-row output { font: 700 11px/1 "Cascadia Mono", monospace; color: var(--echo); }
.echo-row.is-captured { opacity: .65; }

.crown-readout { right: 18px; top: 282px; width: 275px; padding: 13px; }
.crown-readout strong { display: block; margin-top: 4px; color: #ffe4aa; font: 700 18px Georgia, serif; }
.crown-readout p { margin: 5px 0 9px; color: var(--muted); font-size: 10px; }
.crown-slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.crown-slots i { min-width:0;padding:6px;border:1px solid #ffffff16;color:#ffffff55;text-align:center;font-style:normal;white-space:nowrap;overflow:hidden;text-overflow:ellipsis }
.crown-slots i.is-live { color:#ffe4aa;border-color:#ffc46055;background:#ffc4600b }

.interaction-card { left: 18px; bottom: 88px; width: 310px; padding: 14px; }
.interaction-card > span { display: block; margin-bottom: 9px; color: #fff0c8; font: 700 20px Georgia, serif; }
.meter-row { display: grid; grid-template-columns: 72px 1fr; gap: 8px; align-items: center; margin: 5px 0; font-size: 10px; color: var(--muted); }
.pulse-readout { display: flex; justify-content: space-between; margin-top: 8px; color: var(--muted); font-size: 10px; }
.pulse-readout output { color: var(--cyan); font: 800 11px "Cascadia Mono", monospace; }
progress { width: 100%; height: 7px; appearance: none; border: 0; background: #ffffff0e; }
progress::-webkit-progress-bar { background: #ffffff0e; }
#stability-meter::-webkit-progress-value { background: var(--magenta); }
#link-meter::-webkit-progress-value { background: var(--cyan); }
#stability-meter::-moz-progress-bar { background: var(--magenta); }
#link-meter::-moz-progress-bar { background: var(--cyan); }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 11px; }
.action-grid button, dialog button, dialog a, .fallback-card a {
  min-height: 40px;
  border: 1px solid var(--line);
  background: #0b2634;
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
}
.action-grid button:last-child { border-color: #ff5bc867; background: #2b1029; }
kbd {
  padding: 2px 5px;
  border: 1px solid #ffffff28;
  border-bottom-width: 2px;
  background: #ffffff0a;
  color: #fff;
  font: 700 10px/1.2 "Cascadia Mono", monospace;
}

.controls-card {
  left: 50%;
  bottom: 18px;
  translate: -50% 0;
  display: flex;
  gap: 15px;
  align-items: center;
  padding: 9px 13px;
  font-size: 10px;
  white-space: nowrap;
}
.controls-card span { color: var(--muted); }
.status-strip {
  right: 18px;
  bottom: 18px;
  max-width: min(390px, 32vw);
  padding: 9px 13px;
  color: var(--muted);
  font-size: 11px;
}
.status-dot { display: inline-block; width: 6px; height: 6px; margin-right: 7px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 10px var(--cyan); }

.mobile-pad, .mobile-actions { display: none; position: absolute; z-index: 4; }

dialog {
  width: min(530px, calc(100% - 28px));
  padding: 0;
  border: 1px solid var(--line);
  background: #06111bf7;
  color: var(--ink);
  box-shadow: 0 28px 100px #000;
}
dialog::backdrop { background: #01040bd9; backdrop-filter: blur(6px); }
dialog form { padding: 28px; }
dialog h2 { margin: 7px 0 13px; color: #fff0ce; font: 700 30px Georgia, serif; }
dialog p, dialog li { color: var(--muted); line-height: 1.5; }
dialog li { margin: 7px 0; }
dialog button, dialog a { display: inline-flex; align-items: center; justify-content: center; padding: 10px 14px; }
.dialog-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 17px; }
.dialog-actions a { border-color: var(--amber); color: #ffe4aa; }
.resonance-pulses { display:grid;grid-template-columns:repeat(2,1fr);gap:8px;margin:18px 0 }
.resonance-pulses button { border-color:#58f3ff55;background:linear-gradient(135deg,#0a2835,#29102c);font-weight:900;letter-spacing:.12em }
.resonance-pulses button:disabled { cursor:wait;opacity:.45 }

.fallback-card {
  position: absolute;
  inset: 50% auto auto 50%;
  translate: -50% -50%;
  width: min(520px, calc(100% - 32px));
  padding: 30px;
  border: 1px solid var(--danger);
  background: #100811f2;
}
.fallback-card a { display: inline-flex; padding: 10px 14px; }

button:focus-visible, a:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }

@media (max-width: 880px), (pointer: coarse) {
  .world-header p, .crown-readout, .controls-card { display: none; }
  .zone-card { top: 70px; width: min(270px, calc(100vw - 36px)); }
  .zone-card h1 { font-size: 19px; }
  .echo-radar { top: auto; bottom: 154px; right: 10px; width: 210px; }
  .echo-row { padding: 7px 0; }
  .interaction-card { left: 10px; bottom: 154px; width: min(300px, calc(100vw - 240px)); }
  .status-strip { left: 10px; right: 10px; bottom: 104px; max-width: none; }
  .mobile-pad {
    display: grid;
    left: max(12px, env(safe-area-inset-left));
    bottom: max(14px, env(safe-area-inset-bottom));
    grid-template: repeat(2, 43px) / repeat(3, 43px);
    gap: 4px;
  }
  .mobile-pad button, .mobile-actions button {
    border: 1px solid var(--line);
    background: #061521dc;
    color: var(--cyan);
    touch-action: none;
  }
  .mobile-pad button[data-move="forward"] { grid-column: 2; }
  .mobile-pad button[data-move="left"] { grid-row: 2; grid-column: 1; }
  .mobile-pad button[data-move="backward"] { grid-row: 2; grid-column: 2; }
  .mobile-pad button[data-move="right"] { grid-row: 2; grid-column: 3; }
  .mobile-actions {
    display: flex;
    right: max(12px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
    gap: 6px;
  }
  .mobile-actions button { min-width: 62px; height: 45px; font-size: 10px; }
}

@media (max-width: 600px) {
  .world-header { inset-inline: 10px; }
  .world-header > div { gap: 6px; font-size: 10px; }
  .preview-flag { padding: 5px 7px; font-size: 9px; }
  .zone-card { left: 10px; top: 56px; }
  .echo-radar { top: 132px; bottom: auto; right: 10px; width: 170px; }
  .echo-row { grid-template-columns: 8px 1fr; }
  .echo-row output { grid-column: 2; }
  .interaction-card { width: calc(100% - 20px); bottom: 158px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
  .scanlines { display: none; }
}
