/* 見本 prototype.html の見た目を引き継ぐ。選んだタイプの色で背景が染まり、その上に半透明のカード */

/* 色を0.6秒でゆっくり切りかえるため、--t1 --t2 を「色」として登録する */
@property --t1 { syntax: "<color>"; inherits: true; initial-value: #c9ccd8; }
@property --t2 { syntax: "<color>"; inherits: true; initial-value: #c9ccd8; }

:root {
  --bg: #f3f4f8; --card: #ffffffe8; --fg: #25283a; --muted: #6b6f86; --line: #dfe1ea; --chip: #eef0f6;
  --t1: #c9ccd8; --t2: #c9ccd8;
  --f-body: "DotGothic16", "Hiragino Maru Gothic ProN", "Yu Gothic", monospace;
  transition: --t1 .6s, --t2 .6s;
}
/* ダークモード：カードを濃い紺色にする */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #15161f; --card: #1f2130e6; --fg: #eceef7; --muted: #a3a7bd; --line: #33364a; --chip: #2a2d3f; color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #15161f; --card: #1f2130e6; --fg: #eceef7; --muted: #a3a7bd; --line: #33364a; --chip: #2a2d3f; color-scheme: dark; }
@media (prefers-reduced-motion: reduce) { :root { transition: none; } }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--f-body); font-size: 15px; line-height: 1.6; -webkit-tap-highlight-color: transparent; }

/* iPhone のじゃまな動きを止める */
/* ダブルタップでの拡大を止める（スクロールとタップはそのまま） */
html, body { touch-action: manipulation; }
/* 長押しで出る拡大鏡・文字の選択・メニューを止める */
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
/* 入力欄だけは、今までどおり文字を入力・選択できる */
input, textarea { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
/* スクロールバー（画面の端に出る細い棒）を出さない */
html, * { scrollbar-width: none; }
::-webkit-scrollbar { display: none; width: 0; height: 0; }

.sky { position: fixed; inset: 0; z-index: 0; background: linear-gradient(160deg, var(--t1) 0%, var(--t2) 100%); opacity: .55; }
.wrap {
  position: relative; z-index: 1; max-width: 520px; margin: 0 auto;
  padding-top: max(20px, env(safe-area-inset-top, 0px));
  padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); /* 下のタブに隠れないように */
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid; gap: 16px;
}
header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
h1 { font-weight: 400; font-size: 22px; margin: 0; letter-spacing: .04em; }
.date { font-size: 14px; opacity: .8; }

.card { background: var(--card); border-radius: 18px; padding: 16px; display: grid; gap: 12px; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
h2 { font-size: 15px; margin: 0; letter-spacing: .06em; font-weight: 400; }
h2::before { content: "▶ "; color: var(--muted); }

.today { gap: 6px; text-align: center; padding: 6px 0; }
.today .types { font-size: 20px; }
.today .mood { color: var(--muted); font-size: 14px; min-height: 1.6em; }
.badge { display: inline-block; padding: 2px 12px; border-radius: 999px; color: #fff; margin: 0 3px; text-shadow: 0 1px 2px #0005; }

/* タイプのボタン 3列×6段 */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.type { border: 2px solid transparent; background: var(--chip); color: var(--fg); border-radius: 12px; padding: 8px 4px; min-height: 64px; font: inherit; cursor: pointer; display: grid; gap: 2px; align-content: center; line-height: 1.3; }
.type b { font-size: 14px; font-weight: 400; }
.type span { font-size: 11px; color: var(--muted); }
.type .dot { width: 10px; height: 10px; border-radius: 50%; margin: 0 auto 2px; }
.type[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 22%, var(--chip)); }
.type:focus-visible, input:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }

