:root {
  --dim: #8a8a8a;
  --hint: #4a4a4a;
  --ink-on-white: #1a1a1a;
  --hint-on-white: #9a9a9a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Noto Sans JP", Meiryo, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ---- grid ---- */

#grid {
  display: grid;
  gap: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

#grid[data-count="1"] { grid-template-columns: 1fr; }
#grid[data-count="2"] { grid-template-columns: 1fr 1fr; }
#grid[data-count="3"] { grid-template-columns: 1fr 1fr 1fr; }
#grid[data-count="4"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }

.cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6em;
  background: #000;
  transition: background-color 150ms linear;
  overflow: hidden;
}

.cell.ringing { background: #fff; }

.time {
  font-size: clamp(2rem, 12vmin, 6rem);
  font-weight: 200;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--dim);
  opacity: 0;
  transition: opacity 200ms linear, color 150ms linear;
}

.hint {
  font-size: clamp(0.6rem, 2.6vmin, 0.9rem);
  font-weight: 400;
  letter-spacing: 0.18em;
  line-height: 1;
  color: var(--hint);
  opacity: 0;
  transition: opacity 200ms linear, color 150ms linear;
}

.cell.show-time .time,
.cell.show-hint .hint { opacity: 1; }

.cell.ringing .time { color: var(--ink-on-white); }
.cell.ringing .hint { color: var(--hint-on-white); }

/* ---- settings button ---- */

/* タップ領域は 2.75rem のまま、見た目は中央の丸だけ（環境依存のグリフを使わない） */
#settings-open {
  position: fixed;
  left: max(1rem, env(safe-area-inset-left));
  top: max(1rem, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms linear;
}

/* 黒背景でも白背景（鳴動中）でも見える中間グレーの輪郭のみ */
#settings-open::before {
  content: "";
  display: block;
  width: 1.15rem;
  height: 1.15rem;
  border: 2px solid #8a8a8a;
  border-radius: 30%;
  background: none;
}

#settings-open.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ---- settings panel ---- */

#settings {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  background: #0b0b0b;
  color: #e6e6e6;
  transition: opacity 180ms linear;
}

#settings.hidden {
  opacity: 0;
  pointer-events: none;
}

.panel {
  width: min(28rem, 100%);
  padding: max(1.5rem, env(safe-area-inset-top)) 1.5rem 3rem;
}

.panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.75rem;
}

.panel h1 {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  color: #6e6e6e;
}

#settings-close {
  width: 2.25rem;
  height: 2.25rem;
  margin-right: -0.5rem;
  padding: 0;
  border: 0;
  background: none;
  color: #8a8a8a;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.05rem 0;
  border-bottom: 1px solid #1c1c1c;
}

.label {
  font-size: 0.95rem;
  font-weight: 400;
}

.label small {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.72rem;
  color: #616161;
  letter-spacing: 0.04em;
}

.toggle {
  flex: none;
  width: 3.1rem;
  height: 1.8rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #262626;
  cursor: pointer;
  transition: background-color 150ms linear;
}

.toggle span {
  display: block;
  width: 1.35rem;
  height: 1.35rem;
  margin-left: 0.225rem;
  border-radius: 50%;
  background: #6e6e6e;
  transition: transform 150ms ease, background-color 150ms linear;
}

.toggle[aria-checked="true"] { background: #e6e6e6; }
.toggle[aria-checked="true"] span {
  background: #0b0b0b;
  transform: translateX(1.3rem);
}

.slider {
  flex: none;
  width: 9rem;
  height: 1.8rem;
  margin: 0;
  background: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.slider:disabled {
  opacity: 0.35;
  cursor: default;
}

.slider::-webkit-slider-runnable-track {
  height: 0.25rem;
  border-radius: 999px;
  background: #262626;
}

.slider::-webkit-slider-thumb {
  width: 1.35rem;
  height: 1.35rem;
  margin-top: -0.55rem;
  border: 0;
  border-radius: 50%;
  background: #e6e6e6;
  -webkit-appearance: none;
  appearance: none;
}

.slider::-moz-range-track {
  height: 0.25rem;
  border-radius: 999px;
  background: #262626;
}

.slider::-moz-range-thumb {
  width: 1.35rem;
  height: 1.35rem;
  border: 0;
  border-radius: 50%;
  background: #e6e6e6;
}

.slider:focus { outline: none; }

.slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px #4a4a4a; }
.slider:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px #4a4a4a; }

.segmented {
  display: flex;
  flex: none;
  border-radius: 0.5rem;
  background: #1a1a1a;
  padding: 0.2rem;
}

.segmented button {
  width: 2.4rem;
  padding: 0.4rem 0;
  border: 0;
  border-radius: 0.35rem;
  background: none;
  color: #8a8a8a;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color 150ms linear, color 150ms linear;
}

.segmented button[aria-pressed="true"] {
  background: #e6e6e6;
  color: #0b0b0b;
}

.durations .row:last-child { border-bottom: 0; }

.durations input {
  flex: none;
  width: 5.5rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid #262626;
  border-radius: 0.5rem;
  background: #141414;
  color: #e6e6e6;
  font-size: 0.95rem;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  text-align: right;
  -moz-appearance: textfield;
}

.durations input::-webkit-outer-spin-button,
.durations input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.durations input:focus {
  outline: none;
  border-color: #4a4a4a;
}

.duration-field {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: #6e6e6e;
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0s !important; }
}
