:root {
  color-scheme: dark;
  --ink: #edf6ef;
  --muted: rgba(228, 241, 232, 0.72);
  --quiet: rgba(218, 234, 224, 0.5);
  --glass: rgba(6, 15, 22, 0.66);
  --glass-strong: rgba(5, 12, 18, 0.91);
  --edge: rgba(190, 219, 206, 0.22);
  --focus: #a5e4c1;
  --rain: #86b7c8;
  --heat: #d99972;
  --wind: #a8c8a0;
  --storm: #b3a8c9;
  --snow: #d4e5e8;
  --sun: #e1c680;
  font-family: "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo, system-ui, sans-serif;
}

* { box-sizing: border-box; }

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

button { font: inherit; -webkit-tap-highlight-color: transparent; }

.aquarium-app {
  position: fixed;
  inset: 0;
  min-width: 320px;
  overflow: hidden;
  background: #050b0f;
}

#aquarium {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.topbar {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: calc(13px + env(safe-area-inset-top)) 13px 8px;
  pointer-events: none;
}

.identity { min-width: 0; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.74); }

.product-name {
  margin: 0 0 3px;
  color: var(--quiet);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0;
}

.topbar #worldClock {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.top-actions { display: flex; gap: 7px; pointer-events: auto; }

.icon-button,
.close-button {
  display: grid;
  place-items: center;
  border: 1px solid var(--edge);
  border-radius: 7px;
  color: var(--muted);
  background: var(--glass);
  backdrop-filter: blur(12px);
}

.icon-button { width: 40px; height: 40px; font-size: 12px; }
.close-button { min-width: 38px; height: 36px; padding: 0 9px; font-size: 11px; }

.icon-button[aria-pressed="true"],
.icon-button[aria-expanded="true"] {
  color: var(--ink);
  border-color: rgba(165, 228, 193, 0.58);
  background: rgba(38, 74, 65, 0.7);
}

.world-whisper {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: calc(72px + env(safe-area-inset-bottom));
  width: min(88%, 440px);
  margin: 0;
  padding: 8px 11px;
  color: rgba(240, 247, 239, 0.88);
  font-size: 12px;
  line-height: 1.55;
  text-align: center;
  text-shadow: 0 1px 8px #000;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 700ms ease;
  pointer-events: none;
}

.world-whisper.is-visible { opacity: 1; }

.origin-gate {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 26px 20px;
  background: linear-gradient(180deg, rgba(3, 9, 13, 0.47), rgba(2, 7, 10, 0.9));
  transition: opacity 900ms ease, visibility 900ms ease;
}

.origin-gate.is-hidden { visibility: hidden; opacity: 0; pointer-events: none; }
.origin-gate.is-loading { transition: none; }

.origin-copy { width: min(100%, 430px); text-align: center; }
.origin-mark { margin: 0 0 16px; color: var(--quiet); font: 10px ui-monospace, Consolas, monospace; }

.origin-copy h2 {
  margin: 0 auto;
  max-width: 13em;
  font-size: 22px;
  font-weight: 500;
  line-height: 1.55;
  letter-spacing: 0;
}

.origin-copy > p:not(.origin-mark) {
  max-width: 25em;
  margin: 14px auto 22px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.9;
}

.origin-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }

.origin-choices button {
  min-height: 82px;
  padding: 13px 9px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(15, 31, 36, 0.78);
  backdrop-filter: blur(13px);
}

.origin-choices button:last-child { background: rgba(18, 27, 45, 0.8); }
.origin-choices strong { display: block; font-size: 15px; font-weight: 500; }
.origin-choices span { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; }

.weather-shell {
  position: absolute;
  z-index: 5;
  left: 10px;
  right: 10px;
  bottom: calc(9px + env(safe-area-inset-bottom));
  pointer-events: none;
}

.weather-toggle,
.weather-tray { pointer-events: auto; }

.weather-toggle {
  display: grid;
  grid-template-columns: 12px auto 1fr;
  align-items: center;
  gap: 8px;
  width: min(100%, 430px);
  min-height: 48px;
  margin: 0 auto;
  padding: 0 13px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  color: var(--ink);
  background: var(--glass);
  backdrop-filter: blur(15px);
  text-align: left;
}

.weather-sign { width: 8px; height: 8px; border-radius: 50%; background: var(--wind); box-shadow: 0 0 12px rgba(168, 200, 160, 0.55); }
#weatherState { justify-self: end; color: var(--quiet); font-size: 11px; }

.weather-tray {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(100%, 520px);
  padding: 13px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: var(--glass-strong);
  backdrop-filter: blur(20px);
  transform: translate(-50%, 0);
  transition: opacity 280ms ease, transform 280ms ease, visibility 280ms ease;
}