/* 入力欄。iPhone で入力時に画面が拡大されないよう、文字は16px */
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input, textarea { font: inherit; font-size: 16px; color: var(--fg); background: var(--chip); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%; min-width: 0; }
input[type=number] { font-variant-numeric: tabular-nums; }
textarea { resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.unit { display: grid; grid-template-columns: 1fr 3.6em; align-items: center; gap: 6px; }
.unit small { color: var(--muted); white-space: nowrap; font-size: 12px; }
.check { display: flex; align-items: center; gap: 10px; color: var(--fg); font-size: 15px; min-height: 44px; cursor: pointer; }
.check input { width: 24px; height: 24px; margin: 0; accent-color: var(--t1); }
.auto { font-size: 13px; color: var(--muted); background: var(--chip); border-radius: 10px; padding: 8px 10px; }

.save { font: inherit; font-size: 16px; border: 0; border-radius: 14px; padding: 14px; min-height: 52px; color: #fff; cursor: pointer; background: linear-gradient(90deg, var(--t1), var(--t2)); text-shadow: 0 1px 2px #0006; }
.save:disabled { opacity: .6; cursor: wait; }

/* 最近の 記録 */
.log { display: grid; gap: 8px; list-style: none; margin: 0; padding: 0; }
.log li { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; font-size: 13px; }
.log li.empty { display: block; color: var(--muted); }
.swatch { width: 34px; height: 34px; border-radius: 10px; }
.log .sub { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ---- フェーズ2：画面の切りかえ・カレンダー・設定 ---- */
:root { --danger: #c0392b; --mark: #e0457b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --danger: #ff8a80; } }
:root[data-theme="dark"] { --danger: #ff8a80; }

.view { display: grid; gap: 16px; }
.head-right { display: flex; align-items: center; gap: 10px; }

/* 小さいボタンと、横いっぱいのボタン */
.small-btn, .settings-btn { font: inherit; font-size: 13px; color: var(--fg); background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; min-height: 36px; cursor: pointer; }
.small-btn:disabled { opacity: .35; cursor: default; }
.settings-btn { position: relative; }
.settings-btn[aria-current="page"] { border-color: var(--fg); }
.mark-dot { position: absolute; top: -3px; right: -3px; width: 10px; height: 10px; border-radius: 50%; background: var(--mark); border: 2px solid var(--card); }
.action { font: inherit; font-size: 15px; color: var(--fg); background: var(--chip); border: 1px solid var(--line); border-radius: 12px; padding: 12px; min-height: 48px; cursor: pointer; }
.action.danger { color: var(--danger); }

.day-banner { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 16px; }
.auto { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
input[type=date] { -webkit-appearance: none; appearance: none; display: block; min-height: 42px; }

/* お知らせ：下のタブの少し上に出る */
.toast { position: fixed; z-index: 3; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom, 0px)); max-width: calc(100% - 32px); margin: 0; padding: 8px 16px; border-radius: 999px; background: var(--fg); color: var(--bg); font-size: 13px; text-align: center; box-shadow: 0 4px 16px #0003; }

/* 下のタブ */
.tabs { position: fixed; z-index: 2; left: 0; right: 0; bottom: 0; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--card); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-top: 1px solid var(--line); padding: 0 max(8px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(8px, env(safe-area-inset-left, 0px)); }
.tabs button { font: inherit; font-size: 14px; color: var(--muted); background: none; border: 0; border-top: 3px solid transparent; min-height: 56px; cursor: pointer; }
.tabs button[aria-current="page"] { color: var(--fg); border-top-color: var(--t1); }

/* カレンダー */
.cal-head { display: flex; justify-content: space-between; align-items: center; }
.cal-title { font-size: 17px; letter-spacing: .04em; }
.cal-card { padding: 16px 12px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; touch-action: pan-y; }
.wd { text-align: center; font-size: 12px; color: var(--muted); }
.wd.sun { color: #d0506a; }
.wd.sat { color: #4a74d0; }
.day { position: relative; aspect-ratio: 1 / 1.2; min-width: 0; font: inherit; color: var(--fg); background: var(--chip); border: 2px solid transparent; border-radius: 8px; padding: 2px 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 1px; overflow: hidden; }
.day .num { font-size: 13px; line-height: 1.4; }
.day .poke { font-size: 9px; letter-spacing: -.04em; line-height: 1.2; width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.day.filled { color: #fff; text-shadow: 0 1px 2px #0007; }
.day.is-today { border-color: var(--fg); }
.day.is-selected { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--fg); }
.day:disabled { opacity: .35; cursor: default; }
.day .period { position: absolute; top: 3px; right: 3px; width: 7px; height: 7px; border-radius: 50%; background: var(--mark); border: 1px solid #fff; }

.cal-detail .kvs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; }
.kv { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.kv span:first-child { color: var(--muted); }
.memo span { font-size: 12px; color: var(--muted); }
.memo p { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
#backupStatus { margin: 0; font-size: 14px; }

/* ---- フェーズ3：グラフ ---- */
/* 線の色：見分けやすさを計算で確かめた青とオレンジ（明るい画面・ダークモードそれぞれ） */
:root { --s1: #2a78d6; --s2: #eb6834; --surface: #ffffff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --s1: #3987e5; --s2: #d95926; --surface: #1f2130; } }
:root[data-theme="dark"] { --s1: #3987e5; --s2: #d95926; --surface: #1f2130; }

.graph-card { padding: 16px 12px; }
/* 週／月 の切りかえ */
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--chip); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { font: inherit; font-size: 15px; color: var(--muted); background: none; border: 0; border-radius: 10px; min-height: 40px; cursor: pointer; }
.seg button[aria-pressed="true"] { color: var(--fg); background: var(--card); box-shadow: 0 1px 3px #0002; }
/* 見る項目のボタン（4つずつ2段） */
.chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.chip { font: inherit; font-size: 14px; color: var(--fg); background: var(--chip); border: 2px solid transparent; border-radius: 10px; min-height: 44px; padding: 4px 2px; cursor: pointer; }
.chip[aria-pressed="true"] { border-color: var(--fg); }

.graph-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.graph-unit { font-size: 15px; }
.legend { display: flex; gap: 12px; font-size: 13px; color: var(--muted); }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .key i { display: inline-block; width: 16px; height: 3px; border-radius: 2px; }
.legend .key i.s1 { background: var(--s1); }
.legend .key i.s2 { background: var(--s2); }
.readout { margin: 0; font-size: 13px; min-height: 1.6em; font-variant-numeric: tabular-nums; }
.graph-area { width: 100%; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.graph-empty { text-align: center; margin: -8px 0 0; }

.chart { display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-family: var(--f-body); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .tick.sun { fill: #d0506a; }
.chart .tick.sat { fill: #4a74d0; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.s1 { stroke: var(--s1); }
.chart .line.s2 { stroke: var(--s2); }
/* 点のまわりの 2px の輪は、カードと同じ色（線と重なっても見えるように） */
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .dot.s1 { fill: var(--s1); }
.chart .dot.s2 { fill: var(--s2); }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; }
.chart .period-col { fill: var(--mark); opacity: .13; }
.chart .band-empty { fill: var(--chip); }
.period-key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--mark); opacity: .35; margin-right: 6px; vertical-align: -1px; }

.nums { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.nums th { text-align: left; font-weight: 400; color: var(--muted); padding: 4px 6px; border-bottom: 1px solid var(--line); }
.nums td { padding: 6px; border-bottom: 1px solid var(--line); }

/* ---- フェーズ4：タブ5つ・タイプ図鑑・つながり発見・気分の言葉 ---- */
.tabs button { font-size: 13px; padding: 0 2px; white-space: nowrap; }
.note { font-size: 12px; color: var(--muted); text-align: center; margin: 0; }

/* タイプ図鑑 */
.zukan-summary { margin: 0; text-align: center; font-size: 15px; }
.donut-box { display: flex; justify-content: center; }
.donut { display: block; max-width: 100%; height: auto; }
.donut .slice { cursor: pointer; }
.donut .slice.on { filter: brightness(1.12); }
.donut-total { fill: var(--fg); font-family: var(--f-body); font-size: 26px; }
.donut-sub { fill: var(--muted); font-family: var(--f-body); font-size: 11px; }
.zukan-readout { text-align: center; }
.z-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.z-cell { font: inherit; color: var(--fg); background: var(--chip); border: 2px solid transparent; border-radius: 12px; padding: 8px 4px; display: grid; gap: 1px; justify-items: center; line-height: 1.3; cursor: pointer; min-width: 0; }
.z-cell .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); margin-bottom: 2px; }
.z-cell b { font-weight: 400; font-size: 14px; }
.z-cell .mood { font-size: 11px; color: var(--muted); max-width: 100%; overflow-wrap: anywhere; text-align: center; }
.z-cell .n { font-size: 15px; font-variant-numeric: tabular-nums; }
.z-cell .prev { font-size: 10px; color: var(--muted); }
.z-cell.on { border-color: var(--c); }
/* まだ出ていないタイプは灰色のまま */
.z-cell.unseen { cursor: default; }
.z-cell.unseen .dot { background: #c9ccd8; }
.z-cell.unseen b, .z-cell.unseen .n { color: var(--muted); }

/* つながり発見 */
.conn-total { margin: 0; font-size: 15px; }
.facts { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.facts li { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; font-size: 14px; line-height: 1.6; }
.facts .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: .5em; }

/* 気分の言葉 */
.mood-list { display: grid; gap: 8px; }
.mood-row { display: grid; grid-template-columns: auto 5.5em 1fr; align-items: center; gap: 8px; color: var(--fg); font-size: 14px; }
.mood-row .dot { width: 10px; height: 10px; border-radius: 50%; }
/* 文が言葉の途中で改行されないよう、言葉の区切りの空白で改行する（長すぎる言葉だけは途中で切る） */
.facts li, .note, .hint { word-break: keep-all; overflow-wrap: anywhere; }
