/* ==========================================================
   シュウチュウチュウ — スマホ縦画面（320〜430px）最優先
   ========================================================== */
:root {
  --bg: #0e1020;
  --panel: #1a1d33;
  --panel-2: #23274a;
  --line: #333a66;
  --text: #eef0ff;
  --muted: #9aa0c3;
  --accent: #7c8cff;
  --accent-deep: #5a67d8;
  --danger: #e07a7a;
  --madam: #d98cc0;
  --cat: #f2b04e;
  --rocket: #5ad0f0;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", sans-serif;
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  touch-action: manipulation;   /* ダブルタップ拡大の防止 */
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

/* ---------- 画面切り替え ---------- */
.screen {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  flex-direction: column;
}
.screen.active { display: flex; }

.scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: max(16px, env(safe-area-inset-top)) 16px 120px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

/* ---------- 下部固定バー ---------- */
.bottom-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(14,16,32,0.98) 65%, rgba(14,16,32,0));
  display: flex;
  gap: 10px;
  max-width: 480px;
  margin: 0 auto;
}
.bottom-bar > button { flex: 1; }

/* ---------- ボタン ---------- */
button {
  font-family: inherit;
  font-size: 16px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  min-height: 48px;
  color: var(--text);
  transition: transform 0.08s ease;
}
button:active { transform: scale(0.96); }
@media (prefers-reduced-motion: reduce) {
  button:active { transform: none; }
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  font-weight: bold;
  padding: 14px 20px;
  box-shadow: 0 4px 18px rgba(124, 140, 255, 0.35);
}
.btn-primary:disabled {
  background: var(--panel-2);
  color: var(--muted);
  box-shadow: none;
}
.btn-secondary {
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 12px 18px;
}
.btn-quiet {
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  min-height: 44px;
  padding: 10px 16px;
}
.btn-icon {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 44px; height: 44px;
  min-height: 44px;
  font-size: 18px;
  flex-shrink: 0;
}

/* ---------- 共通カード ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { font-size: 16px; margin: 0 0 8px; }
.note { color: var(--muted); font-size: 13px; margin: 0 0 8px; }
.card-accent { border-color: var(--accent); background: linear-gradient(180deg, rgba(124,140,255,0.10), var(--panel)); }
.card-accent .note { color: var(--text); opacity: 0.9; margin: 0; }
.submeta { color: var(--muted); font-size: 12px; margin: -10px 0 16px; text-align: center; }
.feature-list { margin: 0; padding-left: 18px; font-size: 14px; }
.feature-list li { margin-bottom: 8px; }
.feature-list-plain { list-style: none; padding-left: 2px; font-size: 15px; }
.feature-list-plain li { margin-bottom: 12px; }
.feature-list-plain li:last-child { margin-bottom: 0; }
details { font-size: 14px; margin-top: 8px; }
summary {
  cursor: pointer;
  padding: 10px 4px;
  font-weight: bold;
  min-height: 44px;
  display: flex;
  align-items: center;
}
details ol { margin: 4px 0 10px; padding-left: 22px; }
details li { margin-bottom: 6px; }

/* ---------- 初回案内 ---------- */
.guide-hero { text-align: center; padding: 12px 0 20px; }
.guide-hero h1 { font-size: 22px; margin: 12px 0 4px; }
.tagline { color: var(--muted); font-size: 14px; margin: 0 0 18px; text-align: center; }

/* ---------- ホーム ---------- */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.home-header h1 { font-size: 20px; margin: 8px 0; }

.btn-install {
  width: 100%;
  margin-bottom: 12px;
  border-color: var(--accent);
  color: var(--text);
}

.quick-start {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: linear-gradient(135deg, rgba(124,140,255,0.22), rgba(90,103,216,0.14));
  border: 1.5px solid var(--accent);
  border-radius: 18px;
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: 0 4px 18px rgba(124, 140, 255, 0.18);
}
.quick-start-icon { font-size: 30px; flex-shrink: 0; }
.quick-start-text { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.quick-start-label { font-size: 12px; color: var(--muted); }
.quick-start-mode { font-size: 16px; font-weight: bold; }
.quick-start-arrow { font-size: 24px; color: var(--accent); flex-shrink: 0; }

.home-stats {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.stat-chip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--muted);
}
.stat-chip b { color: var(--text); }

