/* 達成感MAX!! — 黒に近い地で、光の霧が燃えて一本の光へ締まっていく。 */
:root {
  --bg: #12151b;
  --ink: #e8ebee;
  --dim: #7f8995;
  --faint: rgba(214, 224, 236, 0.13);
  --line: rgba(214, 224, 236, 0.22);
  --warm: #ffb45e;
  --warm-glow: rgba(255, 170, 80, 0.55);
  --cool: #63d7e9;
  --cool-glow: rgba(90, 215, 235, 0.5);
  --gold: #d8b46a;
  --gold-glow: rgba(232, 190, 110, 0.55);
  --accent: #dfe5ec;
  --accent-glow: rgba(220, 230, 240, 0.35);
  --thin: "Inter Tight", "SF Pro Display", "Helvetica Neue", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --jp: "Noto Sans JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); }
body {
  color: var(--ink);
  font-family: var(--jp);
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
button, a.btn { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; text-decoration: none; }

body[data-phase="work"] { --accent: var(--warm); --accent-glow: var(--warm-glow); }
body[data-phase="rest"] { --accent: var(--cool); --accent-glow: var(--cool-glow); }

/* ---------- 背景の層 ---------- */
#stage2d, #stageGL { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; display: block; }
.tint, .mist, #sweep, #flash { position: fixed; inset: 0; pointer-events: none; }
.tint { z-index: 1; mix-blend-mode: screen; }
.tint::before, .tint::after { content: ""; position: absolute; inset: 0; opacity: 0; transition: opacity 0.9s ease; }
.tint::before { background: radial-gradient(ellipse 90% 60% at 50% 58%, rgba(255, 140, 50, 0.26), rgba(255, 120, 40, 0.06) 55%, transparent 80%); }
.tint::after  { background: radial-gradient(ellipse 90% 60% at 50% 58%, rgba(40, 190, 220, 0.24), rgba(30, 160, 200, 0.06) 55%, transparent 80%); }
body[data-phase="work"] .tint::before { opacity: 1; }
body[data-phase="rest"] .tint::after { opacity: 1; }
.mist {
  z-index: 1;
  background:
    radial-gradient(ellipse 120% 70% at 50% 0%, rgba(170, 190, 215, 0.07), transparent 60%),
    radial-gradient(ellipse 85% 75% at 50% 48%, transparent 50%, rgba(6, 7, 10, 0.72) 100%);
}

/* ---------- 画面 ---------- */
.screen {
  position: fixed; inset: 0; z-index: 2;
  display: none; flex-direction: column; align-items: center;
  padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
}
body[data-screen="home"] #home,
body[data-screen="run"] #run,
body[data-screen="finish"] #finish { display: flex; }
.rig { width: 100%; flex: none; }   /* この中央に上の一本の光が描かれる（場所だけ取る） */
.pyre { width: 100%; flex: 1 1 auto; min-height: 56px; }   /* この下端に光の霧が置かれ、炎が上がる */

.hud { width: 100%; display: flex; justify-content: space-between; align-items: flex-start; flex: none; }
.title {
  font-family: var(--thin); font-weight: 200; font-size: 15px; letter-spacing: 0.42em;
  color: var(--ink); white-space: nowrap;
}
.title .jp { font-family: var(--jp); font-weight: 200; }
.title b { font-weight: 300; color: var(--gold); text-shadow: 0 0 10px var(--gold-glow); }
.cap { font-family: var(--mono); font-weight: 300; font-size: 9px; letter-spacing: 0.18em; color: var(--dim); margin-top: 7px; }
.cap.r { text-align: right; }
.hud-r { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#gear { width: 34px; height: 34px; margin: -8px -8px 0 0; display: grid; place-items: center; color: var(--dim); }
#gear svg { width: 18px; height: 18px; }
.meter {
  display: grid; grid-template-columns: auto auto; column-gap: 12px; row-gap: 3px;
  font-family: var(--mono); font-weight: 300; font-size: 9px; letter-spacing: 0.12em;
}
.meter dt { color: var(--dim); }
.meter dd { color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; }

/* 細い円弧（計器のリング） */
.ring { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; transform: rotate(-90deg); }
.ring circle { fill: none; }
.r-ticks { stroke: var(--faint); stroke-width: 1.4; stroke-dasharray: 0.35 2.2; }
.r-track { stroke: rgba(214, 224, 236, 0.08); stroke-width: 0.6; }
.r-arc {
  stroke: var(--accent); stroke-width: 0.8; stroke-linecap: round;
  stroke-dasharray: 100; stroke-dashoffset: 100;
  filter: drop-shadow(0 0 1.6px var(--accent-glow));
}
.ring.spin { animation: spin 7s linear infinite; }
.ring.spin .r-arc { stroke-dasharray: 22 78; stroke-dashoffset: 0; stroke: rgba(230, 236, 242, 0.55); }
@keyframes spin { to { transform: rotate(270deg); } }

/* ---------- 開いたとき ---------- */
#home .rig { height: 20vh; }
.today {
  position: relative; flex: none;
  width: min(76vw, 38vh); height: min(76vw, 38vh);
  display: grid; place-items: center; margin-top: 3vh;
}
.today-in { text-align: center; line-height: 1; }
.today .lbl { display: block; font-size: 13px; letter-spacing: 0.5em; padding-left: 0.5em; color: var(--dim); }
.today .big {
  display: block; font-family: var(--thin); font-weight: 200; font-variant-numeric: tabular-nums;
  font-size: min(23vw, 12vh); letter-spacing: -0.02em; margin: 10px 0 12px;
  color: #f4f1ea; text-shadow: 0 0 22px rgba(255, 226, 180, 0.35), 0 0 60px rgba(255, 200, 140, 0.18);
}
.home-bottom { width: 100%; margin-top: auto; display: flex; flex-direction: column; align-items: center; gap: 12px; }
#start {
  width: 100%; max-width: 360px; height: 64px;
  border: 1px solid rgba(255, 214, 160, 0.45);
  background: linear-gradient(180deg, rgba(255, 190, 110, 0.10), rgba(255, 190, 110, 0.03));
  box-shadow: 0 0 24px rgba(255, 180, 90, 0.12), inset 0 0 18px rgba(255, 190, 110, 0.06);
  font-size: 17px; font-weight: 300; letter-spacing: 0.6em; color: #ffe7c4;
  position: relative; transition: background 0.2s, box-shadow 0.2s;
}
#start span { padding-left: 0.6em; }
#start::before, #start::after { content: ""; position: absolute; width: 7px; height: 7px; border: 1px solid var(--gold); }
#start::before { left: -4px; top: -4px; border-right: 0; border-bottom: 0; }
#start::after { right: -4px; bottom: -4px; border-left: 0; border-top: 0; }
#start:active { background: rgba(255, 190, 110, 0.2); box-shadow: 0 0 40px rgba(255, 180, 90, 0.3); }
.note { min-height: 12px; font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; color: var(--dim); }
.note.wake:empty { display: none; }
.note.wake { font-family: inherit; letter-spacing: 0.04em; }

/* ---------- 最中（床に置いて遠くから見る） ---------- */
#run .rig { height: 4vh; }
.clock {
  position: relative; flex: none;
  width: min(90vw, 45vh); height: min(90vw, 45vh);
  display: grid; place-items: center; margin-top: 1vh;
}
#runSec {
  font-family: var(--thin); font-weight: 400; font-variant-numeric: tabular-nums;
  font-size: min(56vw, 28vh); line-height: 1; letter-spacing: -0.03em;
  color: #fbf8f2; margin-top: -0.04em;
  text-shadow: 0 0 18px var(--accent-glow), 0 0 56px var(--accent-glow);
  transition: color 0.4s;
}
#runKind {
  position: absolute; bottom: 17%; left: 0; right: 0; text-align: center;
  font-size: 13px; letter-spacing: 0.6em; padding-left: 0.6em; color: var(--accent);
}
#run .r-arc { stroke-width: 1.3; }
#run.last3 #runSec { color: #fff; animation: beat 1s ease-out infinite; }
@keyframes beat { 0% { transform: scale(1.06); text-shadow: 0 0 30px var(--accent), 0 0 80px var(--accent-glow); } 60%, 100% { transform: scale(1); } }
#runSet {
  flex: none; margin-top: 0; margin-bottom: 1.5vh;
  font-family: var(--thin); font-weight: 300; font-variant-numeric: tabular-nums;
  font-size: min(36vw, 18vh); line-height: 1; letter-spacing: 0.02em;
  color: #fbf8f2; text-shadow: 0 0 3px rgba(8, 9, 12, 0.9), 0 0 16px var(--accent-glow);
}
#runSet .of { font-size: 0.42em; font-weight: 200; color: var(--dim); text-shadow: none; margin-left: 0.08em; }
#dots { display: none; }
.instr { width: 100%; max-width: 420px; flex: none; position: relative; }
.timeline { display: flex; gap: 3px; height: 3px; }
.timeline i { display: block; height: 100%; flex: 2 1 0; background: rgba(214, 224, 236, 0.1); }
.timeline i.rest { flex-grow: 1; }
.timeline i.work.done { background: rgba(255, 180, 94, 0.75); }
.timeline i.rest.done { background: rgba(99, 215, 233, 0.7); }
.timeline i.now { background: linear-gradient(90deg, var(--accent) calc(var(--p, 0) * 100%), rgba(214, 224, 236, 0.1) 0); box-shadow: 0 0 6px var(--accent-glow); }
.instr-row { display: flex; justify-content: space-between; align-items: center; margin-top: 9px; font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; color: var(--dim); font-variant-numeric: tabular-nums; }
#quit { font-size: 11px; letter-spacing: 0.2em; color: rgba(214, 224, 236, 0.4); border: 1px solid rgba(214, 224, 236, 0.15); padding: 6px 10px; }

