/*
 * base.css - design tokens, reset, layout shell, and shared primitives.
 *
 * Color comes from Kumanui role variables (assets/kumanui.css); this file maps
 * them to app roles and adds a spacing / type / motion scale. It never touches
 * the raw palette directly.
 *
 * The design language follows Apple's HIG foundations: Clarity (strong type
 * hierarchy, high contrast, tabular numerals), Deference (quiet chrome so the
 * time is the hero), and Depth (subtle materials + purposeful motion). Spacing
 * rides an 8pt grid and interactive targets clear 44px.
 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Author display rules (e.g. .icon-btn { display: inline-grid }) out-specify
   the UA [hidden] rule, so hidden elements would still show. Restore it. */
[hidden] {
  display: none !important;
}

:root {
  /* Color roles on top of Kumanui. */
  --bg: var(--kumanui-web-background);
  --surface: var(--kumanui-web-surface);
  --text: var(--kumanui-web-text);
  --muted: var(--kumanui-web-muted-text);
  --heading: var(--kumanui-web-heading);
  --accent: var(--kumanui-web-accent);
  --border: var(--kumanui-web-border-subtle);
  --border-strong: var(--kumanui-web-border-strong);
  --focus: var(--kumanui-web-focus);
  --danger: var(--kumanui-web-error);

  /* Neutral translucent fills for tracks and hover states - tint follows the
     theme automatically because they are mixed from the muted-text color. */
  --fill: color-mix(in srgb, var(--muted) 12%, transparent);
  --fill-strong: color-mix(in srgb, var(--muted) 20%, transparent);
  --fill-track: color-mix(in srgb, var(--muted) 32%, transparent);
  /* Functional cue: for non-text UI cues that carry meaning (the editable
     underline, the switch off-track) - mixed to clear WCAG 1.4.11's 3:1
     against the page background in both themes. Decorative hairlines stay
     on --border per Kumanui's borderSubtle doctrine. */
  --cue: color-mix(in srgb, var(--muted) 65%, var(--bg));

  /* Type: the platform system stack (SF Pro on Apple), with tabular numerals
     on the readouts so digits never shift width as they tick. */
  --font:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  --text-xs: 0.8125rem;
  --text-sm: 0.9375rem;
  --text-md: 1.0625rem;
  --text-lg: 1.375rem;

  /* Spacing - 8pt grid. */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-8: 3rem;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --pill: 999px;

  /* Motion - an iOS-like ease-out and restrained durations. */
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --dur-1: 140ms;
  --dur-2: 240ms;
  --dur-3: 360ms;

  --shadow-1:
    0 1px 2px rgba(0, 0, 0, 0.06), 0 6px 16px -6px rgba(0, 0, 0, 0.18);
  --shadow-2: 0 12px 48px -16px rgba(0, 0, 0, 0.5);

  --bar-h: 3.5rem;
  --tap: 2.75rem; /* 44px minimum interactive target */
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--text-md);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3 {
  margin: 0;
  color: var(--heading);
  font-weight: 600;
  letter-spacing: -0.01em;
}

button,
input,
select,
textarea {
  /* Form controls don't inherit font by default - keep the whole app, including
     the big timer readout (an <input>), on the system stack. */
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* One consistent, visible focus ring everywhere. */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--sp-2);
  top: -3rem;
  z-index: 40;
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  text-decoration: none;
  transition: top var(--dur-2) var(--ease);
}

.skip-link:focus {
  top: var(--sp-2);
  /* Shadow only while visible - parked off-screen it would bleed a faint arc
     into the top-left corner of the viewport. */
  box-shadow: var(--shadow-1);
}

/* Top bar - a quiet translucent material with a hairline separator. The three
   columns keep the segmented control optically centered whatever flanks it. */
.app-bar {
  flex: none;
  /* viewport-fit=cover: keep the bar's controls clear of the notch/status
     area by absorbing the top safe-area inset into the bar itself. */
  height: calc(var(--bar-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--sp-3);
  padding-inline: max(var(--sp-4), env(safe-area-inset-left))
    max(var(--sp-4), env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}

.brand {
  justify-self: start;
  font-weight: 600;
  font-size: var(--text-md);
  letter-spacing: -0.01em;
  color: var(--heading);
  user-select: none;
}

.app-actions {
  justify-self: end;
  display: flex;
  gap: var(--sp-1);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  transition:
    background var(--dur-1) var(--ease),
    color var(--dur-1) var(--ease),
    transform var(--dur-1) var(--ease);
}

.icon-btn:hover {
  background: var(--fill);
  color: var(--text);
}

.icon-btn:active {
  background: var(--fill-strong);
  transform: scale(0.92);
}

.icon-btn svg {
  width: 1.3rem;
  height: 1.3rem;
}

/* Segmented control - a track with a single accent thumb that slides to the
   selected segment (driven purely by :has(), no JS). */
.modes {
  justify-self: center;
  position: relative;
  isolation: isolate;
  display: flex;
  padding: 3px;
  background: var(--fill);
  border-radius: var(--pill);
}

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

.modes:has(.mode-tab[data-mode="timer"][aria-selected="true"])::before {
  transform: translateX(100%);
}

.mode-tab {
  position: relative;
  z-index: 1;
  flex: 1;
  min-width: 4.5rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.4rem 1rem;
  border-radius: var(--pill);
  font-weight: 600;
  font-size: var(--text-sm);
  text-align: center;
  transition: color var(--dur-2) var(--ease);
}

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

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

.mode-tab[aria-selected="true"] {
  color: var(--bg);
}

/* Forced colors strip the accent thumb + shadow, so the selected tab would be
   indistinguishable. Mark it with the system highlight instead. */
@media (forced-colors: active) {
  .modes::before {
    background: Highlight;
  }
  .mode-tab[aria-selected="true"] {
    color: HighlightText;
  }
}

/* Ultra-narrow phones: tighten the bar so it fits on one line instead of
   overflowing the viewport (the grid's 1fr columns cannot shrink below their
   content). */
@media (max-width: 22.5rem) {
  .app-bar {
    gap: var(--sp-2);
    padding-inline: max(var(--sp-2), env(safe-area-inset-left))
      max(var(--sp-2), env(safe-area-inset-right));
  }

  .mode-tab {
    min-width: 3.5rem;
    padding-inline: var(--sp-2);
  }
}

/* Stage - centers the active mode; the content is the hero. */
#stage {
  flex: 1;
  display: grid;
  place-items: center;
  padding: var(--sp-5) var(--sp-4);
  min-height: 0;
}

/* Skip-link target: focused programmatically, not an interactive control, so
   don't ring the whole stage. */
#stage:focus {
  outline: none;
}

.mode {
  width: 100%;
  max-width: 44rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-6);
}

.mode[hidden] {
  display: none;
}

@media (prefers-reduced-motion: no-preference) {
  .mode:not([hidden]) {
    animation: mode-in var(--dur-2) var(--ease);
  }
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    /* Delays too: the scrim/panel close uses a delayed visibility flip, and an
       invisible scrim must not keep intercepting clicks for that delay. */
    transition-delay: 0s !important;
  }
}
