:root {
  --bg: #070a10;
  --panel: rgba(12, 18, 28, 0.94);
  --panel-soft: rgba(18, 27, 40, 0.88);
  --line: rgba(155, 188, 211, 0.17);
  --line-bright: rgba(146, 221, 222, 0.42);
  --text: #e7eef2;
  --muted: #8c9ba7;
  --cyan: #67d5d1;
  --cyan-soft: rgba(103, 213, 209, 0.12);
  --amber: #efbc68;
  --danger: #f06f64;
  --success: #91d88b;
  --violet: #ad91f3;
  --radius: 9px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 16% 12%, rgba(30, 83, 93, 0.17), transparent 32rem),
    radial-gradient(circle at 88% 86%, rgba(93, 60, 130, 0.12), transparent 38rem),
    #070a10;
}

button, select { font: inherit; }
button { color: inherit; }

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.028;
  z-index: 20;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.75'/%3E%3C/svg%3E");
}

.game-shell {
  width: min(1600px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 3px 14px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: var(--cyan);
  border: 1px solid var(--line-bright);
  border-radius: 50%;
  box-shadow: inset 0 0 18px rgba(103, 213, 209, 0.08), 0 0 22px rgba(103, 213, 209, 0.06);
}
.brand h1 { margin: 0; font-size: 17px; letter-spacing: 0.02em; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 14px; }
.top-actions { display: flex; gap: 8px; align-items: center; }

button {
  border: 1px solid var(--line);
  background: rgba(19, 28, 40, 0.84);
  cursor: pointer;
  transition: border-color 130ms ease, background 130ms ease, transform 130ms ease, color 130ms ease;
}
button:hover:not(:disabled) { border-color: var(--line-bright); color: #fff; background: rgba(29, 46, 58, 0.95); }
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
button:disabled { opacity: 0.38; cursor: not-allowed; }

.icon-button, .text-button { height: 34px; border-radius: 5px; }
.icon-button { width: 36px; font-family: "IBM Plex Mono", monospace; }
.text-button { padding: 0 13px; color: var(--muted); font-size: 14px; }

.play-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 292px;
  gap: 14px;
  padding: 14px 0;
}

.viewport-panel {
  position: relative;
  min-width: 0;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #080b10;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

#viewport { display: block; width: 100%; height: 100%; image-rendering: auto; }
.viewport-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.54) 120%);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.32);
}

.location-strip {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  min-height: 35px;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 7px 11px;
  border: 1px solid rgba(180, 220, 230, 0.15);
  border-radius: 5px;
  background: rgba(4, 9, 14, 0.67);
  backdrop-filter: blur(7px);
  font-size: 13px;
}
.location-strip #level-kicker { color: var(--cyan); font-family: "IBM Plex Mono", monospace; letter-spacing: 0.09em; }
.location-strip strong { font-size: 14px; }
.location-strip #facing-label { margin-left: auto; color: var(--muted); font-family: "IBM Plex Mono", monospace; }

.crosshair { position: absolute; inset: 50% auto auto 50%; width: 18px; height: 18px; transform: translate(-50%, -50%); opacity: 0.42; }
.crosshair span { position: absolute; background: #e7f4f3; }
.crosshair span:first-child { width: 18px; height: 1px; top: 8px; }
.crosshair span:last-child { width: 1px; height: 18px; left: 8px; }

.interaction-hint {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  padding: 8px 12px;
  border: 1px solid var(--line-bright);
  border-radius: 5px;
  color: #dffafa;
  background: rgba(5, 14, 20, 0.86);
  backdrop-filter: blur(7px);
  font: 500 13px "IBM Plex Mono", monospace;
  white-space: nowrap;
}
.hidden { display: none !important; }

.party-formation {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 3;
  display: flex;
  align-items: flex-end;
  gap: 5px;
  pointer-events: none;
}
.formation-member {
  position: relative;
  width: 58px;
  height: 72px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--hero-color) 60%, transparent);
  border-radius: 7px 7px 4px 4px;
  background-image: linear-gradient(to top, rgba(4, 8, 12, 0.72), transparent 45%), url("assets/party-portraits.png");
  background-position: center, var(--portrait-x) var(--portrait-y);
  background-size: 100% 100%, 200% 200%;
  background-repeat: no-repeat;
  box-shadow: 0 7px 18px rgba(0,0,0,0.4), inset 0 0 0 1px rgba(255,255,255,0.04);
}
.formation-member.back { width: 52px; height: 64px; opacity: 0.78; }
.formation-member.down { filter: grayscale(1); opacity: 0.35; }
.formation-member span {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 3px 2px;
  overflow: hidden;
  color: #f0f6f7;
  background: rgba(3,7,11,0.7);
  font: 600 10px "IBM Plex Mono", monospace;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast-stack { position: absolute; right: 16px; bottom: 16px; width: min(320px, 50%); display: grid; gap: 7px; pointer-events: none; }
.toast {
  padding: 10px 12px;
  border-left: 2px solid var(--cyan);
  border-radius: 4px;
  background: rgba(6, 12, 18, 0.9);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.3);
  font-size: 13px;
  animation: toast-in 200ms ease both;
}
.toast.danger { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateX(10px); } }

