/* 水族館メモ */

/* フォント: Zen Maru Gothic の woff2 を assets/fonts/ に置けば優先して使う（OFL）。
   無ければ iOS の丸ゴシック（ヒラギノ丸ゴ）→ システムフォントの順。 */
@font-face {
  font-family: "Zen Maru Gothic App";
  src: local("Zen Maru Gothic"), local("ZenMaruGothic-Regular"),
       url("../assets/fonts/ZenMaruGothic-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  --font: "Zen Maru Gothic App", "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro",
          "BIZ UDPGothic", "Yu Gothic UI", system-ui, sans-serif;
  --radius-card: 18px;
  --composer-h: 56px;
  --kb: 0px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --abyss: 0;
  --veil: 0;
  --bubble-bg: #fdfeff;
  --bubble-text: #0b2e45;
  --danger: #c2334d;
}

/* ---- 時間帯のテーマ ---- */

:root[data-theme="morning"] {
  --surface: linear-gradient(180deg, #d6f3f6 0%, #8fd0e6 100%);
  --text: #0b2e45;
  --muted: #1b5a7a;
  --accent: #0b3a55;
  --on-accent: #ffffff;
  --card: rgba(255, 255, 255, .58);
  --card-border: rgba(255, 255, 255, .75);
  --card-glow: rgba(255, 255, 255, .9);
  --glass: rgba(255, 255, 255, .62);
  --ray: rgba(255, 255, 255, .55);
  --line: rgba(11, 46, 69, .22);
  --sheet: rgba(240, 250, 252, .94);
  --theme-color: #d6f3f6;
}

:root[data-theme="noon"] {
  --surface: linear-gradient(180deg, #a8ecf2 0%, #4fc3d9 50%, #1f8fb8 100%);
  --text: #0b2e45;
  --muted: #1b5a7a;
  --accent: #0b3a55;
  --on-accent: #ffffff;
  --card: rgba(255, 255, 255, .55);
  --card-border: rgba(255, 255, 255, .7);
  --card-glow: rgba(255, 255, 255, .9);
  --glass: rgba(255, 255, 255, .6);
  --ray: rgba(255, 255, 255, .5);
  --line: rgba(11, 46, 69, .25);
  --sheet: rgba(232, 248, 251, .95);
  --theme-color: #a8ecf2;
}

/* 夕: 上は明るい橙、下は暗い紫。文字は濃い紫で、カードと入力バーを明るめのすりガラスにして
   4.5:1 以上を確保する（カード合成色 ≒ #c3b7d1 に対して #2e1a3a ≒ 9:1、補助 #55305c ≒ 5:1）。 */
:root[data-theme="evening"] {
  --surface: linear-gradient(180deg, #ffe4c4 0%, #e8825e 50%, #6a4b8c 100%);
  --text: #2e1a3a;
  --muted: #55305c;
  --accent: #4a2a5e;
  --on-accent: #ffffff;
  --card: rgba(255, 255, 255, .62);
  --card-border: rgba(255, 255, 255, .78);
  --card-glow: rgba(255, 236, 214, .95);
  --glass: rgba(255, 255, 255, .66);
  --ray: rgba(255, 240, 220, .45);
  --line: rgba(46, 26, 58, .28);
  --sheet: rgba(255, 244, 236, .95);
  --theme-color: #ffe4c4;
}

:root[data-theme="night"],
:root[data-theme="deep"] {
  --surface: linear-gradient(180deg, #0b2b52 0%, #071d3d 50%, #040f26 100%);
  --text: #eaf6ff;
  --muted: #9fd7e8;
  --accent: #7ee8e0;
  --on-accent: #062038;
  --card: rgba(255, 255, 255, .08);
  --card-border: rgba(255, 255, 255, .16);
  --card-glow: rgba(126, 232, 224, .45);
  --glass: rgba(255, 255, 255, .1);
  --ray: rgba(126, 232, 224, .16);
  --line: rgba(159, 215, 232, .3);
  --sheet: rgba(8, 28, 56, .96);
  --theme-color: #071d3d;
}

/* ---- 土台 ---- */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: #071d3d;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  transition: color .6s ease;
}

button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
button { cursor: pointer; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}

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

/* ---- 海 ---- */

.ocean {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.ocean-layer {
  position: absolute;
  inset: 0;
  transition: opacity .8s ease;
}

.ocean-layer.surface { background: var(--surface); }
.ocean-layer.abyss {
  background: linear-gradient(180deg, #0a2a4f 0%, #06183a 35%, #030b20 70%, #01040d 100%);
  opacity: var(--abyss);
}
.ocean-layer.veil {
  background: #01040d;
  opacity: var(--veil);
}

.rays {
  position: absolute;
  inset: -10% -20% 30% -20%;
  opacity: calc(1 - var(--veil) * 1.4);
}

.rays span {
  position: absolute;
  top: -10%;
  width: 18%;
  height: 120%;
  background: linear-gradient(180deg, var(--ray) 0%, transparent 85%);
  filter: blur(14px);
  transform-origin: 50% 0;
  animation: ray-sway 14s ease-in-out infinite alternate;
}
.rays span:nth-child(1) { left: 12%; transform: rotate(12deg); animation-duration: 16s; }
.rays span:nth-child(2) { left: 34%; width: 10%; transform: rotate(8deg); animation-duration: 12s; animation-delay: -4s; opacity: .7; }
.rays span:nth-child(3) { left: 55%; width: 22%; transform: rotate(5deg); animation-duration: 18s; animation-delay: -9s; }
.rays span:nth-child(4) { left: 78%; width: 9%; transform: rotate(2deg); animation-duration: 13s; animation-delay: -2s; opacity: .6; }

@keyframes ray-sway {
  from { transform: rotate(14deg) translateX(-4%); opacity: .55; }
  to   { transform: rotate(4deg) translateX(4%); opacity: 1; }
}

/* ---- スクロール領域 ---- */

.scroller {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding:
    calc(var(--safe-top) + 20px)
    46px
    calc(var(--composer-h) + var(--safe-bottom) + var(--kb) + 120px)
    18px;
}

.today-head {
  padding: 8px 52px 18px 4px;
}

.depth-label {
  margin: 0 0 4px;
  font-size: 12px;
  letter-spacing: .12em;
  color: var(--muted);
}

.today-date {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: .02em;
  line-height: 1.2;
}

.today-date .weekday {
  margin-left: .4em;
  font-size: 18px;
  font-weight: 400;
  color: var(--muted);
}

.chip {
  display: inline-block;
  margin: 10px 8px 0 0;
  padding: 4px 12px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
  background: var(--glass);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.chip-btn {
  min-height: 44px;
  padding: 8px 14px;
  text-align: left;
}

/* ---- 日とカード ---- */



.day-sep {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 30px 0 14px;
  font-size: 13px;
  color: var(--muted);
}
.day-sep::before,
.day-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.day-sep span {
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  white-space: nowrap;
}
.day-sep b { font-weight: 700; color: var(--text); margin-right: .6em; }

.entries {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.card {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 12px 16px 14px;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background-color .6s ease, border-color .6s ease, box-shadow .6s ease;
}

.card time {
  display: block;
  margin-bottom: 2px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.card p {
  margin: 0;
  font-size: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.card.latest {
  box-shadow: 0 0 0 1px var(--card-glow), 0 0 22px -4px var(--card-glow);
}

.card.just-added { animation: card-in .5s ease-out; }
@keyframes card-in {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
}

.empty {
  margin: 4px 0 0;
  padding: 18px 16px;
  font-size: 14px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius-card);
}

.seabed {
  margin: 40px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .1em;
}

/* ---- 固定ボタン類 ---- */

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text);
}
.icon-btn svg { width: 22px; height: 22px; }

.settings-btn {
  position: fixed;
  z-index: 5;
  top: calc(var(--safe-top) + 16px);
  right: 16px;
}

.surface-btn {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: calc(var(--composer-h) + max(var(--safe-bottom), 12px) + var(--kb) + 14px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 14px;
  color: var(--text);
}
.surface-btn svg { width: 18px; height: 18px; }

/* ---- 入力バー ---- */

.composer {
  position: fixed;
  z-index: 6;
  left: 12px;
  right: 12px;
  bottom: calc(max(var(--safe-bottom), 12px) + var(--kb));
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-height: var(--composer-h);
  padding: 6px 6px 6px 20px;
  border-radius: 28px;
  background: var(--glass);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 6px 24px -10px rgba(0, 0, 0, .35);
}

.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 40vh;
  padding: 11px 0;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  font-size: 16px; /* 16px 未満だと iOS が拡大する */
  line-height: 1.4;
}
.composer textarea::placeholder { color: var(--muted); opacity: .9; }

.send-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  transition: opacity .2s ease, transform .15s ease;
}
.send-btn svg { width: 22px; height: 22px; }
.send-btn:disabled { opacity: .45; cursor: default; }
.send-btn:not(:disabled):active { transform: scale(.92); }

/* ---- 水深ゲージ ---- */

.gauge {
  position: fixed;
  z-index: 4;
  right: 2px;
  top: 26%;
  height: 40%;
  width: 40px;
  opacity: 0;
  transition: opacity .5s ease;
  pointer-events: none;
}
.gauge.on { opacity: 1; }

.gauge-track {
  position: absolute;
  right: 9px;
  top: 0;
  bottom: 0;
  width: 2px;
  border-radius: 2px;
  background: linear-gradient(180deg, rgba(159, 215, 232, .5), rgba(159, 215, 232, .12));
}

.gauge-ticks span {
  position: absolute;
  right: 16px;
  transform: translateY(-50%);
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.gauge-ticks span::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 50%;
  width: 5px;
  height: 1px;
  background: var(--muted);
}

.gauge-dot {
  position: absolute;
  right: 5px;
  top: 0;
  width: 10px;
  height: 10px;
  margin-top: -5px;
  border-radius: 50%;
  background: #7ee8e0;
  box-shadow: 0 0 10px 3px rgba(126, 232, 224, .7);
  transition: top .3s ease;
}

/* ---- 生き物と泡 ---- */

.stage {
  position: fixed;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  overflow: hidden;
}

.bubble-dot {
  position: absolute;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, .75);
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, .7), rgba(255, 255, 255, .08) 60%);
}

.creature {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  will-change: transform;
}

.creature img {
  display: block;
  height: auto;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .2));
}

.creature[data-motion="lurk"] img {
  filter: drop-shadow(0 0 18px rgba(255, 233, 160, .35));
}

.speech {
  position: relative;
  max-width: min(78vw, 300px);
  margin-bottom: 10px;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--bubble-bg);
  color: var(--bubble-text);
  font-size: 15px;
  line-height: 1.55;
  box-shadow: 0 6px 20px -8px rgba(0, 0, 0, .4);
  opacity: 0;
  transform: translateY(6px) scale(.96);
  transition: opacity .3s ease, transform .3s ease;
}
.speech.show { opacity: 1; transform: none; }
.speech::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  margin-left: -7px;
  border: 7px solid transparent;
  border-bottom: 0;
  border-top-color: var(--bubble-bg);
}
.speech small {
  display: block;
  font-size: 11px;
  color: #1b5a7a;
}
.creature[data-motion="peek"] .speech { font-size: 13px; }

