/* おとログ — トークン・レイアウト・コンポーネント */

:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --text: #1b1b1f;
  --text-dim: #6b6b75;
  --border: #dddcd5;
  --accent: #3d5ce0;
  --accent-text: #ffffff;
  --danger: #d64545;
  --sat: #3b6fd6;
  --day-light: #4a9a4f;
  --day-dark: #6cc070;
  --day: var(--day-light);
  --day-fill: #3d8a42;
  --day-on-fill: #ffffff;
  --day-bg-top: #1f3a20;
  --day-bg-bottom: #0e1a14;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .06);
  --radius: 16px;
  --header-h: 52px;
  --tab-h: 60px;
  --font: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111114;
    --surface: #1c1c21;
    --surface-2: #26262d;
    --text: #ececf1;
    --text-dim: #9a9aa6;
    --border: #33333b;
    --accent: #8aa0ff;
    --accent-text: #111114;
    --danger: #ff6b6b;
    --sat: #7aa2ff;
    --day: var(--day-dark);
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111114;
  --surface: #1c1c21;
  --surface-2: #26262d;
  --text: #ececf1;
  --text-dim: #9a9aa6;
  --border: #33333b;
  --accent: #8aa0ff;
  --accent-text: #111114;
  --danger: #ff6b6b;
  --sat: #7aa2ff;
  --day: var(--day-dark);
  --shadow: none;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
