/* ═══════════════ デザイントークン ═══════════════
   色はライト値をそのまま持ち、ダーク値は "-dark" 接尾辞の変数として
   :root に一度だけ定義する。実際にダークを有効化する2つの入口
   （手動設定 [data-theme="dark"] と OS設定 prefers-color-scheme）は
   どちらもその値を var() で参照するだけにして、色の実体が複数箇所に
   コピーされないようにしている（直し忘れによる色ズレを防ぐため）。 */
:root {
  --bg: #f2f6f6;
  --card: #ffffff;
  --text: #10221f;
  --muted: #4f6360;
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --primary-deep: #115e59;
  --danger: #e11d48;
  --accent: #f59e0b;
  --special: #8b5cf6;
  --border: #e3ebea;
  --shadow: 0 1px 2px rgba(16, 34, 31, .05), 0 4px 16px rgba(16, 34, 31, .06);
  --radius: 20px;
  --nav-h: 62px;
  --toast-bg: #10221f;
  --toast-fg: #f2f6f6;
  --hint-warn: #b45309;

  /* 余白スケール（この単位の倍数だけを使うことで、画面全体の余白のリズムを揃える） */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;

  /* 角丸スケール（小さい部品ほど小さい角丸、大きい面ほど大きい角丸） */
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 24px;
  --radius-pill: 99px;

  /* ダーク値（実体はここだけ。参照は下の2箇所から） */
  --bg-dark: #0c1222;
  --card-dark: #131b30;
  --text-dark: #e4eae9;
  --muted-dark: #8fa3a0;
  --primary-a-dark: #2dd4bf;
  --primary-dark-a-dark: #14b8a6;
  --primary-deep-dark: #0f766e;
  --danger-dark: #fb7185;
  --border-dark: #22304d;
  --shadow-dark: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .35);
  --toast-bg-dark: #e4eae9;
  --toast-fg-dark: #0c1222;
  --hint-warn-dark: #fcd34d;
}
:root[data-theme="dark"] {
  --bg: var(--bg-dark);
  --card: var(--card-dark);
  --text: var(--text-dark);
  --muted: var(--muted-dark);
  --primary: var(--primary-a-dark);
  --primary-dark: var(--primary-dark-a-dark);
  --primary-deep: var(--primary-deep-dark);
  --danger: var(--danger-dark);
  --border: var(--border-dark);
  --shadow: var(--shadow-dark);
  --toast-bg: var(--toast-bg-dark);
  --toast-fg: var(--toast-fg-dark);
  --hint-warn: var(--hint-warn-dark);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: var(--bg-dark);
    --card: var(--card-dark);
    --text: var(--text-dark);
    --muted: var(--muted-dark);
    --primary: var(--primary-a-dark);
    --primary-dark: var(--primary-dark-a-dark);
    --primary-deep: var(--primary-deep-dark);
    --danger: var(--danger-dark);
    --border: var(--border-dark);
    --shadow: var(--shadow-dark);
    --toast-bg: var(--toast-bg-dark);
    --toast-fg: var(--toast-fg-dark);
    --hint-warn: var(--hint-warn-dark);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* hidden属性は、要素側で display を明示的に指定しているクラス（.field など）
   があると打ち消されてしまうため、ここで確実に優先させる */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", "Segoe UI", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font-family: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--primary); outline-offset: 2px; border-radius: 6px; }

/* キーボード操作の人が下タブまでTabキーを連打しなくて済むようにする */
.skip-link {
  position: fixed; top: -60px; left: 12px; z-index: 300;
  background: var(--primary); color: #fff; font-weight: 700; font-size: .9rem;
  padding: 10px 18px; border-radius: var(--radius-sm); text-decoration: none;
  transition: top .15s;
}
.skip-link:focus-visible { top: 12px; }

#app {
  max-width: 560px; margin: 0 auto;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 16px);
}

/* ═══════════════ ヘッダー ═══════════════ */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 20px 8px;
}
.app-header h1 { font-size: 1.25rem; font-weight: 800; letter-spacing: .01em; }
.icon-btn {
  background: none; border: none; cursor: pointer; font-size: 1.25rem;
  padding: var(--sp-2); border-radius: var(--radius-md); line-height: 1; min-width: 42px; min-height: 42px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--border); }
.icon-btn .ui-icon { width: 21px; height: 21px; }

main { padding: 4px 16px 8px; }
.view { display: none; animation: fade .28s; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); margin-bottom: 14px; border: 1px solid var(--border);
}
.card h2 { font-size: 1.02rem; margin-bottom: 14px; font-weight: 700; }

.greeting { font-size: .9rem; color: var(--muted); font-weight: 600; padding: 2px 6px 10px; }

