:root {
  --bg: #070614;
  --ink: #f5f3ff;
  --muted: #a9a3c9;
  --accent: #7dd3fc;
  --accent2: #c084fc;
  --gold: #fde68a;
  --danger: #fb7185;
  --ok: #86efac;
  --glass: rgba(255, 255, 255, 0.07);
  --glass-border: rgba(255, 255, 255, 0.14);
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: 'Zen Kaku Gothic New', system-ui, -apple-system, 'Hiragino Sans', sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

body { min-height: 100vh; min-height: 100dvh; background: transparent; }

/* ---- 背景 ---- */
.mesh {
  position: fixed;
  inset: -20%;
  z-index: -2;
  background:
    radial-gradient(40% 40% at 20% 20%, rgba(192, 132, 252, 0.35), transparent 60%),
    radial-gradient(35% 35% at 80% 30%, rgba(56, 189, 248, 0.28), transparent 60%),
    radial-gradient(45% 45% at 50% 90%, rgba(244, 114, 182, 0.22), transparent 60%),
    linear-gradient(160deg, #0b0820, #070614 60%);
  animation: meshDrift 22s ease-in-out infinite alternate;
}
@keyframes meshDrift {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to { transform: translate3d(3%, 2%, 0) scale(1.08); }
}
#stars {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

/* ---- 画面切り替え ---- */
.screen { min-height: 100vh; min-height: 100dvh; }
.screen.is-hidden { display: none !important; }
.screen-enter { animation: screenIn 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
@keyframes screenIn {
  from { opacity: 0; transform: scale(0.97); filter: blur(10px); }
  to { opacity: 1; transform: none; filter: none; }
}
/* ページ移動で出て行く時（navigateWithFade が is-leaving を付ける） */
.screen.is-leaving { animation: screenOut 0.35s cubic-bezier(0.4, 0, 1, 1) both; }
@keyframes screenOut {
  to { opacity: 0; transform: scale(0.985); filter: blur(8px); }
}
a.btn { text-decoration: none; }

/* ---- ヘッダー（アプリ名・設定リンク／戻るリンク） ---- */
.site-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  max-width: 880px;
  margin: 0 auto;
  padding: 16px 16px 0;
}
.site-title {
  margin: 0;
  font-family: 'Outfit', sans-serif;
  letter-spacing: 0.2em;
  font-size: 0.85rem;
  color: var(--accent);
}
.gear-link, .back-link { font-size: 0.9rem; padding: 9px 14px; }
.gear-ico { display: inline-block; transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1); }
.gear-link:hover .gear-ico { transform: rotate(90deg); }
.gear-link:active { transform: scale(0.96); }
.empty-cta { margin-top: 14px; }

/* ---- ガラスのカード ---- */
.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

/* ---- 合言葉画面 ---- */
#screen-auth {
  display: grid;
  place-items: center;
  padding: 16px;
}
.auth-card {
  width: min(420px, 100%);
  padding: 28px 24px;
  text-align: center;
}
.eyebrow {
  font-family: 'Outfit', sans-serif;
  letter-spacing: 0.3em;
  color: var(--accent);
  font-size: 0.75rem;
  margin: 0;
}
h1 { font-size: 1.5rem; margin: 6px 0 10px; }
.lead { color: var(--muted); line-height: 1.7; font-size: 0.92rem; margin: 0 0 8px; }
.auth-card .form { text-align: left; }

/* ---- フォーム（フローティングラベル） ---- */
.form { margin: 0; }
.field { position: relative; margin: 20px 0 6px; }
.field input {
  width: 100%;
  padding: 16px 14px 8px;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* iOSの自動ズーム防止 */
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  color-scheme: dark;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(125, 211, 252, 0.25);
}
.field label {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.95rem;
  padding: 0 4px;
  pointer-events: none;
  transition: all 0.2s ease;
  background: transparent;
}
.field input:focus + label,
.field input:not(:placeholder-shown) + label,
.field input[type="date"] + label {
  top: 0;
  font-size: 0.75rem;
  color: var(--accent);
  background: #120d2b;
}
.field-error { color: var(--danger); min-height: 1.3em; font-size: 0.88rem; margin: 8px 0 0; text-align: left; }
.status { min-height: 1.4em; font-size: 0.88rem; color: var(--muted); margin: 8px 0 0; }
.status[data-kind="error"] { color: var(--danger); }
.status[data-kind="ok"] { color: var(--ok); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- ボタン ---- */
.btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 14px;
  border: 0;
  font: inherit;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: transform 0.18s, box-shadow 0.18s, opacity 0.2s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn-primary {
  background: linear-gradient(135deg, #7dd3fc, #c084fc);
  color: #0b0820;
  box-shadow: 0 8px 24px rgba(192, 132, 252, 0.35);
}
.btn-ghost { background: transparent; border: 1px solid var(--glass-border); color: var(--ink); }
.btn-block { width: 100%; margin-top: 12px; }
.btn:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  transform: scale(0);
  pointer-events: none;
  animation: ripple 0.6s ease-out forwards;
}
@keyframes ripple { to { transform: scale(2.4); opacity: 0; } }

/* ---- メイン（1ページ・縦1列の中央寄せ。1024px以上はカウントと目標を横並び） ---- */
.app-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  max-width: 880px;
  margin: 0 auto;
}
.app-main > [data-panel] { display: block; }
.settings-wrap { max-width: 520px; margin: 0 auto; padding: 16px; }
.panel { padding: 20px; min-width: 0; }
.panel-title { font-size: 1.05rem; margin: 0 0 12px; }

