/* =========================================================
   ととのい呼吸 スタイル
   色はすべて :root のトークンで管理（ダーク／ライト）
   ========================================================= */
:root,
:root[data-theme="dark"] {
  --bg: #0c1418;
  --bg-2: #0f1b20;
  --surface: #14232a;
  --surface-2: #1a2d35;
  --line: #27404a;
  --text: #e4eeec;
  --muted: #92a9aa;
  --accent: #6cc4b4;
  --accent-2: #86a9dc;
  --accent-ink: #08201c;
  --warn: #e3b874;
  --danger: #e58f86;
  --glow: rgba(108, 196, 180, .28);
  --shadow: 0 1px 0 rgba(255,255,255,.03), 0 8px 24px rgba(0,0,0,.25);
  --orb-ink: #062520;
  --orb-shadow: 0 0 14px rgba(255,255,255,.35);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f2f6f4;
  --bg-2: #e9f0ed;
  --surface: #ffffff;
  --surface-2: #eaf2ef;
  --line: #d3e0dc;
  --text: #182a2d;
  --muted: #587073;
  --accent: #2c8a7b;
  --accent-2: #3d6aa3;
  --accent-ink: #ffffff;
  --warn: #8f6210;
  --danger: #b23a2e;
  --glow: rgba(44, 138, 123, .22);
  --shadow: 0 1px 2px rgba(20,40,40,.06), 0 8px 24px rgba(20,40,40,.08);
  --orb-ink: #ffffff;
  --orb-shadow: 0 1px 10px rgba(0,0,0,.3);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  font-feature-settings: "palt";
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }

/* ---------- ヘッダー ---------- */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 560px; margin: 0 auto; padding: 14px 16px 6px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); min-width: 0; }
.brand-mark { width: 28px; height: 28px; }
.brand h1 { margin: 0; font-size: clamp(1rem, 4.4vw, 1.15rem); letter-spacing: .04em; color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-mark { flex: none; }
.header-actions { display: flex; gap: 2px; flex: none; }
.lang-switch {
  min-width: 44px; height: 44px; padding: 0 8px; white-space: nowrap; display: inline-grid; place-items: center; border-radius: 12px;
  color: var(--muted); text-decoration: none; font-size: .82rem; font-weight: 600; letter-spacing: .04em;
}
.lang-switch:hover { background: var(--surface); color: var(--text); }
.lang-banner {
  max-width: 528px; margin: 4px auto 6px; padding: 6px 6px 6px 14px; border-radius: 12px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .85rem;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
}
@media (max-width: 560px) { .lang-banner { margin-left: 16px; margin-right: 16px; } }
.lang-banner a { color: var(--accent); font-weight: 600; min-height: 32px; display: inline-flex; align-items: center; }
.lang-banner-close { margin-left: auto; width: 36px; height: 36px; border: 0; background: none; color: var(--muted); font-size: 1.1rem; border-radius: 10px; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center;
  background: transparent; border: 0; border-radius: 12px; color: var(--muted);
}
.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- アプリ本体 ---------- */
main { max-width: 560px; margin: 0 auto; padding: 0 16px; }
.app { position: relative; }
.view { padding-bottom: 24px; }
.lead { color: var(--muted); margin: 6px 0 18px; font-size: .95rem; }
.sec-title { font-size: .85rem; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin: 22px 0 10px; }
.sec-title .opt { font-weight: 400; letter-spacing: 0; }

.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu-card {
  position: relative; text-align: left; min-height: 72px;
  display: flex; flex-direction: column; gap: 2px; justify-content: center;
  padding: 12px 14px; border-radius: 16px;
  background: var(--surface); border: 1.5px solid var(--line);
  box-shadow: var(--shadow); transition: border-color .2s, background .2s;
}
.menu-card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.menu-card[aria-checked="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}
.menu-card.featured { grid-column: 1 / -1; padding: 16px 16px 14px; min-height: 92px; }
.menu-card.featured .mc-title { font-size: 1.1rem; }
.mc-title { font-weight: 600; font-size: 1rem; line-height: 1.4; }
.mc-sub { font-size: .8rem; color: var(--muted); line-height: 1.5; }
.mc-badge {
  align-self: flex-start; font-size: .7rem; letter-spacing: .08em; font-weight: 600;
  color: var(--accent-ink); background: var(--accent); border-radius: 999px; padding: 1px 10px; margin-bottom: 4px;
}
.compact .menu-card { min-height: 64px; }

.panel {
  margin-top: 12px; padding: 8px 14px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line);
}
.stepper { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.stepper + .stepper { border-top: 1px solid var(--line); }
.st-label { flex: 1; }
.st-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); font-size: 1.2rem; line-height: 1;
}
.st-val { min-width: 2ch; text-align: right; font-size: 1.2rem; font-variant-numeric: tabular-nums; font-weight: 600; }
.st-unit { color: var(--muted); font-size: .85rem; margin-right: 4px; }