.side-panel { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.instrument-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, var(--panel-soft), rgba(8, 13, 21, 0.96));
}
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 9px; }
.section-heading > span { color: var(--muted); font: 600 11px "IBM Plex Mono", monospace; letter-spacing: 0.1em; text-transform: uppercase; }
.section-heading > b { color: var(--cyan); font: 500 11px "IBM Plex Mono", monospace; }
.objective-card h2 { margin: 0 0 7px; font-size: 17px; }
.objective-card p { min-height: 48px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.progress-track { height: 4px; margin-top: 12px; overflow: hidden; border-radius: 5px; background: rgba(255,255,255,0.07); }
.progress-track span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--cyan), #8ee7b9); transition: width 250ms ease; }

.minimap-card { flex: 1; min-height: 224px; }
#minimap { display: block; width: 100%; height: auto; max-height: 204px; background: rgba(1, 5, 9, 0.72); border-radius: 4px; }
.mini-button { padding: 4px 8px; border-radius: 4px; color: var(--muted); font: 500 11px "IBM Plex Mono", monospace; }

.evidence-slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.evidence-slot { min-width: 0; padding: 8px 3px; text-align: center; border: 1px dashed var(--line); border-radius: 4px; color: #596572; }
.evidence-slot i { display: block; margin-bottom: 4px; font-style: normal; font-size: 18px; }
.evidence-slot span { display: block; overflow: hidden; font: 500 10px "IBM Plex Mono", monospace; text-overflow: ellipsis; }
.evidence-slot.collected { color: var(--amber); border-style: solid; border-color: rgba(239, 188, 104, 0.36); background: rgba(239, 188, 104, 0.06); }

.control-deck {
  display: grid;
  grid-template-columns: 184px minmax(560px, 1fr) 286px;
  gap: 12px;
  align-items: stretch;
}
.movement-panel, .party-panel, .log-panel {
  min-width: 0;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.dpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.dpad button { height: 35px; border-radius: 4px; color: #a9bbc5; font: 600 12px "IBM Plex Mono", monospace; }
.dpad .interact-button { padding: 0; color: var(--cyan); font-size: 10px; }

.party-panel { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 8px; }
.hero-card {
  position: relative;
  min-width: 0;
  padding: 9px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: linear-gradient(145deg, rgba(24, 35, 47, 0.95), rgba(10, 15, 24, 0.98));
  transition: border-color 150ms ease, opacity 150ms ease;
}
.hero-card.front { border-top-color: rgba(103, 213, 209, 0.5); }
.hero-card.down { opacity: 0.52; filter: grayscale(0.7); }
.hero-card.ready { box-shadow: inset 0 1px 0 rgba(103, 213, 209, 0.16); }
.hero-head { display: flex; gap: 8px; align-items: center; min-width: 0; }
.portrait {
  position: relative;
  flex: 0 0 58px;
  width: 58px;
  height: 64px;
  border: 1px solid var(--hero-color, var(--line-bright));
  border-radius: 6px;
  background-image: linear-gradient(to top, rgba(4,8,12,0.54), transparent 42%), url("assets/party-portraits.png");
  background-position: center, var(--portrait-x) var(--portrait-y);
  background-size: 100% 100%, 200% 200%;
  background-repeat: no-repeat;
  box-shadow: inset 0 0 12px rgba(0,0,0,0.18);
}
.portrait::after { content: ""; position: absolute; inset: 3px; border: 1px solid rgba(255,255,255,0.08); border-radius: 3px; }
.hero-identity { min-width: 0; }
.hero-identity strong { display: block; overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.hero-identity span { display: block; margin-top: 2px; color: var(--muted); font: 500 10px "IBM Plex Mono", monospace; white-space: nowrap; }
.hero-identity em { display: block; max-width: 112px; margin-top: 4px; overflow: hidden; color: var(--hero-color, var(--cyan)); font: normal 500 10px/1.25 "IBM Plex Mono", monospace; text-overflow: ellipsis; }
.stat-bars { display: grid; gap: 3px; margin: 8px 0; }
.stat-row { display: grid; grid-template-columns: 20px 1fr 38px; gap: 5px; align-items: center; color: var(--muted); font: 500 10px "IBM Plex Mono", monospace; }
.bar { height: 6px; overflow: hidden; border-radius: 3px; background: rgba(255,255,255,0.06); }
.bar span { display: block; height: 100%; transition: width 160ms linear; }
.bar.health span { background: linear-gradient(90deg, #c84e4e, #ee7a69); }
.bar.stamina span { background: linear-gradient(90deg, #b78642, #e5b35b); }
.bar.focus span { background: linear-gradient(90deg, #487d9f, #69bdd2); }
.hero-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.hero-action { position: relative; height: 34px; padding: 0 6px; overflow: hidden; border-radius: 4px; font: 600 10px "IBM Plex Mono", monospace; }
.hero-action .cooldown { position: absolute; inset: auto 0 0; height: 0; background: rgba(0,0,0,0.65); pointer-events: none; }
.hero-action.ability { color: var(--hero-color, var(--cyan)); }
.hero-status { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(20, 5, 8, 0.72); color: #ffada4; font: 700 10px "IBM Plex Mono", monospace; letter-spacing: 0.12em; }

.log-panel { display: flex; flex-direction: column; }
.combat-log { height: 112px; overflow: hidden auto; mask-image: linear-gradient(to bottom, transparent, black 15%, black); font: 400 11px/1.55 "IBM Plex Mono", monospace; color: #a9b7c0; }
.log-entry { margin: 0 0 4px; }
.log-entry strong { color: #d9e4e8; font-weight: 500; }
.log-entry.damage { color: #e19289; }
.log-entry.success { color: #9cd69a; }
.quick-items { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-top: auto; padding-top: 8px; border-top: 1px solid var(--line); }
.quick-item { min-width: 0; height: 34px; border-radius: 4px; color: var(--muted); font: 500 10px "IBM Plex Mono", monospace; }
.quick-item b { color: var(--amber); }

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 6, 10, 0.76);
  backdrop-filter: blur(10px);
}
.modal-layer:empty { display: none; }
.modal {
  width: min(700px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 30px;
  border: 1px solid var(--line-bright);
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(21, 34, 46, 0.98), rgba(8, 13, 21, 0.99)),
    var(--panel);
  box-shadow: 0 26px 90px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.04);
  animation: modal-in 220ms ease both;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.99); } }
.modal-emblem { width: 56px; height: 56px; display: grid; place-items: center; margin: 0 auto 16px; border: 1px solid var(--line-bright); border-radius: 50%; color: var(--cyan); font-size: 22px; }
.eyebrow { margin: 0 0 8px; color: var(--cyan); text-align: center; font: 500 11px "IBM Plex Mono", monospace; letter-spacing: 0.12em; text-transform: uppercase; }
.modal h2 { margin: 0; text-align: center; font-size: clamp(25px, 5vw, 39px); letter-spacing: -0.035em; }
.modal .lead { max-width: 580px; margin: 13px auto 22px; color: #b6c3cb; text-align: center; font-size: 15px; line-height: 1.65; }
.briefing-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 20px 0; }
.briefing-grid div { padding: 13px; text-align: center; border: 1px solid var(--line); border-radius: 6px; background: rgba(0,0,0,0.12); }
.briefing-grid b { display: block; color: var(--amber); font: 600 20px "IBM Plex Mono", monospace; }
.briefing-grid span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.difficulty-label { display: block; margin: 22px 0 7px; color: var(--muted); font: 500 11px "IBM Plex Mono", monospace; text-transform: uppercase; letter-spacing: 0.1em; }
.modal select { width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 5px; background: rgba(3,8,14,0.68); color: var(--text); }
.asset-loading-status { margin: 10px 0 -9px; color: var(--amber); text-align: center; font: 500 11px "IBM Plex Mono", monospace; }
.asset-loading-status.ready { color: var(--success); }
.asset-loading-status.failed { color: var(--danger); }
.modal-actions { display: flex; justify-content: center; gap: 9px; margin-top: 22px; }
.primary-button, .secondary-button { min-height: 44px; padding: 0 22px; border-radius: 5px; font-weight: 700; font-size: 13px; }
.primary-button { color: #071013; border-color: var(--cyan); background: var(--cyan); }
.primary-button:hover:not(:disabled) { color: #061012; background: #8ce6e2; }
.secondary-button { color: var(--muted); }
.keyboard-note { margin: 18px 0 0; color: #71818d; text-align: center; font: 400 10px "IBM Plex Mono", monospace; }

.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 22px; }
.help-grid > div { padding: 13px; border: 1px solid var(--line); border-radius: 6px; }
.help-grid b { color: var(--amber); font-size: 13px; }
.help-grid p { margin: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

.puzzle-modal { width: min(620px, 100%); }
.puzzle-symbol { width: 58px; height: 58px; display: grid; place-items: center; margin: 0 auto 13px; border-radius: 50%; color: var(--amber); border: 1px solid rgba(239, 188, 104, 0.4); font: 600 20px "IBM Plex Mono", monospace; }
.puzzle-options { display: grid; gap: 8px; margin-top: 18px; }
.puzzle-option { min-height: 48px; padding: 11px 14px; border-radius: 5px; color: #c4cfd5; text-align: left; font-size: 13px; line-height: 1.45; }
.puzzle-option:hover { color: #fff; }

.journal-modal { width: min(820px, 100%); }
.journal-tabs { display: flex; gap: 6px; margin: 18px 0 13px; }
.journal-tabs button { padding: 8px 12px; border-radius: 4px; color: var(--muted); font-size: 12px; }
.journal-tabs button.active { color: var(--cyan); border-color: var(--line-bright); background: var(--cyan-soft); }
.journal-content { max-height: 48vh; overflow: auto; padding-right: 8px; }
.journal-entry { padding: 12px 0; border-bottom: 1px solid var(--line); }
.journal-entry h3 { margin: 0 0 6px; font-size: 15px; }
.journal-entry p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }

.boss-banner {
  position: fixed;
  top: 82px;
  left: 50%;
  z-index: 30;
  width: min(520px, calc(100% - 40px));
  transform: translateX(-50%);
  padding: 9px 12px;
  border: 1px solid rgba(240, 111, 100, 0.33);
  border-radius: 6px;
  background: rgba(21, 7, 10, 0.88);
  box-shadow: 0 8px 28px rgba(0,0,0,0.4);
}
.boss-banner-head { display: flex; justify-content: space-between; margin-bottom: 7px; font: 600 11px "IBM Plex Mono", monospace; color: #eab2ac; }
.boss-health { height: 5px; background: rgba(255,255,255,0.07); }
.boss-health span { display: block; height: 100%; background: linear-gradient(90deg, #ac3d43, #ed7264); transition: width 180ms linear; }

@media (max-width: 1180px) {
  .play-area { grid-template-columns: minmax(0, 1fr) 250px; }
  .control-deck { grid-template-columns: 170px minmax(500px, 1fr); }
  .log-panel { grid-column: 1 / -1; min-height: 140px; }
  .combat-log { height: 75px; }
}

@media (max-width: 900px) {
  .game-shell { padding: 10px; }
  .play-area { grid-template-columns: 1fr; }
  .side-panel { display: grid; grid-template-columns: 1fr 1fr; }
  .minimap-card { grid-row: span 2; }
  .control-deck { grid-template-columns: 1fr; }
  .party-panel { grid-template-columns: 1fr 1fr; }
  .movement-panel { order: 2; }
  .log-panel { order: 3; grid-column: auto; }
  .dpad { max-width: 260px; margin: 0 auto; }
}

@media (max-width: 580px) {
  .brand p { display: none; }
  .brand h1 { font-size: 14px; }
  .top-actions .text-button { display: none; }
  .play-area { padding-top: 10px; }
  .side-panel { grid-template-columns: 1fr; }
  .minimap-card { grid-row: auto; }
  .party-panel { grid-template-columns: 1fr; }
  .party-formation { transform: scale(0.82); transform-origin: bottom left; }
  .location-strip strong { max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .location-strip #facing-label { display: none; }
  .help-grid { grid-template-columns: 1fr; }
  .briefing-grid span { font-size: 10px; }
  .modal { padding: 22px 17px; }
  .modal-actions { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