/* パネルのスクロール時フェードイン（一度だけ。動きを減らす設定では shell.js が付けない） */
.reveal-ready [data-panel] {
  transition: opacity 0.7s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.reveal-ready [data-panel]:not(.is-revealed) {
  opacity: 0;
  transform: translateY(22px);
}
.reveal-ready [data-panel].is-revealed {
  opacity: 1;
  transform: none;
}

/* ---- カウントダウン ---- */
.empty { text-align: center; padding: 40px 12px; color: var(--muted); }
.empty-title { color: var(--ink); font-weight: 700; font-size: 1.05rem; }
.count-title { font-size: 0.95rem; color: var(--muted); font-weight: 500; margin: 0 0 6px; text-align: center; }
.days-label { text-align: center; color: var(--muted); margin: 0; font-size: 0.85rem; letter-spacing: 0.1em; }
.days {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: clamp(3.2rem, 16vw, 7rem);
  line-height: 1;
  min-height: 1em;
  margin: 6px 0 4px;
  text-shadow: 0 0 24px rgba(125, 211, 252, 0.35);
  font-variant-numeric: tabular-nums;
}
/* 桁の回転（odometer）。--d が 0〜9 の位置 */
.odo { display: inline-block; height: 1em; width: 0.6em; overflow: hidden; text-align: center; }
.strip {
  display: flex;
  flex-direction: column;
  transform: translateY(calc(var(--d, 0) * -1em));
  transition: transform 0.9s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.strip > span { display: block; height: 1em; line-height: 1em; }

.ring-box { position: relative; width: min(240px, 70vw); margin: 18px auto 0; }
.ring { width: 100%; height: auto; display: block; }
.ring-track { fill: none; stroke: rgba(255, 255, 255, 0.1); stroke-width: 8; }
.ring-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 1.6s cubic-bezier(0.2, 0.8, 0.2, 1);
  filter: drop-shadow(0 0 6px rgba(125, 211, 252, 0.6));
}
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ring-pct { font-family: 'Outfit', sans-serif; font-size: 1.9rem; font-weight: 600; margin: 0; }
.ring-caption { margin: 0; font-size: 0.75rem; color: var(--muted); }
.target-text { text-align: center; color: var(--muted); font-size: 0.9rem; margin: 14px 0 0; }

.units {
  list-style: none;
  padding: 0;
  margin: 18px 0 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
@media (min-width: 520px) { .units { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.unit-card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 12px 8px;
  text-align: center;
  animation: rise 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: calc(var(--i, 0) * 90ms);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.unit-name { display: block; color: var(--muted); font-size: 0.78rem; }
.unit-value {
  display: inline-block;
  font-family: 'Outfit', sans-serif;
  font-size: 1.35rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.tick-pulse { animation: tickPulse 0.4s ease-out; }
@keyframes tickPulse {
  from { transform: rotateX(-70deg); opacity: 0.3; }
  to { transform: none; opacity: 1; }
}
.over-msg {
  padding: 18px;
  border-radius: 16px;
  background: rgba(251, 113, 133, 0.12);
  border: 1px solid rgba(251, 113, 133, 0.4);
  text-align: center;
  font-weight: 700;
  line-height: 1.6;
  margin: 12px 0;
}

/* ---- 人生カレンダー ---- */
.cal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.cal-summary { color: var(--muted); font-family: 'Outfit', sans-serif; margin: 0; font-size: 0.9rem; }
.cal-help { color: var(--muted); font-size: 0.8rem; margin: 6px 0 12px; }
.cal-wrap { width: 100%; overflow: hidden; }
#life-canvas { display: block; margin: 0 auto; max-width: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.78rem; color: var(--muted); margin-top: 10px; }
.lg { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.lg.lived { background: #a78bfa; }
.lg.now { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.lg.future { background: rgba(255, 255, 255, 0.15); }
.tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  transform: translate(-50%, -100%);
  background: rgba(12, 10, 30, 0.92);
  border: 1px solid var(--glass-border);
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 0.82rem;
  white-space: nowrap;
}

/* ---- 目標（〇歳までに〇〇する） ---- */
.goals-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.goal-form { margin: 0 0 8px; }
.goals-empty { color: var(--muted); text-align: center; padding: 24px 12px; font-size: 0.9rem; margin: 0; }
.goals-list { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 12px; }
.goal-card {
  position: relative;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 14px;
}
.goal-card.goal-enter { animation: goalRise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.goal-card.is-done { border-color: rgba(134, 239, 172, 0.45); }
.goal-card.is-removing {
  overflow: hidden;
  opacity: 0;
  transition: height 0.35s ease, padding 0.35s ease, border-width 0.35s ease, opacity 0.25s ease;
}
.goal-body.goal-shake { animation: goalShake 0.6s ease both; }
.goal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.goal-title { margin: 0; font-size: 1rem; font-weight: 700; overflow-wrap: anywhere; }
.goal-check { width: 26px; height: 26px; flex: 0 0 auto; opacity: 0; }
.goal-check path {
  fill: none;
  stroke: var(--ok);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 24;
  stroke-dashoffset: 24;
}
.goal-card.is-done .goal-check { opacity: 1; }
.goal-card.is-done .goal-check path { animation: drawCheck 0.5s ease-out forwards; }
.goal-date { color: var(--muted); font-size: 0.85rem; margin: 6px 0 0; }
.goal-left { margin: 4px 0 0; font-family: 'Outfit', sans-serif; font-weight: 600; }
.goal-left.is-over { color: var(--danger); }
.goal-left.is-done-text { color: var(--ok); }
.goal-bar {
  height: 6px;
  margin-top: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.goal-bar-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #7dd3fc, #c084fc);
  transition: width 1.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.goal-card.is-done .goal-bar-fill { background: linear-gradient(90deg, #86efac, #7dd3fc); }
.goal-actions { display: flex; gap: 8px; margin-top: 12px; }
.goal-btn { padding: 8px 12px; font-size: 0.85rem; border-radius: 12px; }
.goal-card.is-done .goal-done-btn { border-color: var(--ok); color: var(--ok); }
.confetti {
  position: absolute;
  left: 50%;
  top: 40%;
  width: 6px;
  height: 10px;
  border-radius: 2px;
  pointer-events: none;
  animation: confettiFly 1.2s ease-out forwards;
}
@keyframes goalRise {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes goalShake {
  0%, 100% { transform: none; }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}
@keyframes drawCheck { to { stroke-dashoffset: 0; } }
@keyframes confettiFly {
  from { opacity: 1; transform: translate(-50%, -50%) rotate(0deg); }
  to { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rot)); }
}
.undo-bar {
  position: fixed;
  left: 0;
  right: 0;
  margin: 0 auto;
  bottom: calc(16px + var(--safe-b));
  z-index: 55;
  width: min(92vw, 420px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(20, 16, 44, 0.95);
  border: 1px solid var(--glass-border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  font-size: 0.9rem;
}
.undo-bar.bar-in { animation: rise 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both; }

/* ---- 人生カレンダーの目標の印・ツールチップ ---- */
.lg.goal { background: transparent; border: 1.5px solid #fde68a; }
.tip-goal { color: var(--gold); font-size: 0.78rem; white-space: normal; max-width: 260px; margin-top: 2px; }

/* ---- トースト ---- */
.toast-root {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: grid;
  gap: 8px;
  width: min(92vw, 420px);
}
.toast {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(20, 16, 44, 0.95);
  border: 1px solid var(--glass-border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  font-size: 0.9rem;
  line-height: 1.5;
  opacity: 0;
  transform: translateY(-20px);
  transition: opacity 0.3s, transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.toast.is-in { opacity: 1; transform: none; }
.toast.is-out { opacity: 0; transform: translateY(-12px); }
.toast-error { border-color: rgba(251, 113, 133, 0.6); }

/* ---- PC（768px以上）：トーストとバーを右下へ ---- */
@media (min-width: 768px) {
  .toast-root { left: auto; right: 24px; transform: none; width: min(92vw, 380px); }
  .undo-bar { bottom: 24px; }
}

/* ---- 広い画面（1024px以上）：カウントと目標を横並びにし、カレンダーは全幅 ---- */
@media (min-width: 1024px) {
  .app-main {
    max-width: 1040px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "count goals"
      "cal cal";
    align-items: start;
  }
  #panel-count { grid-area: count; }
  #panel-goals { grid-area: goals; }
  #panel-calendar { grid-area: cal; }
  .site-head { max-width: 1040px; }
}

/* ---- 動きを減らす設定 ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .strip { transition: none !important; }
  .mesh { animation: none; }
  #stars { display: none; }
}
