:root {
  color-scheme: dark;
  --ink: #f7f4e8;
  --muted: #c2c7bd;
  --quiet: #88948c;
  --panel: rgba(12, 24, 25, 0.88);
  --panel-solid: #102123;
  --line: rgba(222, 231, 211, 0.2);
  --leaf: #9bdc8d;
  --cyan: #8ce3d1;
  --amber: #ffc56d;
  --rust: #d77a43;
  --danger: #ff9b80;
  --safe-top: max(14px, env(safe-area-inset-top));
  --safe-right: max(14px, env(safe-area-inset-right));
  --safe-bottom: max(14px, env(safe-area-inset-bottom));
  --safe-left: max(14px, env(safe-area-inset-left));
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #071416;
  color: var(--ink);
}

button,
select,
input { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

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

canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

[hidden] { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
}

.eyebrow {
  display: block;
  margin: 0 0 0.45rem;
  color: var(--cyan);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  line-height: 1.25;
  text-transform: uppercase;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(14px);
}

.button,
.icon-button,
.interaction-panel button,
.choice-buttons button,
.island-card button,
.mobile-controls button {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font-weight: 750;
}

.button {
  min-height: 46px;
  padding: 0.75rem 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.button:hover,
.icon-button:hover,
.island-card button:hover { background: rgba(255, 255, 255, 0.15); }

.button-primary {
  border-color: rgba(255, 197, 109, 0.65);
  color: #16201d;
  background: linear-gradient(180deg, #ffe0a5, #f5b85f);
}

.button-primary:hover { background: linear-gradient(180deg, #ffebc2, #ffc66f); }
.button-secondary { border-color: rgba(140, 227, 209, 0.4); }
.button-text { border-color: transparent; background: transparent; color: var(--cyan); }
.button-danger { border-color: rgba(255, 155, 128, 0.48); color: #ffd4c8; background: rgba(122, 33, 19, 0.35); }
.button-row { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.stacked-actions { display: grid; gap: 0.7rem; }

.loading-screen {
  display: grid;
  place-items: center;
  padding: 1rem;
  background:
    radial-gradient(circle at 50% 70%, rgba(56, 109, 91, 0.28), transparent 42%),
    linear-gradient(160deg, #081719, #102627 55%, #071416);
}

.loading-card {
  width: min(460px, 100%);
  text-align: center;
}

.loading-card h1 { margin: 0.4rem 0; font: 650 clamp(1.8rem, 5vw, 3rem)/1.05 ui-serif, Georgia, serif; }
.loading-card p { color: var(--muted); }

.loading-orbit {
  position: relative;
  width: 84px;
  height: 84px;
  margin: 0 auto 1.3rem;
  border: 1px solid rgba(140, 227, 209, 0.25);
  border-radius: 50%;
  animation: slow-spin 9s linear infinite;
}

.loading-orbit span {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--leaf);
  box-shadow: 0 0 22px rgba(155, 220, 141, 0.5);
}

.loading-orbit span:nth-child(1) { left: 4px; top: 40px; }
.loading-orbit span:nth-child(2) { right: 8px; top: 12px; background: var(--amber); }
.loading-orbit span:nth-child(3) { right: 1px; bottom: 8px; background: var(--cyan); }

@keyframes slow-spin { to { transform: rotate(360deg); } }

.progress,
.quest-progress,
.recall-progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
}

.progress span,
.quest-progress span,
.recall-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--amber));
  transition: width 240ms ease;
}

.loading-count { font-size: 0.8rem; }

.intro-screen {
  display: flex;
  align-items: center;
  padding: clamp(1.2rem, 6vw, 5rem);
  background: linear-gradient(90deg, rgba(4, 13, 15, 0.9) 0%, rgba(4, 13, 15, 0.62) 48%, rgba(4, 13, 15, 0.1) 80%);
}

.intro-vignette { position: absolute; inset: 0; background: linear-gradient(0deg, rgba(2, 9, 10, 0.64), transparent 44%); pointer-events: none; }
.intro-copy { position: relative; width: min(650px, 100%); }
.intro-copy h1 { margin: 0 0 1rem; max-width: 620px; font: 650 clamp(2.6rem, 7vw, 5.4rem)/0.96 ui-serif, Georgia, serif; letter-spacing: -0.045em; }
.intro-deck { max-width: 600px; margin: 0 0 1.4rem; color: var(--muted); font-size: clamp(1rem, 2vw, 1.25rem); line-height: 1.55; }

.daily-preview {
  width: min(540px, 100%);
  margin-bottom: 1.25rem;
  padding: 1rem 1.1rem;
  border-left: 3px solid var(--amber);
  background: rgba(10, 28, 27, 0.68);
}

.daily-preview span { display: block; color: var(--amber); font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.12em; }
.daily-preview strong { display: block; margin: 0.3rem 0; font-size: 1.25rem; }
.daily-preview p { margin: 0; color: var(--muted); }
.version-links { display: flex; flex-wrap: wrap; gap: 0.8rem 1rem; margin-top: 1.2rem; color: var(--quiet); font-size: 0.84rem; }
.version-links a { color: var(--cyan); }

.hud-top {
  position: fixed;
  z-index: 5;
  top: var(--safe-top);
  left: var(--safe-left);
  right: var(--safe-right);
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  pointer-events: none;
}

.brand-panel,
.condition-panel { min-height: 56px; padding: 0.65rem 0.8rem; pointer-events: auto; }
.brand-panel { width: 160px; }
.brand-panel strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.condition-panel { display: flex; align-items: center; gap: 1rem; color: var(--muted); font-size: 0.78rem; }
.condition-panel b { color: var(--ink); }
.hud-buttons { margin-left: auto; display: flex; gap: 0.4rem; pointer-events: auto; }
.icon-button { min-height: 44px; padding: 0.55rem 0.75rem; background: var(--panel); backdrop-filter: blur(14px); }
.icon-button b { color: var(--amber); }

.quest-panel {
  position: fixed;
  z-index: 5;
  top: calc(var(--safe-top) + 72px);
  left: var(--safe-left);
  width: min(330px, calc(100vw - 28px));
  padding: 0.9rem 1rem;
}

.quest-panel h2 { margin: 0 0 0.35rem; font: 650 1.25rem/1.15 ui-serif, Georgia, serif; }
.quest-panel p:not(.eyebrow) { margin: 0 0 0.8rem; color: var(--muted); font-size: 0.88rem; line-height: 1.4; }
.quest-panel small { display: block; margin-top: 0.4rem; color: var(--quiet); }

.interaction-panel {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 38px);
  width: min(390px, calc(100vw - 28px));
  padding: 0.75rem;
  transform: translateX(-50%);
  text-align: center;
}

.interaction-panel span { display: block; margin-bottom: 0.45rem; color: var(--muted); font-size: 0.8rem; }
.interaction-panel button { width: 100%; min-height: 44px; border-color: rgba(255, 197, 109, 0.52); background: rgba(255, 197, 109, 0.16); }
.interaction-panel small { display: block; margin-top: 0.35rem; color: var(--quiet); }

.choice-panel {
  position: fixed;
  z-index: 12;
  top: 50%;
  left: 50%;
  width: min(520px, calc(100vw - 28px));
  padding: 1.25rem;
  transform: translate(-50%, -50%);
}

.choice-panel h2 { margin: 0 0 0.5rem; font: 650 1.8rem/1.1 ui-serif, Georgia, serif; }
.choice-panel p:not(.eyebrow) { color: var(--muted); }
.choice-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.choice-buttons button { min-height: 62px; padding: 0.8rem; border-color: rgba(140, 227, 209, 0.42); }

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 18px);
  max-width: min(640px, calc(100vw - 28px));
  margin: 0;
  padding: 0.75rem 1rem;
  border: 1px solid rgba(255, 197, 109, 0.45);
  border-radius: 12px;
  color: #fff6df;
  background: rgba(39, 29, 14, 0.94);
  transform: translateX(-50%);
  text-align: center;
}