.notif-card { margin-top: 14px; }
.notif-card #push-status { margin: 8px 0 0; font-size: 12px; }
.notif-card #push-status.on { color: var(--accent); }

.notif-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.notif-details { font-size: 13px; }
.notif-details summary { min-height: 36px; padding: 4px 2px; color: var(--muted); font-weight: normal; }
.notif-head h2 { margin: 0 0 6px; }
.notif-headtext { flex: 1; min-width: 0; }

.notif-icon {
  position: relative;
  flex-shrink: 0;
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  color: var(--muted);
  transition: color 0.15s, background 0.15s;
}
.notif-icon .bell-slash { display: none; }
.notif-icon.off .bell-slash { display: block; }
.notif-icon.off .bell-body,
.notif-icon.off .bell-clapper { opacity: 0.45; }
.notif-icon.on {
  color: var(--accent);
  background: rgba(124, 140, 255, 0.16);
}
.notif-icon .notif-dot {
  position: absolute;
  top: 4px; right: 4px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #4caf7d;
  border: 2px solid var(--panel);
  display: none;
}
.notif-icon.on .notif-dot { display: block; }

#row-push #push-toggle-label { font-weight: bold; }
.notif-card #row-push { background: transparent; border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px; }
.notif-card #row-push + p { padding: 0 2px; }

.mode-cards { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.mode-card {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  min-height: 88px;
  transition: border-color 0.15s, background 0.15s;
}
.mode-card[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--panel-2);
}
.mode-thumb {
  width: 58px; height: 58px;
  border-radius: 14px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
}
.mode-thumb-madam { background: rgba(217, 140, 192, 0.16); }
.mode-thumb-madam::before { content: "👒"; }
.mode-thumb-cat { background: rgba(242, 176, 78, 0.16); }
.mode-thumb-cat::before { content: "🐱"; }
.mode-thumb-rocket { background: rgba(90, 208, 240, 0.16); }
.mode-thumb-rocket::before { content: "🚀"; }
.mode-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.mode-name { font-weight: bold; font-size: 16px; }
.mode-catch { font-size: 13px; color: var(--text); opacity: 0.85; }
.mode-desc { font-size: 12px; color: var(--muted); }
.mode-check {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  flex-shrink: 0;
}
.mode-card[aria-checked="true"] .mode-check { display: flex; }

.toggles {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 4px 16px;
  margin-bottom: 12px;
}
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  font-size: 15px;
  cursor: pointer;
}
.toggle-row + .toggle-row { border-top: 1px solid var(--line); }

/* iOS風トグル */
.toggle {
  appearance: none;
  -webkit-appearance: none;
  width: 52px; height: 32px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}
.toggle:checked { background: var(--accent); }
.toggle:checked::after { transform: translateX(20px); }

/* ---------- 集中画面 ---------- */
#screen-focus { background: #090a14; }
.focus-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: max(20px, env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}
.stage {
  width: 100%;
  max-width: 340px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  max-height: 300px;
}
.stage svg { width: 100%; height: 100%; max-height: 300px; }

