:root {
  color-scheme: dark;
  --bg: #0e0e0e;
  --idle: #262626;
  --idle-text: #8f8f8f;
  --ready: #2f2f2f;
  --ready-text: #e8e8e8;
  --turn: #e6bd6c; /* 榧（かや）の碁盤・将棋盤の色 */
  --turn-text: #23180a;
  --low: #f08a3c;
  --low-text: #231005;
  --lost: #c62828;
  --lost-text: #ffffff;
  --surface: #1b1b1b;
  --surface-2: #272727;
  --line: #3a3a3a;
  --text: #ececec;
  --muted: #a3a3a3;
  --accent: #e6bd6c;
  --accent-text: #23180a;
  --danger: #ff8a80;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button { font: inherit; color: inherit; cursor: pointer; }
input { -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }

/* ---- 時計 ---- */

.clock {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  gap: 8px;
  padding:
    max(8px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
}

.panel {
  position: relative;
  min-height: 0;
  border-radius: 20px;
  background: var(--idle);
  color: var(--idle-text);
  touch-action: none;
  cursor: pointer;
  transition: background-color 0.12s, color 0.12s;
  overflow: hidden;
}

.face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5vmin;
  padding: 6% 5%;
  container-type: size;
  text-align: center;
}

@media (orientation: portrait) {
  .clock.flip .panel[data-side="0"] .face { transform: rotate(180deg); }
}

@media (orientation: landscape) {
  .clock {
    grid-template-rows: 1fr;
    grid-template-columns: 1fr auto 1fr;
  }
  .controls { flex-direction: column; }
}

.status {
  min-height: 1.3em;
  font-size: 15px;
  font-size: clamp(13px, 6cqh, 30px);
  font-weight: 700;
  line-height: 1.3;
}

.time {
  font-size: 18vmin;
  font-size: min(calc(90cqw / var(--w, 3)), 52cqh);
  font-weight: 500;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.info {
  min-height: 1.3em;
  font-size: 14px;
  font-size: clamp(12px, 5.5cqh, 26px);
  line-height: 1.3;
  opacity: 0.85;
}

.moves {
  position: absolute;
  top: max(10px, 5cqh);
  left: max(14px, 4cqw);
  font-size: clamp(12px, 4.5cqh, 20px);
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

.bar {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: max(10px, 6cqh);
  height: max(5px, 1.6cqh);
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: currentColor;
  opacity: 0.55;
}

.clock[data-status="ready"] .panel { background: var(--ready); color: var(--ready-text); }
.panel.is-turn { background: var(--turn); color: var(--turn-text); }
.panel.is-low { background: var(--low); color: var(--low-text); }
.panel.is-paused { filter: saturate(0.45) brightness(0.72); }
.panel.is-paused .time { animation: blink 1.4s ease-in-out infinite; }
.panel.is-lost { background: var(--lost); color: var(--lost-text); }
.clock[data-status="over"] .panel:not(.is-lost) { color: var(--ready-text); }

@keyframes blink {
  50% { opacity: 0.35; }
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
}

.ctl {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
}

.ctl svg { width: 24px; height: 24px; }
.ctl.primary { width: 60px; height: 60px; background: var(--accent); color: var(--accent-text); }
.ctl.primary svg { width: 28px; height: 28px; }
.ctl:disabled { opacity: 0.3; cursor: default; }
.ctl:not(:disabled):active { transform: scale(0.94); }
#btn-pause[data-icon="play"] .i-pause,
#btn-pause[data-icon="pause"] .i-play { display: none; }

/* ---- 設定 ---- */

dialog {
  border: none;
  padding: 0;
  background: var(--surface);
  color: var(--text);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.65); }

.sheet {
  width: min(560px, calc(100vw - 32px));
  max-width: 100vw;
  max-height: min(860px, calc(100dvh - 32px));
  border-radius: 18px;
}

.sheet[open] { display: flex; flex-direction: column; }

@media (max-width: 600px) {
  .sheet {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
  }
}

.sheet form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.sheet header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px 20px;
  border-bottom: 1px solid var(--line);
}

.sheet h2 { margin: 0; font-size: 20px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
}

.icon-btn svg { width: 22px; height: 22px; }

.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 20px 20px;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.sheet section { margin-top: 22px; }
.sheet h3 { margin: 0 0 10px; font-size: 14px; font-weight: 700; color: var(--muted); }

.summary {
  margin: 16px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(230, 189, 108, 0.12);
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

.summary:empty { display: none; }

.preset-group { display: flex; gap: 10px; align-items: flex-start; }
.preset-group + .preset-group { margin-top: 10px; }
.preset-label { flex: none; width: 2.6em; padding-top: 8px; font-size: 14px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-size: 14px;
}

.chip.selected {
  border-color: var(--accent);
  background: rgba(230, 189, 108, 0.16);
  color: var(--accent);
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-2);
}

.segmented label { position: relative; }

.segmented input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented span {
  display: block;
  padding: 10px 4px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  text-align: center;
}

.segmented input:checked + span { background: var(--accent); color: var(--accent-text); }
.segmented input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 1px; }

.field-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.field-row input {
  width: 5.2em;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 20px;
  text-align: right;
}

.field-row input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.field-row .times { margin: 0 4px; color: var(--muted); }

.hint { margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.hint:empty { display: none; }

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: 12px;
  font-size: 15px;
  line-height: 1.5;
  cursor: pointer;
}

.check input { flex: none; width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--accent); }

.error { margin: 18px 0 0; color: var(--danger); font-weight: 700; }
.error:empty { display: none; }

.sheet footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 20px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.btn {
  min-width: 96px;
  padding: 11px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  font-size: 16px;
  font-weight: 700;
}

.btn.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.btn.small { min-width: 0; margin-top: 12px; padding: 7px 14px; font-size: 14px; }

.confirm {
  width: min(380px, calc(100vw - 32px));
  padding: 22px 20px 16px;
  border-radius: 18px;
}

.confirm p { margin: 0 0 20px; font-size: 16px; line-height: 1.6; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }

.toast {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 10;
  max-width: calc(100vw - 48px);
  padding: 12px 18px;
  border-radius: 12px;
  background: rgba(20, 20, 20, 0.92);
  color: var(--text);
  font-size: 15px;
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