.desktop-help { position: fixed; z-index: 4; right: var(--safe-right); bottom: var(--safe-bottom); margin: 0; color: rgba(255, 255, 255, 0.58); font-size: 0.72rem; text-shadow: 0 1px 4px #000; }
.recall-panel { position: fixed; z-index: 7; left: 50%; top: 44%; width: min(320px, calc(100vw - 28px)); padding: 0.8rem; transform: translate(-50%, -50%); text-align: center; }
.recall-panel span { display: block; margin-bottom: 0.5rem; }

.card-screen {
  display: grid;
  place-items: center;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  background: rgba(3, 10, 11, 0.76);
  backdrop-filter: blur(12px);
}

.screen-card {
  width: min(980px, 100%);
  max-height: min(88vh, 820px);
  overflow: auto;
  padding: clamp(1rem, 3vw, 2rem);
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(160deg, rgba(20, 44, 43, 0.98), rgba(10, 26, 28, 0.99));
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.5);
}

.compact-card { width: min(430px, 100%); }
.screen-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.screen-heading h2,
.compact-card h2 { margin: 0; font: 650 clamp(1.65rem, 4vw, 2.5rem)/1.05 ui-serif, Georgia, serif; }
.screen-intro { max-width: 720px; color: var(--muted); line-height: 1.55; }
.close-button { width: 42px; height: 42px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 50%; color: var(--ink); background: transparent; cursor: pointer; font-size: 1.5rem; }