.time-block { position: relative; text-align: center; padding: 8px 0 16px; }
.time-ring {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(78vw, 300px);
  height: min(78vw, 300px);
  transform-origin: center;
  pointer-events: none;
}
.time-ring-bg, .time-ring-fg {
  fill: none;
  stroke-width: 6;
}
.time-ring-bg { stroke: rgba(255,255,255,0.08); }
.time-ring-fg {
  stroke: var(--accent);
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 100px 100px;
  transition: stroke-dashoffset 0.25s linear;
}
.time-label { position: relative; color: var(--muted); font-size: 15px; }
.time {
  position: relative;
  font-size: clamp(56px, 20vw, 84px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
  line-height: 1.1;
}
.time.paused { opacity: 0.4; }
.session-info { position: relative; color: var(--muted); font-size: 14px; margin-top: 6px; }

.focus-controls {
  display: flex;
  gap: 10px;
  width: 100%;
  justify-content: center;
  align-items: center;
}
.focus-controls .btn-secondary { flex: 1; max-width: 150px; }

.sound-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.sound-btn .sound-icon { font-size: 16px; }
.sound-btn[aria-pressed="true"] {
  background: rgba(76, 175, 125, 0.18);
  border-color: #4caf7d;
  color: #d7ffe9;
}
.sound-btn[aria-pressed="false"] {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--muted);
}

.btn-preview { width: 100%; margin: 4px 0 16px; }
.wake-note {
  color: var(--muted);
  opacity: 0.7;
  font-size: 11px;
  margin: 10px 0 0;
  text-align: center;
  min-height: 1em;
  transition: opacity 0.6s;
}

/* ---------- 置き時計モード（無操作30秒で減光） ---------- */
#screen-focus.dimmed { background: #000; transition: background 0.8s; }
#screen-focus.dimmed .stage,
#screen-focus.dimmed .focus-controls,
#screen-focus.dimmed .session-info,
#screen-focus.dimmed .wake-note,
#screen-focus.dimmed .time-ring,
#screen-focus.dimmed .time-label {
  opacity: 0;
  transition: opacity 0.8s;
}
#screen-focus.dimmed .time {
  opacity: 0.5;
  font-weight: 300;
  transition: opacity 0.8s;
}
#screen-focus .stage,
#screen-focus .focus-controls,
#screen-focus .session-info,
#screen-focus .time-label {
  transition: opacity 0.4s;
}

/* ---------- オーバーレイ共通 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(9, 10, 20, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.overlay[hidden] { display: none; }

.dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px 20px;
  text-align: center;
  max-width: 340px;
  width: 100%;
}
.dialog p { margin: 0 0 18px; font-size: 15px; }
.dialog-buttons { display: flex; flex-direction: column; gap: 10px; }

/* ---------- 励ましオーバーレイ ---------- */
#overlay-encourage { flex-direction: column; }
#overlay-encourage.mode-madam { background: radial-gradient(circle at 50% 30%, #2b1e33 0%, #0e0a16 70%); }
#overlay-encourage.mode-cat { background: radial-gradient(circle at 50% 30%, #2e2414 0%, #120d06 70%); }
#overlay-encourage.mode-rocket { background: radial-gradient(circle at 50% 90%, #0d2438 0%, #05070f 70%); }