.weather-shell.is-collapsed .weather-tray {
  visibility: hidden;
  opacity: 0;
  transform: translate(-50%, 14px);
  pointer-events: none;
}

.weather-heading,
.journal-heading,
.admin-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.weather-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.weather-heading-actions { display: flex; gap: 6px; }

.weather-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 11px; }

.weather-choice {
  min-width: 0;
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--edge);
  border-radius: 7px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.035);
  text-align: left;
}

.weather-choice[data-tone="rain"] { border-left: 3px solid var(--rain); }
.weather-choice[data-tone="heat"] { border-left: 3px solid var(--heat); }
.weather-choice[data-tone="wind"] { border-left: 3px solid var(--wind); }
.weather-choice[data-tone="storm"] { border-left: 3px solid var(--storm); }
.weather-choice[data-tone="snow"] { border-left: 3px solid var(--snow); }
.weather-choice[data-tone="sun"] { border-left: 3px solid var(--sun); }
.weather-choice:last-child { grid-column: 1 / -1; min-height: 52px; }
.weather-choice strong { display: block; font-size: 13px; font-weight: 500; }
.weather-choice span { display: block; margin-top: 4px; color: var(--quiet); font-size: 10px; line-height: 1.45; }
.weather-choice[aria-pressed="true"] { background: rgba(104, 135, 116, 0.17); border-top-color: rgba(220, 240, 225, 0.42); border-right-color: rgba(220, 240, 225, 0.42); border-bottom-color: rgba(220, 240, 225, 0.42); }

.speed-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(190, 219, 206, 0.13);
  color: var(--muted);
  font-size: 11px;
}

.speed-options {
  display: grid;
  grid-template-columns: repeat(3, 42px);
  gap: 4px;
}

.speed-options button {
  min-height: 34px;
  border: 1px solid var(--edge);
  border-radius: 6px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
}

.speed-options button[aria-pressed="true"] {
  color: var(--ink);
  border-color: rgba(165, 228, 193, 0.58);
  background: rgba(65, 102, 84, 0.48);
}

.weather-afterword { margin: 10px 0 0; color: var(--quiet); font-size: 10px; text-align: center; }

.journal-sheet {
  position: absolute;
  z-index: 7;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(88%, 390px);
  padding: calc(15px + env(safe-area-inset-top)) 15px calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
  background: rgba(5, 12, 16, 0.95);
  border-left: 1px solid var(--edge);
  backdrop-filter: blur(22px);
  transform: translateX(102%);
  transition: transform 320ms ease;
}

.admin-sheet {
  position: absolute;
  z-index: 8;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(94%, 420px);
  padding: calc(15px + env(safe-area-inset-top)) 15px calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
  color: var(--ink);
  background: rgba(5, 12, 16, 0.97);
  border-left: 1px solid var(--edge);
  backdrop-filter: blur(22px);
  transform: translateX(102%);
  transition: transform 320ms ease;
}

.admin-sheet.is-open { transform: translateX(0); }
.admin-heading p { margin: 0 0 2px; color: var(--quiet); font: 9px ui-monospace, Consolas, monospace; }
.admin-heading h2 { margin: 0; font-size: 18px; font-weight: 500; }

.admin-login-view,
.admin-controls-view { margin-top: 24px; }