/* ---- シート（編集・設定） ---- */

.sheet {
  width: min(100% - 24px, 460px);
  max-height: calc(100dvh - var(--safe-top) - 24px);
  margin: auto auto calc(var(--safe-bottom) + 12px);
  padding: 0;
  border: 1px solid var(--card-border);
  border-radius: 24px;
  background: var(--sheet);
  color: var(--text);
  box-shadow: 0 20px 60px -20px rgba(0, 0, 0, .6);
}
.sheet::backdrop {
  background: rgba(2, 10, 24, .45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sheet[open] { animation: sheet-up .25s ease-out; }
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } }

.sheet-body { padding: 20px; }
.sheet-title { margin: 0 0 4px; font-size: 18px; }
.sheet-sub { margin: 0 0 12px; font-size: 13px; color: var(--muted); }

.sheet textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 16px;
  line-height: 1.6;
  resize: vertical;
}

.sheet-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}
.spacer { flex: 1; }

.btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  font-size: 15px;
}
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn.ghost { background: var(--card); }
.btn.danger { color: var(--danger); border-color: currentColor; }
:root[data-theme="night"] .btn.danger,
:root[data-theme="deep"] .btn.danger { --danger: #ff9aac; }
.btn.danger.armed { background: var(--danger); color: #fff; border-color: transparent; }
:root[data-theme="night"] .btn.danger.armed,
:root[data-theme="deep"] .btn.danger.armed { color: #2a0610; }

.setting { padding: 14px 0; border-top: 1px solid var(--line); }
.setting:first-of-type { border-top: 0; }
.setting h3 { margin: 0 0 6px; font-size: 15px; }
.setting .row { display: flex; gap: 8px; flex-wrap: wrap; }
.hint { margin: 6px 0; font-size: 12px; line-height: 1.6; color: var(--muted); }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  font-size: 15px;
}
.switch-row > span { white-space: nowrap; }
.switch-row input[type="checkbox"] {
  width: 26px;
  height: 26px;
  accent-color: var(--accent);
}
.switch-row select {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 16px;
}

/* ---- トースト ---- */

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  top: calc(var(--safe-top) + 16px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--bubble-bg);
  color: var(--bubble-text);
  font-size: 14px;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .5);
}

/* ---- 動きを止める ---- */

@media (prefers-reduced-motion: reduce) {
  .rays span { animation: none; }
  .card.just-added, .sheet[open] { animation: none; }
  .speech, .ocean-layer, .gauge-dot, body { transition: none; }
}
:root.reduce-motion .rays span { animation: none; }
:root.reduce-motion .card.just-added,
:root.reduce-motion .sheet[open] { animation: none; }
:root.reduce-motion .speech,
:root.reduce-motion .ocean-layer,
:root.reduce-motion .gauge-dot,
:root.reduce-motion body { transition: none; }
