:root {
  color-scheme: light dark;
  --shell-width: 430px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bg: #eef5ff;
  --surface: rgba(255, 255, 255, 0.93);
  --surface-strong: #ffffff;
  --text: #17213a;
  --muted: #5d6981;
  --border: rgba(37, 57, 94, 0.16);
  --accent: #5a65d8;
  --message-font: "Trebuchet MS", "Avenir Next Rounded", ui-rounded, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; overflow-x: hidden; overflow-y: auto; }
body { min-height: 100svh; min-height: 100dvh; background: var(--bg); color: var(--text); }
button { font: inherit; }

.app-shell {
  position: relative;
  width: 100%;
  max-width: none;
  min-height: 100svh;
  min-height: 100dvh;
  height: auto;
  margin-inline: auto;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  gap: 0;
  padding: 0;
  overflow: visible;
  background: var(--bg);
  isolation: isolate;
  transition: background-color 220ms ease, color 220ms ease;
}

.app-shell[data-theme="night"] {
  --bg: #0f1424;
  --surface: rgba(35, 46, 78, 0.98);
  --surface-strong: #18233d;
  --text: #f7faff;
  --muted: #d5ddf5;
  --border: rgba(229, 235, 255, 0.2);
  --accent: #c0cbff;
}

.scene-panel {
  width: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(190px, 1fr) minmax(82px, auto) auto;
  overflow: visible;
  background: var(--surface-strong);
}

.scene-root { position: absolute; inset: 0; z-index: 0; min-height: 0; width: 100%; height: 100%; }
.scene-root > svg { display: block; width: 100%; height: 100%; max-width: none; }

.event-zone {
  width: min(100%, var(--shell-width));
  justify-self: center;
  min-height: 82px;
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 10px 16px 12px;
  background: color-mix(in srgb, var(--surface-strong) 88%, var(--accent) 12%);
  border-top: 1px solid var(--border);
  transition: background-color 220ms ease, border-color 220ms ease;
}

.game-message {
  width: 100%;
  max-width: 390px;
  margin: 0;
  text-align: center;
  font-family: var(--message-font);
  font-size: clamp(1.08rem, 4.7vw, 1.45rem);
  font-weight: 700;
  line-height: 1.32;
  letter-spacing: 0.01em;
  color: var(--text);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.1);
  text-wrap: balance;
  transition: opacity 180ms ease, transform 180ms ease, color 180ms ease;
}

