:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #22252b;
  --muted: #6b6f78;
  --line: #e2ded5;
  --accent: #d6402f;
  --accent-text: #ffffff;
  --live: #1f8a5b;
  --dial-face: #ffffff;
  --dial-tick: #9a9da5;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --surface: #1e2129;
    --text: #eceef2;
    --muted: #9ea3ae;
    --line: #2d313b;
    --accent: #e0533f;
    --live: #47c28b;
    --dial-face: #1e2129;
    --dial-tick: #5f6470;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.top h1 { font-size: 1.4rem; margin: 8px 0; letter-spacing: 0.04em; }
.top-actions { display: flex; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: 0.85rem; text-decoration: none; color: var(--text);
}
.notice {
  background: var(--surface); border-left: 4px solid var(--accent); border-radius: 8px;
  padding: 10px 14px; margin: 8px 0 12px; white-space: pre-wrap;
}

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.stat-label { font-size: 0.72rem; color: var(--muted); }
.stat-value { font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 0.75rem; font-weight: 500; margin-left: 2px; color: var(--muted); }
.stat-live .stat-value { color: var(--live); font-size: 1.5rem; }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.join-bar { font-size: 0.85rem; color: var(--muted); margin: 4px 0 12px; }
.link-btn { background: none; border: none; color: var(--accent); text-decoration: underline; padding: 0; }

.tabs {
  display: grid; grid-template-columns: 1fr 1fr; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin: 16px 0;
}
.tab { border: none; background: none; padding: 10px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--accent); color: var(--accent-text); }

.panel { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.dial-wrap { position: relative; width: min(78vw, 360px); aspect-ratio: 1; }
.dial { width: 100%; height: 100%; display: block; }
.dial-face { fill: var(--dial-face); stroke: var(--line); stroke-width: 2; }
.dial-sector { fill: var(--accent); }
.dial-ticks line { stroke: var(--dial-tick); stroke-width: 1.2; stroke-linecap: round; }
.dial-ticks line.major { stroke-width: 2.4; }
.dial-center {
  position: absolute; inset: 0; margin: auto; width: 46%; height: 46%; border-radius: 50%;
  background: var(--dial-face); display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 0 0 2px var(--line); font-variant-numeric: tabular-nums;
}
.dial-center span { font-size: clamp(1.6rem, 7vw, 2.6rem); font-weight: 700; }
.dial-center small { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

.presets, .adjust { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.presets button, .adjust button {
  min-width: 64px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; font-variant-numeric: tabular-nums;
}
.presets button.on { border-color: var(--accent); color: var(--accent); }
.start {
  background: var(--accent); color: var(--accent-text); border: none; border-radius: 999px;
  padding: 14px 48px; font-size: 1.15rem; font-weight: 700;
}
.ghost { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 12px 24px; }
.sw-big { font-size: clamp(3rem, 16vw, 6rem); font-weight: 700; font-variant-numeric: tabular-nums; margin: 24px 0 0; }
.hint { color: var(--muted); font-size: 0.9rem; text-align: center; margin: 0; }

/* 集中画面（いつも暗い） */
.focus {
  position: fixed; inset: 0; z-index: 10; background: #000; color: #8c8f96;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  --dial-face: #0b0b0d; --line: #1d1f24; --dial-tick: #34363c; --accent: #7a2a22; --muted: #5d6068;
}
.focus-top { width: 100%; display: flex; justify-content: space-between; font-size: 0.9rem; }
.f-live { color: #3f7a5e; }
.focus-body { flex: 1; display: flex; align-items: center; justify-content: center; width: 100%; }
.focus-dial { width: min(80vw, 62vh, 460px); }
.focus .dial-center span { color: #9a9da4; }
.focus-sw { color: #8c8f96; margin: 0; }
.focus-actions { display: flex; gap: 16px; }
.focus-actions button {
  background: #111216; border: 1px solid #23252b; color: #8c8f96; border-radius: 999px;
  padding: 12px 28px; font-size: 1rem;
}
.focus.paused .dial, .focus.paused .focus-sw { opacity: 0.45; }
.warn { color: #b08a4a; font-size: 0.85rem; text-align: center; line-height: 1.6; margin: 8px 0 12px; }
.toast {
  position: absolute; top: 18%; left: 50%; transform: translateX(-50%);
  background: #1a1b20; color: #c9a86a; border: 1px solid #2c2d33; border-radius: 12px;
  padding: 12px 18px; font-size: 1rem; max-width: calc(100% - 32px); text-align: center;
}

/* 終了画面：ゆっくり明るくなる */
.done {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: #000; padding: 16px; animation: brighten 3s ease forwards;
}
@keyframes brighten { from { background: #000; } to { background: var(--bg); } }
.done-card {
  background: var(--surface); color: var(--text); border-radius: 20px; padding: 28px 24px;
  width: min(100%, 420px); text-align: center; display: flex; flex-direction: column; gap: 10px;
  animation: fadein 2s ease 0.6s both;
}
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.done-title { font-size: 1.8rem; font-weight: 800; margin: 0; }
.done-main { font-size: 1.1rem; margin: 6px 0 0; }
.done-main strong { font-size: 1.6rem; color: var(--accent); }
.done-sub { color: var(--muted); margin: 0; }
.done-card .start { margin-top: 12px; align-self: center; }

.dialog {
  border: none; border-radius: 18px; padding: 24px; width: min(calc(100% - 32px), 420px);
  background: var(--surface); color: var(--text);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.dialog h2 { margin: 0 0 12px; font-size: 1.2rem; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.small { font-size: 0.85rem; color: var(--muted); }
.small a { color: var(--accent); }
.dialog input[type="text"] {
  width: 100%; font-size: 1.1rem; padding: 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.dialog-actions .start { padding: 12px 28px; font-size: 1rem; }
.err { color: var(--accent); font-size: 0.9rem; margin: 8px 0 0; }
