/*
 * app.css - the components: clock, timer, and the settings sheet.
 * Built on the tokens and HIG-aligned language defined in base.css.
 */

/* Shared numeric readout - system font with tabular figures, tuned tight. */
.readout {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--text);
  margin: 0;
}

/* Clock ---------------------------------------------------------------- */

.clock {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-4);
  text-align: center;
}

.clock__time {
  font-size: clamp(4rem, 20vw, 12rem);
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  white-space: nowrap;
}

/* The AM/PM suffix widens the nowrap line ~15%, which pushes the 12-hour
   clock past the viewport on phone widths; scale the digits down to fit. */
.clock__time:has(.clock__ampm:not([hidden])) {
  font-size: clamp(3.25rem, 18vw, 12rem);
}

/* AM/PM: a small, muted suffix so the digits stay one size in 12h and 24h. */
.clock__ampm {
  font-size: 0.26em;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin-left: 0.4em;
  color: var(--muted);
}

.clock__ampm[hidden] {
  display: none;
}

.clock__date {
  font-size: var(--text-lg);
  color: var(--muted);
  font-weight: 500;
  letter-spacing: -0.01em;
}

.clock__date[hidden] {
  display: none;
}

/* Timer ---------------------------------------------------------------- */

.timer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-5);
  width: 100%;
}

.timer__center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  max-width: 32rem;
}

.timer__label {
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: 0.01em;
  min-height: 1.2em;
}

.timer.is-finished .timer__label {
  color: var(--danger);
}

.timer__time {
  font-size: clamp(3.5rem, 17vw, 8rem);
  background: none;
  border: 0;
  /* Reserve the underline in every state (transparent when read-only) so the
     box never changes height - starting the timer just fades the line out
     instead of removing it and reflowing the text. */
  border-bottom: 2px solid transparent;
  text-align: center;
  width: 100%;
  padding: 0;
  color: inherit;
  transition: border-color var(--dur-1) var(--ease);
}

/* When idle the time doubles as the duration input - the underline is a
   functional cue (editable vs not), so it uses --cue to clear 3:1. */
.timer__time:not([readonly]) {
  cursor: text;
  border-bottom-color: var(--cue);
}

.timer__time:not([readonly]):hover {
  border-bottom-color: var(--muted);
}

/* Editable state: the accent underline IS the focus indicator. The read-only
   states keep the global :focus-visible ring (WCAG 2.4.7). */
.timer__time:not([readonly]):focus {
  outline: none;
  border-bottom-color: var(--accent);
}

/* Forced colors flatten the accent underline to a system color, erasing the
   focus cue - restore a real outline there. */
@media (forced-colors: active) {
  .timer__time:not([readonly]):focus {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }
}

.timer.is-finished .timer__time {
  color: var(--danger);
}

/* Finish is announced by the red numerals, the label, the title, and the
   chime - no looping animation begging for attention. The label gets a single
   quiet entrance, then everything holds still. */
@media (prefers-reduced-motion: no-preference) {
  .timer.is-finished .timer__label {
    animation: finish-in var(--dur-3) var(--ease);
  }
}

@keyframes finish-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

.presets {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-2);
}

.chip {
  position: relative;
  min-height: 2.5rem;
  padding: 0 var(--sp-4);
  border: 1px solid var(--border);
  background: var(--fill);
  color: var(--text);
  border-radius: var(--pill);
  font-weight: 600;
  font-size: var(--text-sm);
  transition:
    background var(--dur-1) var(--ease),
    border-color var(--dur-1) var(--ease),
    transform var(--dur-1) var(--ease),
    opacity var(--dur-1) var(--ease);
}

/* Invisible >=44px hit target - the visual stays compact (HIG-sanctioned). */
.chip::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: max(100%, var(--tap));
  height: max(100%, var(--tap));
}

.chip:hover:not(:disabled) {
  background: var(--fill-strong);
  border-color: var(--border-strong);
}

.chip:active:not(:disabled) {
  transform: scale(0.95);
}

/* Presets apply only while the timer is idle. */
.chip:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.controls {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
}

.btn {
  min-height: var(--tap);
  padding: 0 var(--sp-5);
  border: 1px solid var(--border);
  background: var(--fill);
  color: var(--text);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: var(--text-md);
  letter-spacing: -0.01em;
  transition:
    background var(--dur-1) var(--ease),
    border-color var(--dur-1) var(--ease),
    transform var(--dur-1) var(--ease),
    opacity var(--dur-1) var(--ease);
}

.btn:hover {
  background: var(--fill-strong);
  border-color: var(--border-strong);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Primary CTA: the accent fill with the page background as ink (one accent hue
   per theme - cyan+white in light, yellow+near-black in dark). */
.btn--primary {
  min-width: 9rem;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  box-shadow: var(--shadow-1);
}

.btn--primary:hover {
  background: var(--kumanui-web-hover);
  border-color: var(--kumanui-web-hover);
}

/* Settings sheet ------------------------------------------------------- */

/* Dimming scrim reinforces the modal presentation (HIG). */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(0, 0, 0, 0.32);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--dur-2) var(--ease),
    visibility 0s linear var(--dur-2);
}