.note { font-size: .82rem; color: var(--muted); margin: 10px 0 0; }
.note.warn { color: var(--warn); }

.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 4px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
}
.seg button {
  min-height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted);
  font-size: .95rem; padding: 0 4px;
}
.seg button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.summary {
  margin-top: 14px; padding: 12px 14px; border-radius: 14px;
  background: var(--bg-2); border: 1px dashed var(--line); font-size: .92rem;
}
.summary strong { color: var(--accent); font-variant-numeric: tabular-nums; }
.program-steps { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.program-steps li {
  display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: baseline;
  font-size: .85rem; padding: 6px 10px; border-radius: 10px; background: var(--surface);
}
.program-steps .ps-n {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: .75rem; background: var(--surface-2); color: var(--accent); font-weight: 600;
}
.program-steps .ps-t { color: var(--muted); font-variant-numeric: tabular-nums; }

.mood { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.mood button {
  min-height: 52px; padding: 6px 2px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: .68rem; color: var(--muted); line-height: 1.3;
}
.mood button .mf { font-size: 1.15rem; color: var(--text); line-height: 1.1; }
.mood button[aria-checked="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface)); color: var(--text); }

.options {
  margin-top: 22px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line);
}
.options summary {
  list-style: none; cursor: pointer; padding: 12px 16px; min-height: 44px; font-weight: 600; font-size: .95rem;
  display: flex; justify-content: space-between; align-items: center;
}
.options summary::-webkit-details-marker { display: none; }
.options summary::after { content: "＋"; color: var(--muted); }
.options[open] summary::after { content: "−"; }
.opt-list { padding: 0 16px 14px; display: grid; gap: 4px; }
.toggle { display: flex; align-items: center; gap: 12px; min-height: 44px; font-size: .92rem; cursor: pointer; }
.toggle input {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 44px; height: 26px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line);
  position: relative; transition: background .2s; cursor: pointer;
}
.toggle input::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--muted); transition: transform .2s, background .2s;
}
.toggle input:checked { background: var(--accent); border-color: var(--accent); }
.toggle input:checked::after { transform: translateX(18px); background: var(--accent-ink); }
.field { display: flex; align-items: center; gap: 12px; min-height: 44px; font-size: .92rem; }
.field label { flex: none; width: 4.5em; }
.field select, .field input[type="range"] { flex: 1; min-width: 0; }
.field select {
  min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 10px;
}
input[type="range"] { accent-color: var(--accent); }