/* ---------- 終わった瞬間 ---------- */
#finish .rig { height: 20vh; }
.fin-body { flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; text-align: center; }
.fin-label { font-size: 12px; letter-spacing: 0.6em; padding-left: 0.6em; color: var(--dim); margin-top: 1vh; }
.count-wrap {
  --ring: min(66vw, 31vh);
  position: relative; width: var(--ring); height: var(--ring);
  display: grid; place-items: center; margin-top: 1.2vh;
}
#finish .r-arc { stroke: #f3e2c2; filter: drop-shadow(0 0 1.8px rgba(255, 220, 170, 0.6)); }
#finCount {
  font-family: var(--thin); font-weight: 200; font-variant-numeric: tabular-nums;
  font-size: calc(var(--ring) * 0.33); line-height: 1; letter-spacing: -0.02em;
  color: #f7f3ea; text-shadow: 0 0 18px rgba(255, 222, 170, 0.35);
  transition: text-shadow 0.6s, color 0.6s;
}
.fin-unit { font-size: 12px; letter-spacing: 0.6em; padding-left: 0.6em; color: var(--dim); margin-top: 1vh; }
#finMsg {
  min-height: 3.6em; max-width: 21em; margin-top: 2.2vh;
  font-size: 15px; line-height: 1.8; letter-spacing: 0.06em; color: #eef0f2;
  opacity: 0; transform: translateY(6px); transition: opacity 1.4s ease 0.35s, transform 1.4s ease 0.35s;
}
.fin-actions { display: flex; gap: 12px; margin-top: auto; padding-top: 12px; opacity: 0; transition: opacity 0.8s ease 0.9s; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 132px; height: 48px; padding: 0 18px;
  border: 1px solid var(--line); font-size: 13px; letter-spacing: 0.3em; color: var(--ink);
}
#post { border-color: rgba(216, 180, 106, 0.6); color: #f3dfb4; box-shadow: 0 0 18px rgba(216, 180, 106, 0.12); }
#post.wait, #done.wait { visibility: hidden; }
#finNote { min-height: 14px; margin-top: 10px; font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; color: var(--dim); }
#finish.pop #finCount { color: #fffdf6; text-shadow: 0 0 22px rgba(255, 226, 170, 0.8), 0 0 70px rgba(255, 190, 120, 0.45); }
#finish.pop .fin-actions { opacity: 1; }
#finMsg.show { opacity: 1; transform: none; }
#finish.milestone #finCount { color: #fff4d6; text-shadow: 0 0 24px var(--gold), 0 0 90px var(--gold-glow); }
#finish.milestone .r-arc { stroke: var(--gold); }
#finish.milestone .fin-label, #finish.milestone .fin-unit { color: var(--gold); }