.info-zone {
  width: min(100%, var(--shell-width));
  justify-self: center;
  padding: 8px 10px 10px;
  border-top: 1px solid var(--border);
  background: var(--surface-strong);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.status-card {
  min-width: 0;
  display: grid;
  align-content: space-between;
  gap: 6px;
  min-height: 58px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  box-shadow: 0 8px 18px rgba(26, 35, 61, 0.05);
  cursor: pointer;
  transition: background-color 200ms ease, border-color 200ms ease, box-shadow 200ms ease, transform 200ms ease;
}

.status-head { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; align-items: center; gap: 4px; }
.status-icon, .category-icon, .menu-option-icon { color: var(--accent); transform-origin: center; }
.status-icon { width: 20px; height: 20px; }
.status-icon svg, .category-icon svg, .menu-option-icon svg { display: block; width: 100%; height: 100%; }
.status-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 0.71rem; }
.status-card strong { font-size: 0.75rem; color: var(--text); }
.status-card[aria-expanded="true"] { background: color-mix(in srgb, var(--surface) 75%, var(--accent) 25%); border-color: var(--accent); }
.status-card--summary { align-content: center; }
.status-card--cycle {
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: center;
  cursor: default;
}
.status-cycle-main { min-width: 0; }
.status-settings-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: color-mix(in srgb, var(--surface) 86%, var(--accent) 14%);
  color: var(--accent);
  cursor: pointer;
}
.status-settings-button[aria-expanded="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--surface) 70%, var(--accent) 30%); }
.status-cycle-progress { grid-column: 1 / -1; width: 100%; }
.progress-track { height: 7px; overflow: hidden; border-radius: 999px; background: color-mix(in srgb, var(--muted) 24%, transparent); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; transform-origin: center; transition: width 220ms ease, background-color 180ms ease, filter 180ms ease, transform 180ms ease; }

.icon-button {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background-color 180ms ease, border-color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

.menu-backdrop {
  position: absolute;
  z-index: 20;
  inset: 0;
  background: rgba(10, 16, 32, 0.44);
  backdrop-filter: blur(2px);
}

.category-menu {
  position: absolute;
  z-index: 25;
  left: 50%;
  right: auto;
  width: min(calc(100% - 20px), var(--shell-width));
  transform: translateX(-50%);
  bottom: max(12px, var(--safe-bottom));
  max-height: min(42dvh, 340px);
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface-strong);
  box-shadow: 0 18px 48px rgba(18, 26, 48, 0.28);
  transition: background-color 180ms ease, border-color 180ms ease;
}

.menu-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.menu-eyebrow { margin: 0 0 2px; color: var(--muted); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
.menu-header h2 { margin: 0; font-size: 1.18rem; color: var(--text); }
.menu-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.menu-option {
  width: 100%;
  min-height: 72px;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background-color 180ms ease, border-color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

.menu-option-icon { width: 27px; height: 27px; }
.menu-option-copy { display: grid; gap: 2px; }
.menu-option-copy strong { font-size: 0.9rem; color: var(--text); }
.menu-option-copy small { color: var(--muted); font-size: 0.75rem; line-height: 1.22; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] { display: none !important; }
button:hover { background: color-mix(in srgb, var(--surface) 84%, var(--accent) 16%); }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button:active { transform: translateY(1px); }

@media (min-width: 431px) {
  body { background: #20283a; }
  .app-shell {
    border-radius: 0;
    overflow: visible;
    margin-block: 0;
    min-height: 100dvh;
    height: auto;
    box-shadow: none;
  }
}

@media (max-width: 390px), (max-height: 760px) {
  .scene-panel { grid-template-rows: minmax(172px, 1fr) minmax(74px, auto) auto; }
  .event-zone { min-height: 74px; padding: 8px 14px 10px; }
  .game-message { font-size: clamp(1rem, 4.8vw, 1.2rem); }
  .info-zone { padding: 8px 8px 8px; }
  .status-grid { gap: 6px; }
  .status-card { padding: 7px; gap: 5px; }
  .status-name { font-size: 0.66rem; }
  .status-card strong { font-size: 0.72rem; }
}

@media (max-width: 360px) {
  .status-head { grid-template-columns: 18px minmax(0, 1fr) auto; gap: 3px; }
  .status-icon { width: 17px; height: 17px; }
  .status-name { display: block; white-space: normal; overflow: visible; text-overflow: clip; font-size: 0.58rem; line-height: 1.05; }
}

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

.scene-stage { position: relative; isolation: isolate; width: 100%; min-height: 0; overflow: hidden; }
.condition-indicators {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 12;
  display: flex;
  flex-wrap: wrap-reverse;
  justify-content: flex-end;
  gap: 7px;
  max-width: 138px;
  pointer-events: none;
}
.condition-indicator {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 2px solid color-mix(in srgb, var(--condition-color) 72%, #ffffff 28%);
  border-radius: 50%;
  color: #ffffff;
  background: color-mix(in srgb, var(--condition-color) 82%, #17213a 18%);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--condition-color) 38%, transparent);
  transform-origin: center;
}
.condition-indicator svg { width: 23px; height: 23px; }
.condition-indicator--critical { width: 42px; height: 42px; box-shadow: 0 0 0 4px color-mix(in srgb, var(--condition-color) 25%, transparent), 0 8px 22px color-mix(in srgb, var(--condition-color) 50%, transparent); }
.priority-indicator { --condition-color: var(--accent); }
.priority-indicator[data-level="critical"] { width: 44px; height: 44px; }
.priority-indicator[data-level="high"] { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 24%, transparent), 0 8px 22px color-mix(in srgb, var(--accent) 42%, transparent); }

.dev-lab {
  position: absolute;
  z-index: 80;
  top: max(8px, var(--safe-top));
  left: 8px;
  right: 8px;
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface-strong) 94%, var(--accent) 6%);
  box-shadow: 0 16px 40px rgba(0,0,0,.25);
  font-size: .76rem;
}
.dev-lab strong { grid-column: 1/-1; }
.dev-lab label { display: grid; gap: 3px; }
.dev-lab select,.dev-lab input,.dev-lab button { min-width: 0; min-height: 36px; }

.dev-lab-output { grid-column: 1 / -1; margin: 0; max-height: 150px; overflow: auto; white-space: pre-wrap; font: 0.68rem/1.35 ui-monospace, SFMono-Regular, Consolas, monospace; }

.onboarding-guide {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px dashed var(--muted);
  border-radius: 14px;
}
.onboarding-guide[hidden] { display: none; }
.onboarding-guide p { margin: 0; color: var(--muted); }
.onboarding-progress { color: var(--muted); font-size: .78rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.secondary-action {
  width: fit-content;
  min-height: 40px;
  border: 0;
  border-radius: 12px;
  padding: 8px 12px;
  background: var(--surface-strong);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}
@media (max-width: 390px), (min-resolution: 2dppx) {
  .onboarding-guide { align-items: flex-start; flex-direction: column; }
  .secondary-action { width: 100%; }
}