.start-bar {
  position: sticky; bottom: 0; z-index: 2; margin: 22px -16px 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.btn-primary, .btn-secondary, .btn-ghost {
  min-height: 52px; border-radius: 16px; padding: 0 24px; font-weight: 600; font-size: 1.05rem; border: 0;
}
.btn-primary { width: 100%; background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 20px var(--glow); }
.btn-primary:active { transform: translateY(1px); }
.btn-secondary { background: var(--surface-2); border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn-ghost.small { min-height: 40px; font-size: .9rem; padding: 0 14px; }
.btn-text {
  background: none; border: 0; color: var(--accent); font-size: .88rem; min-height: 44px; padding: 0 6px;
  text-decoration: underline; text-underline-offset: 3px; display: inline-flex; align-items: center;
}
.btn-text.danger { color: var(--danger); }
.sub-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; }
.embed-only { display: none; }
.embed .embed-only { display: inline-flex; }

.caution {
  margin-top: 18px; padding: 12px 16px; border-radius: 14px; font-size: .8rem; color: var(--muted);
  background: var(--bg-2); border: 1px solid var(--line);
}
.caution p { margin: 0 0 4px; color: var(--text); }
.caution ul { margin: 0; padding-left: 1.2em; }

/* ---------- セッション画面 ---------- */
/* 背景の波（WebGL）。内容の後ろに全面表示する */
.wave-bg { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -1; display: block; pointer-events: none; }
.wave-bg[hidden] { display: none; }
.session { min-height: calc(100svh - 70px); display: flex; flex-direction: column; }
.ses-top { padding-top: 4px; }
.ses-stage { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.ses-stage-name { font-weight: 600; font-size: .95rem; }
.ses-remaining { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 1.05rem; }
.progress { height: 4px; border-radius: 4px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 4px; }
.ses-stage-desc { font-size: .82rem; color: var(--muted); min-height: 2.8em; margin: 8px 0 0; }

.orb-wrap {
  --size: min(78vw, 320px, 46svh);
  position: relative; width: var(--size); height: var(--size); margin: auto; flex: none;
  display: grid; place-items: center;
}
.orb-guide {
  position: absolute; inset: 0; border-radius: 50%;
  border: 1.5px dashed color-mix(in srgb, var(--accent) 35%, transparent);
}
.orb {
  position: absolute; inset: 0; border-radius: 50%; transform: scale(.42); will-change: transform;
  background: radial-gradient(circle at 38% 32%, color-mix(in srgb, var(--accent) 82%, #fff) 0%, var(--accent) 45%, color-mix(in srgb, var(--accent) 70%, var(--bg)) 100%);
  box-shadow: 0 0 60px var(--glow), inset 0 0 40px rgba(255,255,255,.08);
  overflow: hidden;
}
.orb-tint {
  position: absolute; inset: 0; border-radius: 50%; opacity: 0; transition: opacity 1.2s ease;
  background: radial-gradient(circle at 38% 32%, color-mix(in srgb, var(--accent-2) 85%, #fff) 0%, var(--accent-2) 50%, color-mix(in srgb, var(--accent-2) 65%, var(--bg)) 100%);
}
.orb-wrap[data-phase="out"] .orb-tint,
.orb-wrap[data-phase="hold2"] .orb-tint { opacity: 1; }
.orb-wrap[data-phase="free"] .orb-tint { opacity: .5; }
.orb-text {
  position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center;
  text-shadow: var(--orb-shadow); color: var(--orb-ink);
}
.ses-phase { font-size: clamp(1.4rem, 6vw, 1.85rem); font-weight: 700; letter-spacing: .08em; white-space: nowrap; }
.ses-count { font-size: clamp(1.2rem, 5vw, 1.6rem); font-variant-numeric: tabular-nums; opacity: .9; min-height: 1.5em; }

.ses-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-top: 16px; }
.hint-keys { text-align: center; font-size: .75rem; color: var(--muted); margin: 10px 0 0; }
@media (hover: none) { .hint-keys { display: none; } }

.dark-overlay {
  position: fixed; inset: 0; z-index: 50; background: #000; display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: calc(40px + env(safe-area-inset-bottom)); transition: opacity .6s;
}
.dark-overlay p { color: #3c4a4d; font-size: .8rem; transition: opacity 1.5s; }
.dark-overlay.quiet p { opacity: 0; }
.dark-overlay.peek { opacity: 0; pointer-events: none; }

/* ---------- 完了画面 ---------- */
.done { text-align: center; padding-top: 24px; }
.done-mark {
  width: 72px; height: 72px; margin: 0 auto; border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, var(--accent-2), var(--accent));
  box-shadow: 0 0 40px var(--glow); animation: settle 2.4s ease-out;
}
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes settle { from { transform: scale(1.35); opacity: .3; } to { transform: scale(1); opacity: 1; } }
.done-title { margin: 18px 0 4px; font-size: 1.4rem; letter-spacing: .06em; }
.done-menu { color: var(--muted); margin: 0; font-size: .9rem; }
.done-stats, .hist-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 20px 0 6px;
}
.done-stats > div, .hist-stats > div {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 6px;
  display: flex; flex-direction: column; align-items: center;
}
.ds-num { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.ds-label { font-size: .75rem; color: var(--muted); }
.done .sec-title { text-align: left; }
.mood-compare { font-size: .9rem; margin: 10px 0 0; }
.mood-compare strong { color: var(--accent); }
.done-actions { display: grid; gap: 10px; margin-top: 24px; }
.share-fallback { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.new-badges { margin-top: 16px; display: grid; gap: 8px; }
.new-badge {
  display: flex; align-items: center; gap: 12px; text-align: left; padding: 10px 14px; border-radius: 14px;
  background: color-mix(in srgb, var(--warn) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--line));
  font-size: .9rem; animation: rise .8s ease-out;
}
.nb-icon { flex: none; width: 30px; height: 30px; border-radius: 50%; background: radial-gradient(circle at 38% 32%, #ffe3ad, var(--warn)); }
.new-badge small { display: block; color: var(--muted); font-size: .75rem; }

/* ---------- 記録画面 ---------- */
.hist-head { display: flex; justify-content: space-between; align-items: center; padding-top: 8px; }
.hist-head h2 { margin: 0; font-size: 1.3rem; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: .7rem; color: var(--muted); }
.cal-day {
  aspect-ratio: 1; border-radius: 8px; display: grid; place-items: center; font-size: .75rem;
  background: var(--surface); color: var(--muted); border: 1px solid transparent; font-variant-numeric: tabular-nums;
}
.cal-day.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.cal-day.today { border-color: var(--accent-2); }
.cal-day.blank { background: transparent; }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.badge {
  padding: 10px 6px; border-radius: 12px; text-align: center; font-size: .75rem; line-height: 1.4;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
}
.badge .bi { display: block; width: 26px; height: 26px; margin: 0 auto 4px; border-radius: 50%; border: 2px dashed var(--line); }
.badge.got { color: var(--text); border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); }
.badge.got .bi { border: 0; background: radial-gradient(circle at 38% 32%, #ffe3ad, var(--warn)); }
.hist-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.hist-list li {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 12px; border-radius: 12px;
  background: var(--surface); font-size: .85rem;
}
.hist-list .hl-date { color: var(--muted); font-size: .75rem; grid-column: 1 / -1; }
.hist-list .hl-dur { font-variant-numeric: tabular-nums; color: var(--muted); }
.hist-list .hl-mood { grid-column: 1 / -1; font-size: .75rem; color: var(--muted); }
.hist-tools { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 14px; }
.file-label { cursor: pointer; position: relative; }
.file-label input { position: absolute; opacity: 0; width: 1px; height: 1px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: .88rem; z-index: 60;
  max-width: calc(100vw - 32px); box-shadow: var(--shadow);
}

/* ---------- 解説 ---------- */
.guide {
  margin: 40px 0 0; padding: 28px 0 8px; border-top: 1px solid var(--line); font-size: .95rem;
}
.guide h2 { font-size: 1.1rem; margin: 28px 0 10px; padding-left: 12px; border-left: 3px solid var(--accent); line-height: 1.5; }
.guide h2:first-child { margin-top: 0; }
.guide p, .guide li, .guide dd { color: color-mix(in srgb, var(--text) 85%, var(--muted)); }
.guide ol, .guide ul { padding-left: 1.4em; }
.guide li { margin: 4px 0; }
.faq dt { font-weight: 600; margin-top: 14px; }
.faq dt::before { content: "Q. "; color: var(--accent); }
.faq dd { margin: 4px 0 0; }
.faq dd::before { content: "A. "; color: var(--muted); }
.site-footer { text-align: center; font-size: .75rem; color: var(--muted); padding: 24px 16px 40px; }

/* ---------- 実行中は余計なものを隠す ---------- */
.in-session .header-actions, .in-session .lang-banner { visibility: hidden; }
.in-session .lang-banner { display: none; }
.in-session .guide, .in-session .site-footer { display: none; }

/* ---------- 埋め込みモード ---------- */
.embed .site-header, .embed .guide, .embed .site-footer, .embed .skip, .embed .lang-banner { display: none !important; }
.embed body { background: var(--bg); }
.embed main { padding-top: 12px; }
.embed .session { min-height: 520px; }

/* ---------- 動きを減らす設定 ---------- */
@media (prefers-reduced-motion: reduce) {
  .done-mark, .new-badge { animation: none; }
  .orb-tint { transition: none; }
}

@media (min-width: 600px) {
  .lead { font-size: 1rem; }
}

/* ---------- とても狭い画面（英語のアプリ名が入りきるように） ---------- */
@media (max-width: 359px) {
  .site-header { padding-left: 12px; padding-right: 8px; }
  .brand-mark { display: none; }
  .icon-btn { width: 40px; }
}