/* ═══════════════ ヒーロー（リング＋肝臓） ═══════════════ */
.hero {
  background:
    radial-gradient(120% 90% at 15% 0%, rgba(255, 255, 255, .14), transparent 55%),
    linear-gradient(140deg, var(--primary-dark), var(--primary-deep) 65%, #134e4a);
  color: #fff; border: none;
}
.hero-top { display: flex; align-items: center; gap: 10px; }
.ring-wrap { position: relative; flex: none; width: 172px; height: 172px; cursor: pointer; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(255, 255, 255, .18); stroke-width: 11; }
.ring-fg {
  fill: none; stroke: url(#ringGrad); stroke-width: 11; stroke-linecap: round;
  stroke-dasharray: 540.35; stroke-dashoffset: 540.35;
  transition: stroke-dashoffset .9s cubic-bezier(.22, 1, .36, 1);
}
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; gap: 0;
}
.ring-label { font-size: .72rem; opacity: .8; }
.ring-days b { font-size: 3rem; font-weight: 800; line-height: 1.05; }
.ring-days i { font-style: normal; font-size: 1.05rem; font-weight: 700; margin-left: 3px; }
.ring-sub { font-size: .66rem; opacity: .85; max-width: 110px; line-height: 1.4; }

.hero-side { flex: 1; text-align: center; min-width: 0; }
.liver-svg {
  width: 92px; height: 77px; display: block; margin: 0 auto;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .3));
}
.liver-svg #liverBody { transition: fill .6s ease; }
.liver-caption { font-size: .72rem; opacity: .95; margin-top: 2px; line-height: 1.35; }
.liver-caption b { font-size: .95rem; font-weight: 800; }
.liver-note { font-size: .6rem; opacity: .55; }
.liver-visual { position: relative; display: inline-block; }
#heroSide:not(.liver-seen) .liver-svg { animation: liverTapPulse 1.4s ease-in-out infinite; }
.liver-tap-btn {
  position: absolute; inset: 0; background: none; border: none; padding: 0; margin: 0;
  cursor: pointer; display: block;
}
.liver-tap-label {
  position: absolute; right: -6px; bottom: 4px;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: .58rem; font-weight: 700;
  padding: 2px 7px; border-radius: 99px; line-height: 1.3; letter-spacing: .02em;
  pointer-events: none; white-space: nowrap;
}
#heroSide.liver-seen .liver-tap-label { display: none; }
@keyframes liverTapPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.16); }
}
.liver-info-btn {
  display: none; background: none; border: none;
  font-size: inherit; font-family: inherit; line-height: 1; color: inherit; opacity: .7;
  cursor: pointer; vertical-align: middle;
  padding: 8px; margin: -8px -8px -8px -4px;
}
.liver-info-btn:hover, .liver-info-btn:active { opacity: 1; }
#heroSide.liver-seen .liver-info-btn { display: inline-block; }

.hero-chips { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.chip {
  background: rgba(255, 255, 255, .14); border-radius: var(--radius-pill); padding: 5px 13px;
  font-size: .78rem;
}
.chip b { font-size: .95rem; font-weight: 800; }
.hero-start { text-align: center; font-size: .78rem; opacity: .8; margin-top: 10px; }

/* 直近7日ストリップ */
.week-strip { display: flex; gap: 6px; margin-top: 14px; }
.ws-day {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: rgba(255, 255, 255, .1); border: none; border-radius: 12px;
  padding: 7px 0 6px; cursor: pointer; color: #fff; transition: transform .12s, background .15s;
}
.ws-day:active { transform: scale(.93); }
.ws-day:hover { background: rgba(255, 255, 255, .18); }
.ws-day .ws-dow { font-size: .62rem; opacity: .75; }
.ws-day .ws-date { font-size: .68rem; font-weight: 600; opacity: .92; }
.ws-day .ws-icon { font-size: 1.02rem; line-height: 1.25; }
.ws-day.faint .ws-icon { opacity: .45; }
.ws-day.today { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .75); background: rgba(255, 255, 255, .18); }
.ws-day.relapse { background: rgba(225, 29, 72, .35); }
.ws-day.exception { background: color-mix(in srgb, var(--special) 35%, transparent); }

/* ═══════════════ ボタン ═══════════════ */
.btn {
  padding: 13px var(--sp-4); border: 1px solid var(--border); border-radius: var(--radius-md); cursor: pointer;
  font-size: .95rem; font-weight: 700; background: var(--card); color: var(--text);
  transition: transform .12s, filter .15s;
}
.btn:hover { filter: brightness(.97); }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-lg { width: 100%; padding: var(--sp-4); font-size: 1.05rem; border-radius: var(--radius-md); box-shadow: var(--shadow); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-quiet {
  display: block; margin: 10px auto 16px; background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: .84rem; text-decoration: underline; padding: 6px 10px;
}
.btn-link-danger {
  display: block; margin: 16px auto 4px; background: none; color: var(--danger); border: none;
  text-decoration: underline; font-size: .85rem; padding: 6px; cursor: pointer;
}

/* ═══════════════ 目標 ═══════════════ */
.goal-card .goal-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.goal-card .goal-title { font-weight: 700; }
.goal-card .goal-count { font-size: .9rem; color: var(--muted); }
.goal-card .goal-count b { color: var(--primary); font-size: 1.1rem; }
.goal-sub { font-size: .82rem; color: var(--muted); margin-top: 8px; }
.goal-card.reached { border: 1.5px solid var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--card)); }
.goal-card.reached .progress > i { background: var(--accent); }
.progress { height: 9px; background: var(--border); border-radius: var(--radius-pill); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--primary); border-radius: var(--radius-pill); transition: width .6s ease; }