/* 光の波・閃光 */
#sweep { z-index: 3; opacity: 0; mix-blend-mode: screen;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 228, 180, 0.22) 45%, rgba(255, 250, 235, 0.45) 50%, rgba(160, 235, 245, 0.22) 55%, transparent 70%);
  background-size: 250% 100%; background-position: 130% 0; }
#sweep.go { animation: sweep 1.9s cubic-bezier(.4, 0, .2, 1) forwards; }
@keyframes sweep { 0% { opacity: 1; background-position: 130% 0; } 85% { opacity: 1; } 100% { opacity: 0; background-position: -30% 0; } }
#flash { z-index: 3; opacity: 0; mix-blend-mode: screen; background: radial-gradient(ellipse 70% 45% at 50% 30%, rgba(255, 236, 200, 0.26), transparent 70%); }
#flash.go { animation: flash 1.6s ease-out forwards; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- 設定 ---------- */
dialog {
  margin: auto; border: 1px solid rgba(214, 224, 236, 0.16); border-radius: 0; padding: 22px 20px 18px;
  width: min(340px, calc(100vw - 32px));
  background: #171b22; color: var(--ink); font-family: var(--jp); font-weight: 300;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
dialog::backdrop { background: rgba(6, 8, 12, 0.7); }
dialog h2 { font-size: 13px; font-weight: 300; letter-spacing: 0.5em; margin-bottom: 16px; color: var(--dim); }
dialog label, dialog .row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid rgba(214, 224, 236, 0.08); font-size: 14px;
}
dialog .row span:last-child, dialog output { font-family: var(--mono); font-size: 12px; color: var(--dim); }
dialog output { min-width: 3.2em; text-align: right; }
dialog input[type="number"] {
  width: 90px; font: 15px var(--mono); padding: 6px 8px; text-align: right;
  border: 1px solid rgba(214, 224, 236, 0.18); border-radius: 0; background: #0f1217; color: var(--ink);
}
dialog input[type="range"] { flex: 1; accent-color: var(--gold); }
dialog .acts { display: flex; gap: 10px; margin-top: 18px; }
dialog .acts button { flex: 1; height: 44px; border: 1px solid var(--line); letter-spacing: 0.3em; font-size: 13px; }
dialog #setSave { border-color: rgba(216, 180, 106, 0.6); color: #f3dfb4; }