.island-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 1.4rem; }
.island-card { min-height: 250px; display: flex; flex-direction: column; padding: 1rem; border: 1px solid var(--line); border-radius: 15px; background: rgba(255, 255, 255, 0.035); }
.island-card[data-island="canopy-crown"] { border-top: 4px solid #78cd7d; }
.island-card[data-island="emberglass"] { border-top: 4px solid #e78951; }
.island-card[data-island="tidelight-atoll"] { border-top: 4px solid #68d7c8; }
.island-card h3 { margin: 0 0 0.4rem; font: 650 1.4rem/1.1 ui-serif, Georgia, serif; }
.island-card p { margin: 0 0 1rem; color: var(--muted); font-size: 0.9rem; line-height: 1.45; }
.island-card ul { margin: 0 0 1rem; padding-left: 1.15rem; color: var(--quiet); font-size: 0.8rem; }
.island-card button { min-height: 44px; margin-top: auto; }
.island-card button:disabled { cursor: default; color: var(--quiet); opacity: 0.65; }
.ship-status { margin-top: 1rem; padding: 0.8rem; display: flex; justify-content: space-between; border-top: 1px solid var(--line); color: var(--muted); }
.ship-status strong { color: var(--ink); }

.drift-list { display: grid; gap: 0.7rem; margin: 1.2rem 0; }
.drift-entry { display: grid; grid-template-columns: 100px 1fr auto; gap: 1rem; align-items: center; padding: 0.9rem; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, 0.025); }
.drift-entry time { color: var(--quiet); font-size: 0.78rem; }
.drift-entry h3 { margin: 0 0 0.2rem; font-size: 1rem; }
.drift-entry p { margin: 0; color: var(--muted); font-size: 0.84rem; }
.drift-entry button { min-height: 38px; padding: 0.45rem 0.75rem; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: rgba(255,255,255,0.07); cursor: pointer; }
.drift-entry.is-complete { opacity: 0.68; }
.milestone-card { display: grid; grid-template-columns: 1fr auto; gap: 0.2rem 1rem; padding: 1rem; border-left: 3px solid var(--amber); background: rgba(255, 197, 109, 0.08); }
.milestone-card span { color: var(--muted); }
.milestone-card strong { grid-row: span 2; font: 650 2.5rem/1 ui-serif, Georgia, serif; color: var(--amber); }
.milestone-card p { margin: 0; color: var(--quiet); }

.ecology-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 1.2rem; }
.ecology-island { padding: 1rem; border: 1px solid var(--line); border-radius: 14px; }
.ecology-island h3 { margin: 0 0 0.8rem; font: 650 1.25rem/1.1 ui-serif, Georgia, serif; }
.ecology-reading { margin-bottom: 0.7rem; }
.ecology-reading div { display: flex; justify-content: space-between; margin-bottom: 0.25rem; color: var(--muted); font-size: 0.78rem; }
.ecology-meter { height: 7px; border-radius: 999px; background: rgba(255,255,255,0.08); overflow: hidden; }
.ecology-meter span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--rust), var(--amber), var(--leaf)); }
.phenomenon-card { margin-top: 1rem; padding: 1rem; border: 1px solid rgba(140, 227, 209, 0.26); border-radius: 14px; background: rgba(140, 227, 209, 0.06); }
.phenomenon-card h3 { margin: 0 0 0.3rem; }
.phenomenon-card p { margin: 0; color: var(--muted); }

.league-roster { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; margin: 1rem 0; }
.league-human { padding: 1rem; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,0.03); }
.league-human h3 { margin: 0; }
.league-human p { color: var(--muted); font-size: 0.84rem; }
.composure { height: 7px; border-radius: 999px; background: rgba(255,255,255,0.08); overflow: hidden; }
.composure span { display: block; height: 100%; background: var(--amber); }
.league-result { min-height: 1.4rem; color: var(--cyan); }