.enc-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.enc-stage {
  width: 100%;
  max-width: 300px;
  height: 42vh;
  max-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.enc-stage svg { width: 100%; height: 100%; }

.enc-msg {
  font-size: 21px;
  font-weight: bold;
  line-height: 1.7;
  margin: 0;
  min-height: 2em;
  animation: msg-in 0.8s ease both;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.enc-countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 120px;
  font-weight: 800;
  color: var(--rocket);
  text-shadow: 0 0 40px rgba(90, 208, 240, 0.6);
  background: rgba(5, 7, 15, 0.85);
  z-index: 5;
}
.enc-countdown[hidden] { display: none; }

.enc-progress {
  width: 60%;
  max-width: 220px;
  height: 4px;
  border-radius: 4px;
  background: rgba(255,255,255,0.15);
  overflow: hidden;
}
.enc-progress-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: left;
}
.enc-progress-fill.running {
  animation: enc-progress linear both;
}
@keyframes enc-progress {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* 登場アニメーション（モード別） */
.enc-stage.appear-madam svg { animation: appear-madam 1.6s ease both; }
@keyframes appear-madam {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
.enc-stage.appear-cat svg { animation: appear-cat 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
@keyframes appear-cat {
  from { opacity: 0; transform: translateY(60px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 記録画面 ---------- */
.result-title { font-size: 22px; text-align: center; margin: 20px 0 8px; }
.result-char {
  width: 170px;
  height: 150px;
  margin: 0 auto;
}
.result-char svg { width: 100%; height: 100%; }
.result-praise {
  text-align: center;
  font-size: 17px;
  font-weight: bold;
  margin: 4px 0 18px;
  line-height: 1.7;
}
.result-stats { font-size: 15px; }
.result-stats .stat-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 4px;
}
.result-stats .stat-row + .stat-row { border-top: 1px solid var(--line); }
.result-stats .stat-row b { font-variant-numeric: tabular-nums; }
.bottom-bar-double .btn-secondary { flex: 1; }
.bottom-bar-double .btn-primary { flex: 1.4; }

/* ---------- トースト ---------- */
.toast {
  position: fixed;
  bottom: calc(100px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 14px;
  z-index: 200;
  white-space: nowrap;
}

/* ==========================================================
   キャラクター（SVG）アニメーション
   ========================================================== */

/* --- 共通：呼吸 --- */
.breath { animation: breath 4s ease-in-out infinite; transform-origin: center 80%; }
@keyframes breath {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(1.02); }
}

/* --- 猫 --- */
.cat-tail {
  animation: tail-sway 3.2s ease-in-out infinite;
  transform-origin: 148px 136px;
}
@keyframes tail-sway {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(14deg); }
}
.cat-ear-r {
  animation: ear-twitch 7s ease-in-out infinite;
  transform-origin: 122px 40px;
}
@keyframes ear-twitch {
  0%, 90%, 100% { transform: rotate(0deg); }
  92% { transform: rotate(-10deg); }
  95% { transform: rotate(4deg); }
  97% { transform: rotate(0deg); }
}
.cat-eyes { animation: blink 5.5s infinite; transform-origin: 100px 68px; }
@keyframes blink {
  0%, 93%, 100% { transform: scaleY(1); }
  95%, 97% { transform: scaleY(0.08); }
}

/* --- マダム --- */
.madam-body { animation: madam-sway 5s ease-in-out infinite; transform-origin: 100px 160px; }
@keyframes madam-sway {
  0%, 100% { transform: rotate(-0.8deg); }
  50% { transform: rotate(0.8deg); }
}
.steam {
  animation: steam-rise 3s ease-in-out infinite;
  opacity: 0;
}
.steam.s2 { animation-delay: 1.5s; }
@keyframes steam-rise {
  0% { opacity: 0; transform: translateY(0); }
  30% { opacity: 0.7; }
  100% { opacity: 0; transform: translateY(-14px); }
}

/* --- ロケット --- */
.star { animation: twinkle 2.6s ease-in-out infinite; }
.star.st2 { animation-delay: 0.9s; }
.star.st3 { animation-delay: 1.7s; }
@keyframes twinkle {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}
.rocket-idle { animation: rocket-hum 2s ease-in-out infinite; }
@keyframes rocket-hum {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-1.5px); }
}
.rocket-flame { opacity: 0; }

/* 発射！ */
.launching .rocket-group {
  animation: rocket-launch 2.2s cubic-bezier(0.55, 0, 0.85, 0.4) 0.1s both;
}
@keyframes rocket-launch {
  0% { transform: translateY(0); }
  20% { transform: translateY(-2px); }
  100% { transform: translateY(-260px); }
}
.launching .rocket-flame {
  opacity: 1;
  animation: flame-flicker 0.12s linear infinite;
  transform-origin: 100px 118px;
}
@keyframes flame-flicker {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(1.35); }
}
.launching.enc-stage { animation: launch-shake 0.4s linear 2; }
@keyframes launch-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* ---------- アクセシビリティ ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  /* 自動クローズの進行表示だけは残す（時間が分かるように） */
  .enc-progress-fill.running { animation-duration: inherit !important; }
}

/* ---------- 小さい端末（320px）調整 ---------- */
@media (max-width: 350px) {
  .time { font-size: 52px; }
  .mode-card { padding: 10px; min-height: 80px; }
  .enc-msg { font-size: 18px; }
}