.admin-form { display: grid; gap: 10px; }
.admin-form label { color: var(--muted); font-size: 11px; }
.admin-form input {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--edge);
  border-radius: 7px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.045);
  outline: none;
}
.admin-form input:focus { border-color: rgba(165, 228, 193, 0.62); }
.admin-form button,
.admin-footer-actions button {
  min-height: 42px;
  border: 1px solid var(--edge);
  border-radius: 7px;
  color: var(--ink);
  background: rgba(65, 102, 84, 0.42);
}
.admin-message { min-height: 18px; margin: 0; color: #dfb09c; font-size: 10px; line-height: 1.6; }

.music-current {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 0 13px;
  border-bottom: 1px solid var(--edge);
  color: var(--muted);
  font-size: 11px;
}
.music-current strong { color: var(--ink); font-weight: 500; text-align: right; }
.music-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 12px; }
.music-choice {
  min-width: 0;
  min-height: 66px;
  padding: 10px;
  border: 1px solid var(--edge);
  border-radius: 7px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.035);
  text-align: left;
}
.music-choice strong { display: block; font-size: 12px; font-weight: 500; }
.music-choice span { display: block; margin-top: 4px; color: var(--quiet); font-size: 9px; line-height: 1.45; }
.music-choice[aria-pressed="true"] {
  border-color: rgba(165, 228, 193, 0.58);
  background: rgba(65, 102, 84, 0.35);
}
.music-choice:first-child { grid-column: 1 / -1; min-height: 54px; }
.custom-track-form {
  display: grid;
  gap: 9px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--edge);
}
.custom-track-heading,
.custom-volume-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.custom-track-heading h3 { margin: 0; font-size: 13px; font-weight: 500; }
.custom-track-heading span { color: var(--quiet); font: 9px ui-monospace, Consolas, monospace; }
.custom-track-form label { color: var(--muted); font-size: 10px; }
.custom-track-form select,
.custom-track-form input[type="file"] {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--edge);
  border-radius: 7px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.045);
}
.custom-track-form input[type="file"] { padding: 7px; color: var(--quiet); font-size: 10px; }
.custom-track-form input[type="file"]::file-selector-button {
  min-height: 27px;
  margin-right: 8px;
  border: 0;
  border-radius: 5px;
  color: var(--ink);
  background: rgba(65, 102, 84, 0.54);
}
.custom-volume-line output { color: var(--ink); font: 10px ui-monospace, Consolas, monospace; }
.custom-track-form input[type="range"] { width: 100%; accent-color: var(--focus); }
.custom-track-status {
  min-width: 0;
  margin: 1px 0 0;
  overflow: hidden;
  color: var(--quiet);
  font-size: 10px;
  line-height: 1.5;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.custom-track-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.custom-track-actions button {
  min-height: 40px;
  border: 1px solid var(--edge);
  border-radius: 7px;
  color: var(--ink);
  background: rgba(65, 102, 84, 0.42);
}
.custom-track-actions button:last-child { color: var(--muted); background: transparent; }
.custom-track-actions button:disabled { opacity: 0.38; }
.custom-track-message { min-height: 16px; margin: 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.admin-footer-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 14px; }
.admin-footer-actions button { color: var(--muted); background: transparent; font-size: 10px; }

.journal-sheet.is-open { transform: translateX(0); }
.journal-heading p { margin: 0 0 2px; color: var(--quiet); font: 9px ui-monospace, Consolas, monospace; }
.journal-heading h2 { margin: 0; font-size: 18px; font-weight: 500; }

.condition-lines { margin: 22px 0 18px; border-top: 1px solid var(--edge); border-bottom: 1px solid var(--edge); }
.condition-line { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; color: var(--muted); font-size: 11px; }
.condition-line + .condition-line { border-top: 1px solid rgba(190, 219, 206, 0.1); }
.condition-line span:last-child { color: var(--ink); text-align: right; }

.journal-entries { margin: 0; padding: 0; list-style: none; }
.journal-entries li { position: relative; padding: 0 0 17px 16px; color: var(--muted); font-size: 11px; line-height: 1.7; }
.journal-entries li::before { content: ""; position: absolute; left: 1px; top: 7px; width: 5px; height: 5px; border-radius: 50%; background: rgba(165, 228, 193, 0.63); }
.journal-entries li::after { content: ""; position: absolute; left: 3px; top: 14px; bottom: 2px; width: 1px; background: var(--edge); }
.journal-entries time { display: block; margin-bottom: 2px; color: var(--quiet); font: 9px ui-monospace, Consolas, monospace; }
.journal-entries li:last-child::after { display: none; }

.change-biome {
  width: 100%;
  min-height: 42px;
  margin-top: 4px;
  border: 1px solid var(--edge);
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
}

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

@media (min-width: 760px) {
  .topbar { padding-left: 20px; padding-right: 20px; }
  .weather-shell { left: 50%; right: auto; width: min(520px, calc(100% - 28px)); transform: translateX(-50%); }
}

@media (max-width: 360px) {
  .origin-copy h2 { font-size: 19px; }
  .origin-choices span { font-size: 9px; }
  .weather-choice { min-height: 59px; padding: 8px; }
  .music-choice { min-height: 61px; padding: 8px; }
}

@media (max-height: 620px) {
  .origin-copy > p:not(.origin-mark) { margin: 9px auto 14px; line-height: 1.65; }
  .origin-mark { margin-bottom: 9px; }
  .origin-choices button { min-height: 68px; }
  .weather-choice { min-height: 56px; }
  .weather-choice:last-child { min-height: 44px; }
  .speed-control { margin-top: 7px; padding-top: 7px; }
  .music-choice { min-height: 58px; }
}

@media (prefers-reduced-motion: reduce) {
  .origin-gate,
  .weather-tray,
  .journal-sheet,
  .admin-sheet,
  .world-whisper { transition: none; }
}