.settings-card { width: min(620px, 100%); }
.settings-card > label { display: grid; grid-template-columns: 1fr minmax(140px, 240px); align-items: center; gap: 1rem; padding: 0.8rem 0; border-bottom: 1px solid var(--line); }
.settings-card select,
.settings-card input[type="range"] { width: 100%; }
.check-row input { justify-self: end; width: 22px; height: 22px; }
.costume-card { margin-top: 1rem; padding: 1rem; border: 1px solid var(--line); border-radius: 12px; background: rgba(140, 227, 209, 0.035); }
.costume-card h3 { margin: 0 0 0.25rem; }
.costume-card > p { margin: 0 0 0.8rem; color: var(--muted); font-size: 0.86rem; }
.costume-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.55rem; }
.costume-option { min-height: 48px; display: flex; align-items: center; gap: 0.65rem; padding: 0.55rem 0.7rem; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: rgba(255,255,255,0.035); text-align: left; cursor: pointer; }
.costume-option::before { content: ""; width: 20px; height: 20px; flex: 0 0 auto; border-radius: 50%; background: var(--coat, #6ab4c8); box-shadow: inset 0 0 0 4px rgba(255,255,255,0.18); }
.costume-option[aria-pressed="true"] { border-color: var(--cyan); background: rgba(140, 227, 209, 0.1); }
.costume-option:disabled { cursor: default; opacity: 0.4; }
.memory-card { margin-top: 1rem; padding: 1rem; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,0.025); }
.memory-card h3 { margin-top: 0; }
.memory-card p { color: var(--muted); }
.diagnostics-readout { color: var(--quiet); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.72rem; }

.travel-screen { display: grid; place-items: center; background: rgba(2, 12, 15, 0.42); }
.travel-copy { width: min(480px, calc(100vw - 28px)); padding: 1.3rem; border: 1px solid var(--line); border-radius: 18px; background: rgba(8, 25, 28, 0.9); text-align: center; }
.travel-copy h2 { margin: 0 0 0.5rem; font: 650 2rem/1.05 ui-serif, Georgia, serif; }
.travel-copy p:not(.eyebrow) { color: var(--muted); }

.mobile-controls { position: fixed; z-index: 8; left: var(--safe-left); right: var(--safe-right); bottom: var(--safe-bottom); align-items: end; justify-content: space-between; pointer-events: none; }
.move-pad { width: 150px; display: grid; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(2, 48px); gap: 3px; }
.move-pad button { pointer-events: auto; min-width: 48px; min-height: 48px; background: rgba(10, 26, 28, 0.72); touch-action: none; }
.move-pad button:nth-child(1) { grid-column: 2; }
.move-pad button:nth-child(2) { grid-column: 1; grid-row: 2; }
.move-pad button:nth-child(3) { grid-column: 3; grid-row: 2; }
.move-pad button:nth-child(4) { grid-column: 2; grid-row: 2; }
.mobile-actions { display: flex; align-items: end; gap: 0.4rem; }
.mobile-actions button { pointer-events: auto; min-width: 58px; min-height: 58px; padding: 0.35rem; background: rgba(10, 26, 28, 0.76); font-size: 0.7rem; touch-action: none; }
.mobile-actions button[data-action] { min-width: 72px; min-height: 72px; border-color: rgba(255, 197, 109, 0.6); background: rgba(255, 197, 109, 0.18); }
.pressed { transform: scale(0.94); background: rgba(255, 197, 109, 0.28) !important; }

@media (max-width: 800px) {
  .condition-panel span:nth-child(2) { display: none; }
  .hud-buttons .icon-button { font-size: 0; width: 44px; padding: 0; }
  .hud-buttons .icon-button::after { content: attr(data-short); font-size: 0.68rem; }
  .icon-button b { display: none; }
  .island-grid,
  .ecology-grid { grid-template-columns: 1fr; }
  .league-roster { grid-template-columns: 1fr; }
  .screen-card { max-height: 94vh; }
}

@media (max-width: 600px), (pointer: coarse) {
  .desktop-help { display: none; }
  .mobile-controls { display: flex; }
  .hud-top { align-items: stretch; }
  .brand-panel { width: 126px; }
  .condition-panel { flex: 1; justify-content: center; padding-inline: 0.45rem; }
  .condition-panel span:first-child { display: none; }
  .hud-buttons { position: fixed; right: var(--safe-right); top: calc(var(--safe-top) + 64px); display: grid; grid-template-columns: repeat(2, 44px); }
  .hud-buttons .icon-button:nth-child(4) { display: none; }
  .quest-panel { top: calc(var(--safe-top) + 64px); width: min(270px, calc(100vw - 110px)); padding: 0.7rem 0.8rem; }
  .quest-panel h2 { font-size: 1rem; }
  .quest-panel p:not(.eyebrow) { display: none; }
  .interaction-panel { bottom: calc(var(--safe-bottom) + 84px); width: min(270px, calc(100vw - 180px)); }
  .choice-buttons { grid-template-columns: 1fr; }
  .intro-screen { align-items: end; padding-bottom: max(1.4rem, env(safe-area-inset-bottom)); background: linear-gradient(0deg, rgba(3, 12, 13, 0.96), rgba(3, 12, 13, 0.38) 76%); }
  .intro-copy h1 { font-size: clamp(2.2rem, 12vw, 3.7rem); }
  .intro-deck { font-size: 0.95rem; }
  .daily-preview { padding: 0.75rem; }
  .drift-entry { grid-template-columns: 1fr auto; gap: 0.35rem 0.7rem; }
  .drift-entry time { grid-column: 1 / -1; }
  .settings-card > label { grid-template-columns: 1fr; gap: 0.45rem; }
  .costume-grid { grid-template-columns: 1fr; }
}

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