@media (prefers-reduced-motion: reduce) {
  .ring.spin, #run.last3 #runSec { animation: none; }
}
.keepawake { position: fixed; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0.01; pointer-events: none; }

/* ---------- 記録（直近12か月の月別回数） ---------- */
.hud-btns { display: flex; gap: 2px; margin: -8px -8px 0 0; }
.hud-btns #gear { margin: 0; }
#recBtn { width: 34px; height: 34px; display: grid; place-items: center; color: var(--dim); }
#recBtn svg { width: 19px; height: 19px; }
dialog.records { width: min(420px, calc(100vw - 24px)); padding: 20px 16px 16px; }
.rec-head { display: flex; justify-content: space-between; align-items: baseline; }
.rec-head h2 { margin-bottom: 0; }
.rec-head .cap { margin-top: 0; }
.rec-sum { display: grid; grid-template-columns: repeat(3, 1fr); margin: 18px 0 8px; text-align: center; }
.rec-sum b { display: block; font-family: var(--thin); font-weight: 200; font-size: 34px; line-height: 1; font-variant-numeric: tabular-nums; color: #f4f1ea; }
.rec-sum span { display: block; margin-top: 7px; font-size: 11px; letter-spacing: 0.3em; padding-left: 0.3em; color: var(--dim); }
.rec-sum .now b { color: #ffe7c4; text-shadow: 0 0 16px var(--gold-glow); }
.rec-sum.pop .now b { animation: sumpop 0.9s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes sumpop { 0% { transform: scale(1); } 30% { transform: scale(1.35); color: #fff4d6; text-shadow: 0 0 26px var(--gold), 0 0 60px var(--gold-glow); } 100% { transform: scale(1); } }
.rec-chart {
  --plot: 190px; --lab: 20px;
  position: relative; display: flex; align-items: flex-end; gap: 5px;
  height: calc(var(--plot) + var(--lab) + 22px); margin-top: 14px;
}
.rec-chart .col { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.rec-chart .v { font-family: var(--mono); font-size: 10px; color: var(--dim); margin-bottom: 5px; font-variant-numeric: tabular-nums; }
.rec-chart i {
  display: block; width: 100%; max-width: 22px; height: calc(var(--h) * var(--plot)); min-height: 1px;
  background: linear-gradient(180deg, rgba(232, 235, 238, 0.42), rgba(232, 235, 238, 0.12));
  transition: height 0.75s cubic-bezier(.2, .8, .2, 1) var(--d, 0ms);
}
.rec-chart .m { height: var(--lab); line-height: var(--lab); margin-top: 6px; font-family: var(--mono); font-size: 10px; color: var(--dim); }
.rec-chart .now i { background: linear-gradient(180deg, #ffd08a, rgba(255, 170, 80, 0.35)); box-shadow: 0 0 14px var(--warm-glow); }
.rec-chart .now .v, .rec-chart .now .m { color: #ffe7c4; }
.rec-chart .now.grow i { transition: height 0.7s cubic-bezier(.3, 1.9, .5, 1) 0ms, box-shadow 0.4s; box-shadow: 0 0 26px var(--gold), 0 0 60px var(--warm-glow); background: linear-gradient(180deg, #fff1d0, #ffb45e 60%, rgba(255, 170, 80, 0.4)); }
.rec-chart .now.grow .v { animation: sumpop 0.9s cubic-bezier(.2, 1.6, .4, 1); color: #fff4d6; }
.rec-chart .plus {
  position: absolute; left: 50%; bottom: calc(var(--h, 0) * var(--plot) + var(--lab) + 30px);
  transform: translateX(-50%); opacity: 0; pointer-events: none;
  font-family: var(--thin); font-weight: 300; font-size: 20px; color: var(--gold); text-shadow: 0 0 12px var(--gold-glow);
}
.rec-chart .now.grow .plus { animation: plus 1.6s ease-out forwards; }
@keyframes plus { 0% { opacity: 0; transform: translate(-50%, 18px) scale(0.6); } 20% { opacity: 1; transform: translate(-50%, 0) scale(1.25); } 60% { opacity: 1; transform: translate(-50%, -14px) scale(1); } 100% { opacity: 0; transform: translate(-50%, -34px) scale(1); } }
.rec-chart .avg {
  position: absolute; left: 0; right: 0; bottom: calc(var(--a) * var(--plot) + var(--lab) + 6px);
  border-top: 1px dashed rgba(216, 180, 106, 0.45); pointer-events: none;
}
.rec-legend { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 12px; font-size: 11px; color: var(--dim); }
.rec-legend i { width: 18px; border-top: 1px dashed rgba(216, 180, 106, 0.7); }
@media (prefers-reduced-motion: reduce) { .rec-chart i { transition: none; } }
