:root {
  --blue: #5976ba;
  --blue-light: #8fa6dc;
  --ink: #111;
  --red: #c2305a;
  --page: #f2f3f7;
  --surface: #fff;
  --soft: #e9ebf2;
  --line: #eceef3;
  --muted: #6b7080;
  --shadow: 0 1px 2px rgb(17 17 17 / 0.04), 0 8px 24px rgb(17 17 17 / 0.06);
  --din: "DIN Condensed", "Barlow Condensed", "Roboto Condensed", sans-serif-condensed, "Arial Narrow", sans-serif;
  /* 画面の高さの1%。タイマー画面ではJSが実測して上書きする */
  --vh: 1vh;
}

@supports (height: 1dvh) {
  :root { --vh: 1dvh; }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

/* iPhoneでホーム画面から開くと、ページが画面より短いときに限って、下端にステータスバーと
   同じ高さの描画されない帯ができる。ページを必ずその分だけ長くして、帯が出ないようにする */
html { min-height: calc(100% + env(safe-area-inset-top)); }

/* ダブルタップでの拡大と、引っ張って更新（ラウンド中の誤リロード）を止める */
html { touch-action: manipulation; overscroll-behavior: none; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", YuGothic, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ホーム画面に追加して開くと、時刻や電池の表示がアプリに重なり白文字になる。
   明るい画面でも読めるよう、その部分だけ黒い帯を敷く */
body::before {
  content: ""; position: fixed; z-index: 20; top: 0; left: 0; right: 0;
  height: env(safe-area-inset-top); background: var(--ink);
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; transition: transform 0.12s, background-color 0.15s, opacity 0.15s; }
button:active { transform: scale(0.95); }

.din {
  font-family: var(--din);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* 見出し */
.hd {
  margin: 0 6px 10px;
  font-size: 13px; font-weight: 700; letter-spacing: 0.1em;
  color: var(--muted);
}

body[data-view="home"] #timer,
body[data-view="timer"] #home { display: none; }

.card {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ---------- ホーム ---------- */

#home {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 28px) max(16px, env(safe-area-inset-right)) 150px max(16px, env(safe-area-inset-left));
}

.brand { text-align: center; }
.brand h1 { margin: 0; font-size: 52px; line-height: 1; letter-spacing: 0.16em; padding-left: 0.16em; }
.brand p { margin: 2px 0 0; font-size: 13px; color: var(--blue); letter-spacing: 0.3em; }

.modes {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  margin-top: 26px; padding: 4px;
  background: var(--soft); border-radius: 16px;
}
.modes button {
  height: 46px; border: 0; border-radius: 12px; background: none;
  font-weight: 700; font-size: 15px; color: var(--muted);
}
.modes button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(17 17 17 / 0.12); }
.modes button:disabled { opacity: 0.4; }

#home section { margin-top: 30px; }

.presets { margin-bottom: 12px; }
.presets p { margin: 0 6px 8px; font-size: 13px; color: var(--muted); }
.presets ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.presets li {
  display: flex; align-items: center;
  background: var(--surface); border-radius: 999px; box-shadow: var(--shadow);
}
.presets button { height: 44px; border: 0; background: none; }
.presets button:first-child { padding: 0 4px 0 16px; font-size: 14px; font-weight: 700; }
.presets button:last-child { width: 40px; font-size: 18px; color: #9aa0b0; }
.presets li.on { background: var(--ink); color: #fff; }

.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 64px; padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row span { line-height: 1.4; }

.stepper { display: flex; align-items: center; gap: 2px; }
.stepper button {
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: var(--soft);
  font-size: 22px; font-weight: 600; line-height: 1;
}
.stepper output { width: 78px; text-align: center; font-size: 32px; letter-spacing: 0.02em; padding-top: 0.15em; }

.switch {
  appearance: none; -webkit-appearance: none;
  flex: none; width: 56px; height: 34px; margin: 0;
  border-radius: 17px; background: #cfd3de;
  position: relative; cursor: pointer; transition: background 0.2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 28px; height: 28px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.25);
  transition: transform 0.2s;
}
.switch:checked { background: var(--blue); }
.switch:checked::after { transform: translateX(22px); }

.sound-test {
  min-height: 44px; padding: 0 20px;
  border: 0; border-radius: 999px; background: var(--soft);
  font-weight: 700; font-size: 15px;
}

.add { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.add input {
  flex: 1; min-width: 0; height: 48px; padding: 0 16px;
  border: 2px solid transparent; border-radius: 14px; background: var(--page);
  user-select: text; -webkit-user-select: text;
}
.add input:focus { outline: 0; border-color: var(--blue); background: var(--surface); }
.add button { width: 76px; border: 0; border-radius: 14px; background: var(--ink); color: #fff; font-weight: 700; }

.members, .roster { list-style: none; margin: 0; padding: 0; }
.members li, .roster li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 58px; padding: 0 8px 0 16px;
  border-bottom: 1px solid var(--line);
}
.members li:last-child, .roster li:last-child { border-bottom: 0; }
.members label, .roster label { flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; min-height: 58px; font-weight: 700; }
.members label span, .roster label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

input[type="checkbox"]:not(.switch) {
  appearance: none; -webkit-appearance: none;
  flex: none; width: 26px; height: 26px; margin: 0;
  border: 2px solid #c5c9d6; border-radius: 9px; background: var(--surface);
  position: relative; transition: background 0.15s, border-color 0.15s;
}
input[type="checkbox"]:not(.switch):checked { background: var(--blue); border-color: var(--blue); }
input[type="checkbox"]:not(.switch):checked::after {
  content: ""; position: absolute; left: 7px; top: 2px;
  width: 6px; height: 12px;
  border: solid #fff; border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}
input:not(:checked) + span { color: #9aa0b0; font-weight: 400; }
.del { width: 44px; height: 44px; border: 0; background: none; font-size: 22px; color: #9aa0b0; }

.hint { margin: 10px 6px 0; font-size: 13px; color: var(--muted); line-height: 1.6; }
.est { margin: 14px 6px 0; font-size: 14px; color: var(--muted); text-align: center; }
.notice { margin: 8px 6px 0; font-size: 14px; color: var(--red); text-align: center; }

.start {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; align-items: center; gap: 10px;
  padding: 12px max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 14px) max(16px, env(safe-area-inset-left));
  background: rgb(242 243 247 / 0.82);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border-top: 1px solid rgb(17 17 17 / 0.06);
}
.go {
  flex: 1; max-width: 420px; height: 60px; padding: 0 28px;
  border: 0; border-radius: 999px; background: var(--red); color: #fff;
  font-size: 19px; font-weight: 700; letter-spacing: 0.12em;
  box-shadow: 0 10px 24px rgb(194 48 90 / 0.35);
}
/* キーボードが出ている間は、入力欄に重ならないよう開始ボタンの帯を隠す */
@media (pointer: coarse) {
  body:has(#add-name:focus) .start { display: none; }
}
.go:disabled { background: #c9cdd8; color: #fff; box-shadow: none; }
.ghost { height: 60px; padding: 0 22px; border: 0; border-radius: 999px; background: var(--soft); color: var(--ink); font-weight: 700; }

/* ---------- タイマー ---------- */

body[data-phase="fight"] {
  --bg: #fff; --fg: #111; --acc: var(--blue); --track: #e6e9f1;
  --side-bg: #111; --side-fg: #fff; --side-acc: var(--blue-light);
}
body[data-phase="rest"], body[data-phase="ready"] {
  --bg: #111; --fg: #fff; --acc: var(--blue-light); --track: #ffffff2e;
  --side-bg: #fff; --side-fg: #111; --side-acc: var(--blue);
}
body[data-alert="true"] {
  --bg: var(--red); --fg: #fff; --acc: #fff; --track: #ffffff40;
  --side-bg: #0000003d; --side-fg: #fff; --side-acc: #fff;
}

#timer {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--fg);
  overflow: hidden;
  transition: background-color 0.25s;
  /* タイマー中はピンチでの拡大も止める */
  touch-action: none;
  --fit: 1;
}

/* 背景のやわらかい光 */
.deco {
  position: absolute; pointer-events: none; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--acc) 30%, transparent), transparent 68%);
}
.d1 { width: 110vmin; height: 110vmin; top: -45vmin; left: -45vmin; }
.d2 { width: 80vmin; height: 80vmin; bottom: 10%; right: -45vmin; opacity: 0.6; }

.clock {
  flex: 1; min-height: 0; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  text-align: center;
}
.meta { font-size: clamp(14px, 2.6vmin, 22px); color: var(--acc); }
.meta:not(.din) { font-size: clamp(13px, 2.4vmin, 20px); font-weight: 700; letter-spacing: 0.1em; }

/* いまの状態を示すバッジ */
.clock .hd { margin: 6px 0 0; color: var(--fg); font-size: clamp(15px, 3.4vmin, 28px); letter-spacing: 0.14em; }
.clock .hd span {
  display: inline-block; padding: 0.35em 1.1em 0.35em 1.24em; border-radius: 999px;
  background: color-mix(in srgb, var(--acc) 22%, transparent);
}

.digits {
  font-size: calc(min(62vw, 30 * var(--vh)) * var(--fit));
  line-height: 0.82;
  letter-spacing: 0;
  /* DIN Condensedは字面が上に寄るぶんを下げる */
  padding-top: 0.16em;
  font-variant-numeric: tabular-nums;
}
/* 10:00のように5文字になるときは、横幅に収まるよう小さくする */
.digits[data-long="true"] { font-size: calc(min(48vw, 30 * var(--vh)) * var(--fit)); }
body[data-paused="true"] .digits { opacity: 0.4; }

.bar { width: min(88%, 620px); height: 10px; margin-top: calc(1.2 * var(--vh)); border-radius: 999px; background: var(--track); position: relative; }
.bar i { display: block; height: 100%; border-radius: 999px; background: var(--acc); }
/* 半分の位置の目印 */
.bar b { position: absolute; left: 50%; top: -5px; width: 3px; height: 20px; margin-left: -1px; border-radius: 2px; background: var(--fg); }

.note { min-height: 28px; margin-top: calc(1.2 * var(--vh)); font-size: 14px; opacity: 0.85; }
.note b { display: inline-block; padding: 5px 14px; border-radius: 999px; background: var(--red); color: #fff; }
body[data-alert="true"] .note b { background: #fff; color: var(--red); }

.pair { margin-top: var(--vh); max-width: 100%; }
.lbl { font-size: 13px; font-weight: 700; letter-spacing: 0.1em; }
.pair .lbl { color: var(--acc); font-size: clamp(13px, 2.4vmin, 20px); }
.names { display: flex; flex-direction: column; align-items: center; font-weight: 700; font-size: calc(min(13vw, 6.2 * var(--vh)) * var(--fit)); line-height: 1.25; }
.names span { max-width: 92vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.names span.din { font-size: 1.5em; line-height: 1.1; letter-spacing: 0.04em; padding-top: 0.12em; }
.names em { font-style: normal; font-size: 0.5em; color: var(--acc); line-height: 1; padding-top: 0.2em; }

/* 下の操作パネル。画面の端から少し浮かせる */
.side {
  position: relative;
  display: flex; flex-direction: column; gap: 12px;
  margin: 0 10px max(10px, env(safe-area-inset-bottom));
  padding: 16px 18px;
  border-radius: 30px;
  background: var(--side-bg); color: var(--side-fg);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.18);
  transition: background-color 0.25s, color 0.25s;
}
.queue { min-width: 0; }
.side .lbl { color: var(--side-acc); }
.next { font-weight: 700; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side em { font-style: normal; font-size: 11px; font-weight: 700; margin-left: 8px; padding: 3px 9px; border-radius: 999px; background: var(--red); color: #fff; vertical-align: 2px; }
.after { display: none; }
.after ol { list-style: none; margin: 0; padding: 0; }
.after li { padding: 8px 0; border-bottom: 1px solid color-mix(in srgb, var(--side-fg) 16%, transparent); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 休憩中の縦向きは、下のパネルに次の次を1件だけ出す */
body:not([data-phase="fight"]) .after { display: block; }
body:not([data-phase="fight"]) .after li { border: 0; padding: 0; font-weight: 700; font-size: 18px; }
body:not([data-phase="fight"]) .after li:nth-child(n+2) { display: none; }

.ctrl { display: flex; align-items: center; gap: 12px; flex: none; }
.ctrl button {
  width: 54px; height: 54px; padding: 0; flex: none;
  border: 0; border-radius: 50%;
  background: color-mix(in srgb, var(--side-fg) 12%, transparent);
  display: grid; place-items: center;
}
.ctrl svg { width: 22px; height: 22px; fill: currentColor; }
.ctrl .main {
  width: 92px; height: 92px; margin-left: auto;
  background: var(--red); color: #fff;
  box-shadow: 0 10px 24px rgb(194 48 90 / 0.45);
}
.ctrl .main svg { width: 44px; height: 44px; }
body[data-alert="true"] .ctrl .main { background: #fff; color: var(--red); box-shadow: 0 10px 24px rgb(0 0 0 / 0.25); }

@media (orientation: landscape) {
  #timer { flex-direction: row; }
  .clock { padding: 12px 16px; padding-left: calc(env(safe-area-inset-left) + 16px); }
  .digits { font-size: calc(min(36vw, 52 * var(--vh)) * var(--fit)); }
  .digits[data-long="true"] { font-size: calc(min(30vw, 52 * var(--vh)) * var(--fit)); }
  .ctrl { flex-wrap: wrap; justify-content: space-between; gap: 12px; }
  .ctrl .main { order: 1; width: 100%; height: 76px; margin: 0; border-radius: 999px; }
  .names { flex-direction: row; gap: 0.5em; font-size: calc(min(4.6vw, 9 * var(--vh)) * var(--fit)); }
  .names span { max-width: 26vw; }
  .names em { padding-top: 0.5em; }
  .note { min-height: 0; }
  .side {
    width: 34%; min-width: 220px;
    margin: 10px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) 0;
    padding: 20px;
  }
  .queue { flex: 1; overflow: hidden; }
  .next { font-size: clamp(18px, 2.8vw, 30px); margin-bottom: 14px; white-space: normal; line-height: 1.3; }
  .after, body:not([data-phase="fight"]) .after { display: block; }
  body:not([data-phase="fight"]) .after li { padding: 8px 0; font-size: clamp(16px, 2.2vw, 22px); border-bottom: 1px solid color-mix(in srgb, var(--side-fg) 16%, transparent); }
  body:not([data-phase="fight"]) .after li:nth-child(n+2) { display: block; font-weight: 400; }
}

@media (orientation: landscape) and (max-height: 420px) {
  .after li:nth-child(n+3), body:not([data-phase="fight"]) .after li:nth-child(n+3) { display: none; }
  .side { padding: 12px 16px; border-radius: 24px; gap: 8px; }
  .ctrl { gap: 8px; }
  .ctrl button { width: 44px; height: 44px; }
  .ctrl .main { height: 58px; }
  .next { margin-bottom: 6px; }
}

/* ---------- 対戦表 ---------- */

#sheet {
  position: fixed; inset: 0; z-index: 10;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  background: var(--page); color: var(--ink);
  padding: calc(env(safe-area-inset-top) + 16px) max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 32px) max(16px, env(safe-area-inset-left));
}
#sheet > * { max-width: 620px; margin-left: auto; margin-right: auto; }
#sheet header { display: flex; align-items: center; justify-content: space-between; padding: 4px 0 14px; }
#sheet header .hd { margin: 0 6px; font-size: 20px; color: var(--ink); letter-spacing: 0.08em; }
.close { width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--soft); font-size: 24px; line-height: 1; }
#sheet h3 { margin-top: 28px; margin-bottom: 10px; padding: 0 6px; font-size: 13px; letter-spacing: 0.1em; color: var(--muted); }

.scroll { overflow-x: auto; padding: 14px; background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); }
.matrix { border-collapse: separate; border-spacing: 4px; margin: 0 auto; font-size: 13px; }
.matrix th { font-weight: 700; white-space: nowrap; }
.matrix tr > th:first-child { text-align: right; padding-right: 6px; max-width: 7em; overflow: hidden; text-overflow: ellipsis; }
/* 人数が多くて表を横にスクロールしても、名前の列は残す */
.matrix tr > th:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.matrix td { width: 36px; height: 36px; min-width: 36px; text-align: center; border-radius: 10px; background: var(--soft); color: #fff; font-weight: 700; }
.matrix td.done { background: var(--blue); }
.matrix td.self { background: none; }
.matrix .off, .matrix .off th { color: #aab0bf; }
.matrix tr.off td.done { opacity: 0.45; }

.legend { margin-top: 10px; margin-bottom: 0; text-align: center; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; margin: 0 4px 0 12px; border-radius: 4px; background: #d9dce6; vertical-align: -1px; }
.legend i.done { background: var(--blue); }

.roster { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); overflow: hidden; }
.roster li { padding-right: 16px; }
.count { flex: none; font-size: 14px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { min-height: 48px; padding: 0 20px; border: 0; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow); font-weight: 700; }
.chips button.on { background: var(--blue); color: #fff; }
.apply { display: block; width: 100%; min-height: 58px; margin-top: 16px; border: 0; border-radius: 999px; background: var(--ink); color: #fff; font-weight: 700; }
.apply:disabled { background: #d5d8e0; color: #8a90a0; }

/* ---------- 確認ダイアログ ---------- */

dialog {
  width: min(88vw, 380px); padding: 26px 20px 20px;
  border: 0; border-radius: 26px;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 24px 60px rgb(0 0 0 / 0.3);
}
dialog::backdrop { background: rgb(0 0 0 / 0.5); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
dialog p { margin: 0 0 22px; font-weight: 700; line-height: 1.6; text-align: center; }
dialog div { display: flex; gap: 10px; }
dialog button { flex: 1; min-height: 54px; border: 0; border-radius: 999px; font-weight: 700; }
dialog .ghost { height: auto; padding: 0 12px; }
dialog .solid { background: var(--red); color: #fff; }