p, h1, h2, h3, span { overflow-wrap: anywhere; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { flex: none; display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- ヘッダー ---------- */
.app-header {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.header-inner {
  height: var(--header-h);
  max-width: 480px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.header-left, .header-right { min-width: 0; display: flex; align-items: center; gap: 6px; }
.header-right { color: var(--text-dim); font-size: 14px; text-align: right; }
.app-name { font-weight: 800; font-size: 18px; letter-spacing: .02em; }
.back-link {
  display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding-right: 8px;
  color: var(--text); text-decoration: none; font-weight: 600;
}
.header-date { display: inline-flex; align-items: center; gap: 6px; color: var(--text); white-space: nowrap; }

/* ---------- メイン ---------- */
.app-main {
  max-width: 480px; margin: 0 auto;
  padding: 16px 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 32px);
  outline: none;
  min-width: 0;
}
.view { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.boot { color: var(--text-dim); text-align: center; padding: 40px 0; }

/* ---------- 下部タブ ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 1; max-width: 160px; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text-dim); text-decoration: none; font-size: 12px; font-weight: 600;
}
.tabbar a[aria-current="page"] { color: var(--text); }
.tabbar a[aria-current="page"] .icon { color: var(--accent); }

/* ---------- 共通部品 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 999px;
  border: 1px solid transparent; cursor: pointer; font-weight: 700; font-size: 15px;
  background: var(--surface-2); color: var(--text);
  text-align: center; line-height: 1.2;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--surface); border-color: var(--border); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); color: #fff; }
:root[data-theme="dark"] .btn-danger { color: #111114; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-danger { color: #111114; } }
.btn-sm { min-height: 44px; padding: 0 12px; font-size: 14px; }
.btn-lg { min-height: 52px; padding: 0 26px; font-size: 17px; }
.btn-block { width: 100%; }
.btn-text-danger { background: transparent; color: var(--danger); border: 0; min-height: 44px; font-weight: 700; cursor: pointer; padding: 0 8px; }
.text-danger { color: var(--danger); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; color: var(--text);
}
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.note { color: var(--text-dim); font-size: 13px; }
.empty { color: var(--text-dim); text-align: center; padding: 28px 8px; background: var(--surface); border-radius: var(--radius); border: 1px dashed var(--border); }
.badge {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.badge-voice { background: color-mix(in srgb, var(--day) 22%, transparent); color: var(--text); }
.badge-ambient { background: var(--surface-2); color: var(--text-dim); }
.section-label { font-size: 13px; color: var(--text-dim); font-weight: 700; margin-bottom: 6px; }
.day-dot { display: inline-block; border-radius: 50%; background: var(--day); flex: none; }
.textarea {
  width: 100%; min-height: 64px; resize: vertical; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 16px; line-height: 1.5;
}
.counter { text-align: right; color: var(--text-dim); font-size: 12px; margin-top: 4px; }

.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 4px; border-radius: 14px; background: var(--surface-2);
}
.segmented button {
  min-height: 40px; min-width: 0; border: 0; border-radius: 10px; background: transparent; cursor: pointer;
  font-weight: 700; font-size: 14px; color: var(--text-dim); padding: 0 6px;
}
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- 今日画面 ---------- */
.date-heading { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 800; }
.banner {
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
  padding: 18px 16px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.banner-todo .banner-text { font-weight: 700; font-size: 17px; }
.banner-done { flex-direction: row; justify-content: space-between; padding: 8px 8px 8px 16px; text-align: left; }
.banner-done .banner-text { color: var(--text-dim); font-size: 14px; font-weight: 600; min-width: 0; }

.slot-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.slot-wrap { min-width: 0; }
.slot {
  position: relative; width: 100%; min-height: 48px; aspect-ratio: 1.15;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
  font-weight: 700; font-size: 15px; color: var(--text); padding: 0;
}
.slot.filled { background: var(--day-fill); border-color: transparent; color: var(--day-on-fill); cursor: pointer; }
.slot.past { color: var(--text-dim); background: transparent; }
.slot.future { opacity: .4; background: transparent; border-style: dashed; }
.slot.now { border: 2px solid var(--accent); }
.slot-now { font-size: 10px; line-height: 1; color: var(--accent); font-weight: 800; }
.slot.filled .slot-now { color: var(--day-on-fill); }

/* ---------- day-panel ---------- */
.day-panel { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.player-card {
  min-height: 260px; border-radius: 22px; padding: 18px 18px 14px; color: #fff;
  background: linear-gradient(180deg, var(--day-bg-top), var(--day-bg-bottom));
  display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden;
}
.player-card::before {
  content: ""; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--day-light) 45%, transparent), transparent 70%);
  pointer-events: none;
}
.pc-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; position: relative; }
.pc-time { font-size: 40px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.pc-count { font-size: 14px; opacity: .85; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pc-wave { width: 100%; height: 72px; display: block; }
.pc-caption {
  min-height: 2.9em; font-size: 16px; font-weight: 600; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.pc-caption.is-ambient { opacity: .7; }
.pc-progress { padding: 10px 0; cursor: pointer; position: relative; }
.pc-progress-track { position: relative; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .25); overflow: hidden; }
.pc-progress-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: rgba(255, 255, 255, .95); }
.pc-progress-marks { position: absolute; inset: 0; }
.pc-mark { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: rgba(0, 0, 0, .45); }
.pc-controls { display: flex; align-items: center; gap: 8px; position: relative; }
.pc-btn {
  width: 44px; height: 44px; border-radius: 999px; border: 0; background: rgba(255, 255, 255, .14); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none;
}
.pc-play { width: 56px; height: 56px; background: #fff; color: #111; }
.pc-pos { margin-left: auto; font-size: 14px; font-variant-numeric: tabular-nums; opacity: .9; white-space: nowrap; }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, .7); }
  50% { box-shadow: 0 0 0 12px rgba(255, 255, 255, 0); }
}
.vis-section .note { margin-top: 8px; }
.export-btn .icon { color: var(--day); }

.clip-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.clip-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px; min-width: 0; scroll-margin: 80px;
  transition: background-color .3s;
}
.clip-item.flash { background: color-mix(in srgb, var(--day) 25%, var(--surface)); }
.clip-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.clip-meta { display: flex; align-items: center; gap: 8px; min-width: 0; }
.clip-time { font-weight: 800; font-size: 17px; font-variant-numeric: tabular-nums; }
.clip-dur { margin-left: auto; color: var(--text-dim); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.clip-wave-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mini-wave { width: 96px; height: 28px; flex: none; }
.clip-caption { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.clip-caption.is-ambient { color: var(--text-dim); }
.clip-actions { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.clip-actions .btn-sm { padding: 0 10px; }
.clip-play.is-playing { background: var(--day-fill); color: var(--day-on-fill); border-color: transparent; }
.delete-day { align-self: center; margin-top: 8px; }

/* ---------- カレンダー ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cal-title { font-size: 20px; font-weight: 800; text-align: center; flex: 1; }
.cal-grid { display: flex; flex-direction: column; gap: 4px; }
.cal-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-wd { text-align: center; font-size: 12px; font-weight: 700; color: var(--text-dim); padding: 4px 0; }
.cal-wd.sun { color: var(--danger); }
.cal-wd.sat { color: var(--sat); }
.cal-cell {
  aspect-ratio: 1; min-width: 0; border-radius: 10px; border: 1px solid transparent; background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding: 4px 0 0; gap: 2px;
  font-size: 14px; color: var(--text); cursor: pointer;
}
.cal-cell.empty { background: transparent; cursor: default; }
.cal-cell.future { opacity: .35; cursor: default; }
.cal-cell.today { border: 2px solid var(--accent); }
.cal-num { font-weight: 700; line-height: 1.3; }
.cal-mark { display: flex; align-items: center; gap: 3px; }
.cal-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dot-light); }
:root[data-theme="dark"] .cal-dot { background: var(--dot-dark); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .cal-dot { background: var(--dot-dark); } }
.cal-count { font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.cal-summary { text-align: center; color: var(--text-dim); font-weight: 600; }

/* ---------- 設定 ---------- */
.page-title { font-size: 22px; font-weight: 800; }
.settings-section {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 10px;
}
.section-title { font-size: 15px; font-weight: 800; }
.field-label { font-size: 13px; color: var(--text-dim); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; cursor: pointer; }
.toggle-label { min-width: 0; }
.switch {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0;
  width: 52px; height: 32px; border-radius: 999px; background: var(--border); position: relative; cursor: pointer;
  transition: background-color .2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }
.switch:disabled { opacity: .4; cursor: not-allowed; }
.usage { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- ダイアログ・シート ---------- */
dialog { color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.app-dialog {
  border: 0; padding: 0; border-radius: 20px; background: var(--surface);
  width: min(400px, calc(100vw - 32px)); max-width: calc(100vw - 32px);
}
.dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dialog-title { font-size: 18px; font-weight: 800; }
.dialog-message { color: var(--text); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 480px;
  max-height: calc(100dvh - 24px);
  border-radius: 24px 24px 0 0; background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet[open] { animation: sheet-in .22s ease-out; }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 10px auto 0; }
.sheet-body { padding: 12px 20px 20px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.sheet-title { font-size: 18px; font-weight: 800; text-align: center; }
.sheet-guide { text-align: center; color: var(--text-dim); font-size: 14px; }
.sheet-status { text-align: center; color: var(--text-dim); padding: 24px 0; font-weight: 600; }
.sheet-error { color: var(--danger); font-weight: 600; text-align: center; }
.sheet-actions { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.sheet-actions .btn { flex: 1 1 0; min-width: 0; padding: 0 10px; }

.rec-stage { position: relative; width: 140px; height: 140px; margin: 8px auto 0; display: flex; align-items: center; justify-content: center; }
.rec-btn {
  width: 88px; height: 88px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--danger); display: flex; align-items: center; justify-content: center; position: relative; z-index: 1;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--danger) 40%, transparent);
}
.rec-btn:disabled { opacity: .4; cursor: not-allowed; }
.rec-dot { width: 30px; height: 30px; border-radius: 50%; background: #fff; }
.rec-btn.is-recording { background: var(--danger); }
.rec-btn.is-locked { opacity: .55; cursor: not-allowed; }
.rec-ring { position: absolute; inset: 0; width: 140px; height: 140px; transform: rotate(-90deg); }
.rec-ring-bg { fill: none; stroke: var(--surface-2); stroke-width: 6; }
.rec-ring-fg { fill: none; stroke: var(--danger); stroke-width: 6; stroke-linecap: round; }
.level-meter { display: flex; align-items: center; gap: 4px; height: 36px; }
.level-meter span { width: 5px; height: 36px; border-radius: 3px; background: #fff; transform: scaleY(.12); transform-origin: center; transition: transform .06s linear; }
.rec-remain { text-align: center; font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.rec-interim { text-align: center; color: var(--text-dim); min-height: 1.5em; font-size: 14px; }
.review-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.review-wave { flex: 1; min-width: 0; height: 56px; }
.review-meta { display: flex; align-items: center; gap: 8px; }
.review-kind-label { color: var(--text-dim); font-size: 13px; }
.review-dur { margin-left: auto; color: var(--text-dim); font-size: 13px; }

.export-preview-wrap { display: flex; justify-content: center; }
.export-preview { width: 180px; height: 320px; border-radius: 14px; background: #000; display: block; }
.export-video { width: 180px; max-height: 320px; border-radius: 14px; background: #000; display: block; }
.export-info { text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--day); transition: width .2s linear; }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; z-index: 1000;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 32px); width: max-content;
  padding: 10px 16px; border-radius: 12px; background: #26262d; color: #fff; font-size: 14px; font-weight: 600;
  transition: opacity .2s, transform .2s; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 致命的エラー ---------- */
.fatal-box { text-align: center; padding: 60px 16px; display: flex; flex-direction: column; gap: 12px; }
.fatal .tabbar { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