.scrim.is-visible {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--dur-2) var(--ease);
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  width: min(23rem, 92vw);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-2);
  /* viewport-fit=cover: the sheet hugs the right screen edge, so it absorbs
     the right inset too (landscape notch), like the app bar does. */
  padding: calc(var(--sp-4) + env(safe-area-inset-top, 0px))
    max(var(--sp-4), env(safe-area-inset-right, 0px))
    calc(var(--sp-4) + env(safe-area-inset-bottom, 0px)) var(--sp-4);
  /* Closed by default: off-screen and inert. Delay the visibility flip so the
     slide-out is still visible when closing. */
  transform: translateX(100%);
  visibility: hidden;
  pointer-events: none;
  transition:
    transform var(--dur-2) var(--ease),
    visibility 0s linear var(--dur-2);
}

.settings-panel.is-open {
  transform: none;
  visibility: visible;
  pointer-events: auto;
  transition: transform var(--dur-2) var(--ease);
}

.settings-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
}

.settings-panel__head h2 {
  font-size: var(--text-lg);
}

/* Grouped inset list - rows separated by hairlines, comfortable row height. */
.settings-form {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  min-height: var(--tap);
  padding: var(--sp-2) 0;
}

.field + .field {
  border-top: 1px solid var(--border);
}

.field > label,
.field > .field__label {
  color: var(--text);
  font-weight: 400;
  font-size: var(--text-md);
}

.field input[type="range"] {
  accent-color: var(--accent);
  width: 9rem;
}

/* Theme segmented control - all options visible at once (no dropdown), the
   same visual language as the mode switcher: a track with an accent thumb
   that slides to the chosen segment. Real radios underneath. */
.segmented {
  position: relative;
  isolation: isolate;
  display: flex;
  padding: 3px;
  background: var(--fill);
  border-radius: var(--pill);
}

.segmented::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc((100% - 6px) / 3);
  border-radius: var(--pill);
  background: var(--accent);
  box-shadow: var(--shadow-1);
  transition: transform var(--dur-2) var(--ease);
}

.segmented:has(input[value="light"]:checked)::before {
  transform: translateX(100%);
}

.segmented:has(input[value="dark"]:checked)::before {
  transform: translateX(200%);
}

.segment {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  min-width: 3.25rem;
  padding: 0.3rem 0.5rem;
  border-radius: var(--pill);
  color: var(--muted);
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: color var(--dur-2) var(--ease);
}

.segment:hover {
  color: var(--text);
}

.segment:has(input:checked) {
  color: var(--bg);
}

.segment input {
  position: absolute;
  inset: 0;
  /* Above the label's ::after hit-area pseudo, so pointer hits (and test
     clicks) land on the radio itself - as with the switch input. */
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

/* Invisible >=44px hit target, as on the mode tabs. */
.segment::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: max(100%, var(--tap));
}

.segment:has(input:focus-visible) {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

@media (forced-colors: active) {
  .segmented::before {
    background: Highlight;
  }
  .segment:has(input:checked) {
    color: HighlightText;
  }
}

/* iOS-style switch for booleans. */
.switch {
  position: relative;
  width: 3.25rem;
  height: 1.9375rem;
  flex: none;
}

.switch input {
  position: absolute;
  /* Above .track so the transparent input receives the click, and extended to
     an invisible >=44px hit target while the visual stays compact. */
  z-index: 1;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: max(100%, var(--tap));
  height: max(100%, var(--tap));
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch .track {
  position: absolute;
  inset: 0;
  /* Off-state is a functional cue (which way is the switch?) - use --cue so
     the track clears 3:1 against the sheet background. */
  background: var(--cue);
  border-radius: var(--pill);
  transition: background var(--dur-2) var(--ease);
}

.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(1.9375rem - 4px);
  height: calc(1.9375rem - 4px);
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform var(--dur-2) var(--ease);
}

.switch input:checked + .track {
  background: var(--accent);
}

.switch input:checked + .track::after {
  transform: translateX(calc(3.25rem - 1.9375rem));
}

.switch input:focus-visible + .track {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Forced-colors (Windows High Contrast) strips the background fills and the
   box-shadow, which would leave the track and thumb invisible. Draw the switch
   with system-keyword borders/fills that forced colors preserve, and mark the
   on-state with the active-text color. */
@media (forced-colors: active) {
  .switch .track {
    border: 1px solid CanvasText;
    background: Canvas;
  }
  .switch .track::after {
    background: CanvasText;
  }
  .switch input:checked + .track {
    background: Highlight;
  }
  .switch input:checked + .track::after {
    background: HighlightText;
  }
}