/* ═══════════════ 統計カード ═══════════════ */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.stat { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 16px 10px; margin-bottom: 0; }
.stat-emoji { display: block; width: 26px; height: 26px; color: var(--primary); }
.stat-num { font-size: 1.3rem; font-weight: 800; }
.stat-cap { font-size: .74rem; color: var(--muted); }

/* ═══════════════ AIアドバイス ═══════════════ */
.advice-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.advice-avatar {
  flex: none; width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 1.35rem;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff;
}
.advice-titles { flex: 1; display: flex; flex-direction: column; line-height: 1.25; }
.advice-title { font-weight: 700; font-size: 1rem; }
.advice-sub { font-size: .74rem; color: var(--muted); }
.advice-refresh {
  flex: none; background: var(--bg); border: 1px solid var(--border); cursor: pointer;
  width: 44px; height: 44px; border-radius: 12px; font-size: 1.05rem;
  transition: transform .12s;
}
.advice-refresh:active { transform: scale(.93); }
.advice-refresh.spin { animation: spin .5s ease; }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
.advice-body { white-space: pre-line; font-size: .93rem; line-height: 1.8; }
.advice-note {
  font-size: .76rem; color: var(--muted); line-height: 1.6; margin-top: 14px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.liver-info-body { white-space: pre-line; text-align: left; font-size: .85rem; }

/* ═══════════════ タロット（めくり） ═══════════════ */
.fortune-card {
  background:
    radial-gradient(100% 80% at 80% 0%, rgba(255, 255, 255, .1), transparent 50%),
    linear-gradient(160deg, #2a1a4a, #4c1d95 60%, #6d28d9);
  color: #f5f3ff; border: 1px solid rgba(255, 255, 255, .12);
}
.fortune-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; }
.fortune-title { font-weight: 700; }
.fortune-date { font-size: .78rem; opacity: .75; }
.flip-stage { display: flex; gap: 16px; align-items: center; }
.flip {
  flex: none; width: 92px; height: 130px; position: relative; cursor: pointer;
  background: none; border: none; perspective: 700px; padding: 0;
  transform-style: preserve-3d; transition: transform .8s cubic-bezier(.3, 1.2, .4, 1);
}
.flip.flipped { transform: rotateY(180deg); cursor: default; }
.flip.shuffling { animation: tarotShuffle .42s ease-in-out; pointer-events: none; }
@keyframes tarotShuffle {
  0% { transform: translateX(0) rotate(0deg); }
  15% { transform: translateX(-7px) rotate(-5deg); }
  30% { transform: translateX(6px) rotate(4deg); }
  45% { transform: translateX(-5px) rotate(-3deg); }
  60% { transform: translateX(4px) rotate(3deg); }
  75% { transform: translateX(-2px) rotate(-1deg); }
  100% { transform: translateX(0) rotate(0deg); }
}
.flip-face {
  position: absolute; inset: 0; border-radius: 12px; backface-visibility: hidden;
  -webkit-backface-visibility: hidden; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .35);
}
.flip-back {
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .06) 0 8px, transparent 8px 16px),
    linear-gradient(160deg, #312e81, #4338ca);
  border: 2px solid rgba(255, 255, 255, .35);
  overflow: hidden;
}
.flip-back::after {
  content: ""; position: absolute; top: 0; left: -60%; width: 45%; height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .65), transparent);
  transform: skewX(-20deg); opacity: 0; pointer-events: none;
}
.flip.shuffling .flip-back::after { animation: tarotGlint .42s ease-in-out; }
@keyframes tarotGlint {
  0% { left: -60%; opacity: 0; }
  40% { opacity: 1; }
  100% { left: 130%; opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .flip.shuffling, .flip.shuffling .flip-back::after { animation: none !important; }
}
.flip-back-star { font-size: 1.9rem; color: #fde047; animation: twinkle 1.8s ease-in-out infinite; }
@keyframes twinkle { 0%, 100% { opacity: .6; transform: scale(1); } 50% { opacity: 1; transform: scale(1.18); } }
.flip-back-text { font-size: .68rem; color: rgba(255, 255, 255, .85); }
.flip-front { transform: rotateY(180deg); }
.tarot {
  width: 100%; height: 100%; border-radius: 12px;
  background: radial-gradient(circle at 50% 30%, #fef3c7, #fde68a 45%, #f59e0b);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative; color: #4c1d95;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .5);
}
.tarot::before { content: ""; position: absolute; inset: 5px; border-radius: 8px; border: 1px solid rgba(76, 29, 149, .4); }
.tarot.reversed .tarot-emoji { transform: rotate(180deg); }
.tarot-emoji { font-size: 2.7rem; line-height: 1; }
.tarot-num { position: absolute; top: 7px; left: 10px; font-size: .7rem; font-weight: 700; opacity: .7; }

/* 大アルカナ（大吉時を除く）: 星座エングレービング風の線画アイコン＋金グラデーション */
.tarot.major {
  background:
    linear-gradient(135deg, rgba(232, 180, 92, .36) 0%, rgba(232, 180, 92, 0) 60%),
    radial-gradient(120% 90% at 50% 8%, #1d2454, #0c0f26 72%);
  box-shadow: inset 0 0 0 2px rgba(232, 180, 92, .35), 0 2px 10px rgba(6, 8, 24, .35);
}
.tarot.major::before { border-color: rgba(232, 180, 92, .28); }
.tarot.major .tarot-num { color: #f3e6ae; opacity: .85; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.tarot-emoji svg { width: 56px; height: 56px; display: block; }
.fortune-info { flex: 1; min-width: 0; }
.fortune-name { font-size: 1.12rem; font-weight: 800; }
.fortune-name .orient { font-size: .76rem; font-weight: 600; opacity: .8; margin-left: 6px; white-space: nowrap; }
.fortune-stars { color: #fde047; font-size: .95rem; letter-spacing: 2px; margin: 2px 0; }
.fortune-meaning { font-size: .86rem; opacity: .92; }
.fortune-detail { animation: fade .4s; }
.fortune-advice { font-size: .9rem; margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .15); }
.fortune-lucky { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.fortune-lucky .luck {
  font-size: .76rem; background: rgba(255, 255, 255, .12); padding: 5px 10px; border-radius: 99px;
  display: inline-flex; align-items: center; gap: 6px;
}
.fortune-lucky .swatch { width: 11px; height: 11px; border-radius: 50%; display: inline-block; box-shadow: 0 0 0 1px rgba(255, 255, 255, .5); }
.fortune-note { font-size: .7rem; opacity: .6; margin-top: 12px; text-align: right; }

/* ═══════════════ 記録画面 ═══════════════ */
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.field-label { font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
.field input[type="date"], .field input[type="number"], .field input[type="time"], .field input[type="text"], .field select, textarea {
  width: 100%; padding: 12px; border: 1.5px solid var(--border);
  border-radius: var(--radius-md); font-size: 1rem; background: var(--bg); color: var(--text);
  font-family: inherit;
}
/* 他のセグメントコントロールと見た目を揃えるため、ブラウザ標準の矢印を
   自作の矢印アイコンに差し替え、太字・カーソルポインタなどを統一する */
.field select {
  appearance: none; -webkit-appearance: none; font-weight: 700; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234f6360' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px;
  padding-right: 40px;
}
:root[data-theme="dark"] .field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238fa3a0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) .field select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238fa3a0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  }
}
.field input[type="range"] { width: 100%; accent-color: var(--primary); }
.field output { font-size: .85rem; color: var(--primary); font-weight: 700; }
textarea { min-height: 84px; resize: vertical; margin-bottom: 12px; }

.mood-row { display: flex; justify-content: space-between; margin-bottom: 18px; }
.mood {
  font-size: 1.9rem; background: none; border: none; cursor: pointer;
  opacity: .4; transition: transform .15s, opacity .15s; padding: 7px; border-radius: 14px;
  min-width: 48px; min-height: 48px;
}
.mood:hover { opacity: .8; }
.mood.selected { opacity: 1; transform: scale(1.18); background: var(--bg); }

.trigger-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.trigger {
  border: 1.5px solid var(--border); background: var(--bg); border-radius: var(--radius-pill);
  padding: 8px 14px; font-size: .84rem; cursor: pointer; transition: .15s;
}
.trigger.selected { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 14%, var(--bg)); color: var(--primary); font-weight: 700; }

.today-summary { display: flex; align-items: center; gap: 12px; }
.today-summary .ts-emoji { font-size: 2rem; }
.today-summary .ts-text { flex: 1; font-size: .9rem; }
.today-summary .ts-sub { font-size: .78rem; color: var(--muted); }

.log-list { display: flex; flex-direction: column; gap: 10px; }
.log-item {
  display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%;
  padding: 13px; border: 1px solid var(--border); border-radius: 14px;
  background: none; cursor: pointer; font-size: 1rem; transition: .15s;
}
.log-item:hover { background: var(--bg); }
.log-item .li-emoji { font-size: 1.5rem; }
.log-item .li-body { flex: 1; min-width: 0; }
.log-item .li-date { font-size: .78rem; color: var(--muted); }
.log-item .li-note { font-size: .9rem; margin-top: 2px; white-space: pre-wrap; word-break: break-word; }
.log-item .li-tags { font-size: .74rem; color: var(--primary); margin-top: 2px; }
.log-item .li-badge { font-size: .72rem; color: var(--danger); }
.log-item .li-edit {
  flex: none; align-self: center; font-size: .76rem; font-weight: 700; color: var(--primary);
  border: 1.5px solid color-mix(in srgb, var(--primary) 45%, transparent);
  border-radius: 99px; padding: 5px 11px; white-space: nowrap;
}
.empty { text-align: center; color: var(--muted); padding: 20px 8px; font-size: .9rem; }

/* ═══════════════ カレンダー ═══════════════ */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-head span { font-weight: 700; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-cell {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-size: .8rem; border-radius: 10px; position: relative; border: none;
  background: none; cursor: default; padding: 0;
}
button.cal-cell { cursor: pointer; }
button.cal-cell:hover { outline: 1.5px solid var(--primary); }
.cal-cell.dow { color: var(--muted); font-size: .7rem; aspect-ratio: auto; padding: 4px 0; }
.cal-cell.sober { background: color-mix(in srgb, var(--primary) 20%, transparent); }
.cal-cell.relapse { background: color-mix(in srgb, var(--danger) 22%, transparent); }
.cal-cell.relapse::after { content: "×"; position: absolute; bottom: 0; right: 4px; font-size: .58rem; color: var(--danger); }
.cal-cell.exception { background: color-mix(in srgb, var(--special) 22%, transparent); }
.cal-cell.exception::after { content: "✦"; position: absolute; bottom: 0; right: 4px; font-size: .58rem; color: var(--special); }
.cal-cell.today { outline: 2px solid var(--accent); font-weight: 800; }
.cal-cell.selected { outline: 2.5px solid var(--primary); }
.cal-legend { display: flex; gap: 16px; justify-content: center; margin-top: 12px; font-size: .78rem; color: var(--muted); }
.cal-legend i.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: middle; }
.dot.sober { background: var(--primary); }
.dot.relapse { background: var(--danger); }
.dot.exception { background: var(--special); }
.dot.today { background: var(--accent); }

.day-detail {
  margin-top: 14px; padding: 14px; border-radius: var(--radius-md); background: var(--bg);
  border: 1px solid var(--border); font-size: .88rem;
}
.day-detail .dd-date { font-weight: 700; margin-bottom: 4px; }
.day-detail .dd-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.day-detail .dd-actions .btn { padding: 8px 14px; font-size: .82rem; }

.trigger-insight { display: flex; flex-direction: column; gap: 8px; }
.ti-row { display: flex; align-items: center; gap: 10px; font-size: .88rem; }
.ti-bar { flex: 1; height: 10px; background: var(--border); border-radius: 99px; overflow: hidden; }
.ti-bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.ti-count { font-size: .78rem; color: var(--muted); min-width: 3em; text-align: right; }

/* ═══════════════ バッジ ═══════════════ */
.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.badge { text-align: center; padding: 16px 8px; border-radius: 16px; border: 1px solid var(--border); }
.badge.locked { opacity: .38; filter: grayscale(1); }
.badge.unlocked { background: color-mix(in srgb, var(--accent) 12%, transparent); border-color: var(--accent); }
.badge .b-emoji { font-size: 2rem; }
.badge .b-title { font-size: .82rem; font-weight: 700; margin-top: 4px; }
.badge .b-sub { font-size: .7rem; color: var(--muted); }

/* ═══════════════ 下部ナビ ═══════════════ */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: flex; justify-content: center; gap: 4px;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--card) 82%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.nav-item {
  flex: 1; max-width: 130px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 1px; background: none; border: none; cursor: pointer;
  border-radius: var(--radius-md); color: var(--muted); transition: .15s; padding: 4px 0;
}
.nav-item .nav-emoji { display: block; width: 22px; height: 22px; opacity: .68; transition: .15s; }
.nav-item .nav-label { font-size: .66rem; font-weight: 700; }
.nav-item.active { color: var(--primary); }
.nav-item.active .nav-emoji { opacity: 1; transform: translateY(-1px); }

/* ═══════════════ 線画UIアイコン共通（絵文字の代わりに使う統一アイコン） ═══════════════ */
.ui-icon { width: 100%; height: 100%; display: block; }

/* ═══════════════ SOS ═══════════════ */
.sos-fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 14px);
  z-index: 40; border: none; cursor: pointer;
  background: linear-gradient(135deg, #f43f5e, #e11d48); color: #fff;
  font-size: .9rem; font-weight: 800; padding: 13px 18px; border-radius: var(--radius-pill);
  box-shadow: 0 6px 18px rgba(225, 29, 72, .4);
  transition: transform .15s;
}
.sos-fab:active { transform: scale(.94); }

.overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(8, 12, 24, .66);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.overlay.hidden, .sheet.hidden, .toast.hidden { display: none; }

.sos-box {
  background: var(--card); border-radius: var(--radius-xl); padding: 26px 22px;
  width: 100%; max-width: 400px; text-align: center; max-height: 92vh; overflow-y: auto;
}
.sos-box h2 { font-size: 1.1rem; margin-bottom: 4px; }
.sos-sub { font-size: .85rem; color: var(--muted); margin-bottom: 18px; }
.breath-stage { position: relative; width: 210px; height: 210px; margin: 0 auto 18px; }
.breath-circle {
  position: absolute; inset: 35px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, color-mix(in srgb, var(--primary) 55%, #fff), var(--primary-dark));
  opacity: .65; transform: scale(.45);
  transition: transform 4s cubic-bezier(.45, 0, .25, 1), opacity 4s ease, box-shadow 4s ease;
  box-shadow: 0 0 0 0 transparent;
}
.breath-circle::after {
  content: ""; position: absolute; inset: -14px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--primary) 45%, transparent);
  opacity: 0; transition: opacity 4s ease;
}
.breath-circle.in,
.breath-circle.hold {
  transform: scale(1.5); opacity: 1;
  box-shadow: 0 0 60px 18px color-mix(in srgb, var(--primary) 45%, transparent);
}
.breath-circle.in::after, .breath-circle.hold::after { opacity: 1; }
.breath-circle.out {
  transform: scale(.45); opacity: .65; transition-duration: 6s;
  box-shadow: 0 0 0 0 transparent;
}
.breath-circle.out::after { opacity: 0; transition-duration: 6s; }
.breath-center {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 6px;
  align-items: center; justify-content: center; color: #fff; text-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}
.breath-center span:first-child {
  font-size: 1.1rem; font-weight: 800;
  background: rgba(8, 20, 18, .45); padding: 4px 16px; border-radius: 99px;
}
#breathPhase.breath-done { font-size: 1.2rem; padding: 6px 18px; white-space: nowrap; }
.breath-count {
  font-size: .82rem; background: rgba(8, 20, 18, .35);
  padding: 2px 12px; border-radius: 99px;
}
.sos-actions { flex-direction: column; margin: 20px 0 16px; }
.sos-reasons { text-align: left; margin-bottom: 16px; }
.sos-reasons .sr-title { font-size: .8rem; color: var(--muted); margin-bottom: 6px; }
.sos-reasons .sr-item { font-size: .9rem; padding: 7px 12px; background: var(--bg); border-radius: 10px; margin-bottom: 6px; }

/* ═══════════════ シート（下から出るパネル） ═══════════════ */
.sheet { position: fixed; inset: 0; z-index: 90; background: rgba(8, 12, 24, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet-panel {
  background: var(--card); border-radius: var(--radius-xl) var(--radius-xl) 0 0; padding: 10px 20px calc(22px + env(safe-area-inset-bottom, 0px));
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  animation: sheetUp .3s cubic-bezier(.22, 1, .36, 1);
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
/* 見た目のバーは細いが、指で下にスワイプして閉じられるよう
   実際の当たり判定はもっと広く取ってある */
.sheet-grip {
  width: 100%; height: 30px; margin: -6px auto 4px; display: flex;
  align-items: center; justify-content: center; cursor: grab; touch-action: none;
}
.sheet-grip > i { width: 42px; height: 5px; border-radius: var(--radius-pill); background: var(--border); display: block; }
.sheet-panel h2 { font-size: 1.1rem; margin-bottom: 16px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.sheet-actions .btn { flex: 1; }
.sticky-actions { position: sticky; bottom: 0; background: var(--card); padding: 12px 0 4px; }
.sheet-tall { max-height: 92vh; }
.sec-title { font-size: .78rem; font-weight: 800; color: var(--primary); margin: 20px 0 10px; letter-spacing: .06em; }
.sec-title:first-of-type { margin-top: 4px; }
.relapse-copy { font-size: .9rem; background: var(--bg); border-radius: 12px; padding: 13px 14px; margin-bottom: 16px; }

.seg { display: flex; gap: 6px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 4px; margin-bottom: 16px; }
.seg-btn {
  flex: 1; border: none; background: none; padding: 9px 6px; border-radius: 9px;
  font-size: .88rem; font-weight: 700; cursor: pointer; color: var(--muted); transition: .15s;
}
.seg-btn.active { background: var(--card); color: var(--primary); box-shadow: var(--shadow); }

.toggle-field { display: flex; align-items: center; justify-content: space-between; }
.toggle-field > span { margin-bottom: 0; }
.toggle-field input[type="checkbox"] { width: 48px; height: 28px; appearance: none; background: var(--border); border-radius: 99px; position: relative; cursor: pointer; transition: .2s; flex: none; }
.toggle-field input[type="checkbox"]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.toggle-field input[type="checkbox"]:checked { background: var(--primary); }
.toggle-field input[type="checkbox"]:checked::after { transform: translateX(20px); }
.hint { font-size: .78rem; color: var(--muted); margin: -6px 0 14px; }
.hint-warn {
  color: var(--hint-warn); background: color-mix(in srgb, #f59e0b 12%, transparent);
  border: 1px solid color-mix(in srgb, #f59e0b 35%, transparent);
  border-radius: var(--radius-sm); padding: 9px 11px; margin-top: 2px;
}
.migrate-details {
  margin: -6px 0 14px; border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 14px; background: var(--bg-alt, transparent);
}
.migrate-details summary {
  font-size: .85rem; font-weight: 700; cursor: pointer; list-style: none;
}
.migrate-details summary::-webkit-details-marker { display: none; }
.migrate-details summary::after { content: '▾'; float: right; color: var(--muted); transition: transform .15s; }
.migrate-details[open] summary::after { transform: rotate(180deg); }
.migrate-steps { margin: 10px 0 2px; padding-left: 20px; font-size: .8rem; color: var(--muted); line-height: 1.6; }
.migrate-steps li { margin-bottom: 6px; }
/* 通貨変更時に金額欄へ注目を促すパルス */
.pulse-attn { animation: pulseAttn 1.4s ease-in-out; }
@keyframes pulseAttn {
  0%, 100% { box-shadow: none; }
  25%, 65% { box-shadow: 0 0 0 3px color-mix(in srgb, #f59e0b 55%, transparent); }
}

.data-actions { display: flex; gap: 10px; margin-bottom: 10px; }
.data-actions .btn { flex: 1; font-size: .84rem; padding: 11px 8px; text-align: center; }
.file-btn { display: flex; align-items: center; justify-content: center; }
.link-btn { display: flex; align-items: center; justify-content: center; text-decoration: none; margin-bottom: 10px; }

/* ═══════════════ オンボーディング ═══════════════ */
.ob-box {
  background: var(--card); border-radius: var(--radius-xl); padding: 28px 24px 20px;
  width: 100%; max-width: 420px; max-height: 92vh; overflow-y: auto;
}
.ob-emoji { font-size: 2.6rem; text-align: center; margin-bottom: 8px; }
.ob-box h2 { text-align: center; font-size: 1.25rem; margin-bottom: 8px; }
.ob-lead { text-align: center; font-size: .9rem; color: var(--muted); margin-bottom: 20px; white-space: pre-line; }
.ob-dots { display: flex; gap: 7px; justify-content: center; margin-top: 18px; }
.ob-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--border); transition: .2s; }
.ob-dots i.on { background: var(--primary); width: 22px; border-radius: 99px; }
#obNext1 { margin-top: 6px; }

/* ═══════════════ トースト・紙吹雪 ═══════════════ */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 18px);
  left: 50%; transform: translateX(-50%);
  background: var(--toast-bg); color: var(--toast-fg); padding: 12px 20px; border-radius: 99px;
  font-size: .9rem; font-weight: 700; z-index: 200; box-shadow: var(--shadow);
  animation: toastIn .3s; display: flex; align-items: center; gap: 12px;
  max-width: min(92vw, 480px);
}
.toast button {
  background: none; border: none; color: var(--primary); font-weight: 800;
  cursor: pointer; font-size: .9rem; padding: 2px 4px; flex: none;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ═══════════════ バックアップ誘導カード ═══════════════ */
/* ボタン操作で閉じるまで消えないため、SOSボタンの帯とは重ねず、その上に置く */
.backup-nudge {
  position: fixed; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 84px);
  left: 50%; transform: translateX(-50%);
  width: min(92vw, 420px);
  background: var(--card); color: var(--text); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: 0 12px 32px rgba(0, 0, 0, .18), var(--shadow);
  z-index: 200; animation: toastIn .3s;
}
.backup-nudge.hidden { display: none; }
.backup-nudge-x {
  position: absolute; top: 8px; right: 8px; background: none; border: none;
  color: var(--muted); font-size: 1rem; cursor: pointer; padding: 6px; line-height: 1;
}
.backup-nudge-row { display: flex; align-items: flex-start; gap: 10px; padding-right: 22px; }
.backup-nudge-icon { font-size: 1.3rem; flex: none; }
.backup-nudge-msg { font-size: .88rem; line-height: 1.5; margin: 0; }
.backup-nudge-actions { display: flex; align-items: center; gap: 6px 14px; flex-wrap: wrap; margin-top: 12px; }
.backup-nudge-actions .btn-sm { padding: 9px 16px; font-size: .85rem; border-radius: 11px; }
.backup-nudge-quiet { margin: 0; padding: 6px 2px; }

/* ═══════════════ スリップ記録の確認（中央ポップ） ═══════════════ */
.rc-overlay {
  position: fixed; inset: 0; z-index: 210; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(10, 20, 18, .46);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  animation: rcFadeIn .22s ease-out;
}
.rc-overlay.hidden { display: none; }
.rc-overlay.closing { animation: rcFadeOut .2s ease-in forwards; }
.rc-overlay.closing .rc-card { animation: rcCardOut .2s ease-in forwards; }
@keyframes rcFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rcFadeOut { from { opacity: 1; } to { opacity: 0; } }
.rc-card {
  position: relative; max-width: 340px; width: 100%; text-align: center;
  background: var(--card); border-radius: calc(var(--radius) + 6px); padding: 30px 26px 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .22), var(--shadow);
  animation: rcCardIn .42s cubic-bezier(.2, 1.6, .4, 1);
}
@keyframes rcCardIn { from { opacity: 0; transform: scale(.72) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes rcCardOut { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(.85); } }
.rc-icon {
  font-size: 3rem; line-height: 1; margin-bottom: 12px;
  animation: rcIconPop .5s .1s backwards cubic-bezier(.2, 1.8, .4, 1);
}
@keyframes rcIconPop { from { transform: scale(0) rotate(-15deg); } to { transform: scale(1) rotate(0); } }
.rc-msg {
  font-size: 1.02rem; font-weight: 700; color: var(--text); line-height: 1.7; margin-bottom: 22px;
  white-space: pre-line;         /* 文章内の改行位置をそのまま使う */
  text-wrap: balance;            /* 収まらない場合も行の長さを揃えて折り返す */
}
.rc-actions { display: flex; align-items: center; justify-content: center; gap: 10px; }
.rc-undo {
  flex: 1; background: var(--primary); color: #fff; border: none; border-radius: 99px;
  padding: 13px 18px; font-size: .96rem; font-weight: 800; cursor: pointer;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 38%, transparent);
}
.rc-undo:active { transform: scale(.97); }
.rc-close {
  flex: none; width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--bg); color: var(--muted); font-size: 1rem; cursor: pointer;
}
@media (prefers-reduced-motion: reduce) {
  .rc-overlay, .rc-card, .rc-icon { animation: none !important; }
}

.confetti-piece { position: fixed; top: -14px; z-index: 500; pointer-events: none; }

/* ═══════════════ 大吉ジャックポット演出 ═══════════════ */
.jackpot {
  position: fixed; inset: 0; z-index: 400; overflow: hidden; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: rgba(12, 8, 2, .74);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
.jackpot.hidden { display: none; }
.jp-rays {
  position: absolute; left: 50%; top: 50%; width: 220vmax; height: 220vmax;
  transform: translate(-50%, -50%);
  background: repeating-conic-gradient(from 0deg,
    rgba(251, 191, 36, .30) 0deg 11deg, transparent 11deg 26deg);
  animation: jpSpin 7s linear infinite;
  -webkit-mask-image: radial-gradient(circle, #000 0%, transparent 62%);
  mask-image: radial-gradient(circle, #000 0%, transparent 62%);
}
@keyframes jpSpin { to { transform: translate(-50%, -50%) rotate(360deg); } }
.jp-core { position: relative; text-align: center; animation: jpPop .7s cubic-bezier(.2, 1.7, .4, 1); padding: 0 20px; }
.jp-emoji { font-size: 4.2rem; line-height: 1.1; animation: jpBounce .9s ease-in-out infinite alternate; }
.jp-title {
  font-size: clamp(2.6rem, 13vw, 3.6rem); font-weight: 900; letter-spacing: .05em; color: #fde047;
  text-shadow: 0 0 28px rgba(251, 191, 36, .95), 0 3px 0 #b45309, 0 0 70px rgba(253, 224, 71, .5);
  animation: jpFlash .55s ease-in-out infinite alternate;
}
.jp-sub { color: #fff; font-weight: 700; margin-top: 10px; font-size: 1rem; text-shadow: 0 1px 8px rgba(0, 0, 0, .7); }
.jp-tap { color: rgba(255, 255, 255, .75); font-size: .78rem; margin-top: 22px; }
@keyframes jpPop { 0% { transform: scale(0) rotate(-8deg); opacity: 0; } 62% { transform: scale(1.18) rotate(2deg); opacity: 1; } 100% { transform: scale(1) rotate(0); } }
@keyframes jpFlash { from { filter: brightness(1); transform: scale(1); } to { filter: brightness(1.4); transform: scale(1.06); } }
@keyframes jpBounce { from { transform: translateY(0); } to { transform: translateY(-12px); } }

/* 大吉の日のカード（金色仕様・演出後もその日は残る） */
.tarot.gold {
  background: radial-gradient(circle at 50% 28%, #fff7d6, #fde047 42%, #f59e0b 82%);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .85), 0 0 20px 5px rgba(251, 191, 36, .6);
  animation: goldGlow 1.6s ease-in-out infinite alternate;
}
@keyframes goldGlow {
  from { box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .85), 0 0 14px 3px rgba(251, 191, 36, .45); }
  to { box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .85), 0 0 26px 8px rgba(251, 191, 36, .75); }
}
.jp-chip {
  display: inline-block; margin-left: 8px; vertical-align: 2px;
  background: linear-gradient(135deg, #fde047, #f59e0b); color: #7c2d12;
  font-size: .66rem; font-weight: 900; border-radius: 99px; padding: 2px 10px; letter-spacing: .04em;
}

canvas { width: 100%; }

/* ═══════════════ 小さい画面・モーション設定 ═══════════════ */
@media (max-width: 380px) {
  .ring-wrap { width: 148px; height: 148px; }
  .ring-days b { font-size: 2.5rem; }
  .liver-svg { width: 78px; height: 65px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
