/* ==========================================================================
   Web Clock — design tokens
   ========================================================================== */
:root {
  --paper: #f5f4ef;
  --surface: #fbfaf7;
  --raised: #ffffff;
  --ink: #1f211e;
  --muted: #72766d;
  --faint: #a6a99f;
  --line: #e2e1d9;
  --line-strong: #d3d2c8;
  --inset: #ebeae3;
  --accent: #c2492b;
  --accent-ink: #ffffff;
  --accent-soft: rgba(194, 73, 43, .1);
  --good: #3c8a5a;
  --shadow-sm: 0 1px 2px rgba(31, 33, 30, .06), 0 1px 1px rgba(31, 33, 30, .04);
  --shadow-md: 0 1px 2px rgba(31, 33, 30, .04), 0 8px 24px -8px rgba(31, 33, 30, .12);
  --shadow-lg: 0 2px 6px rgba(31, 33, 30, .06), 0 24px 64px -16px rgba(31, 33, 30, .28);

  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Geometry: every control is a pill (radius = height / 2).
     Containers are concentric: outer radius = inner radius + padding. */
  --control-size: 44px;
  --field-size: 48px;
  --pill: 999px;
  --control-radius: var(--pill);
  --card-pad: 16px;
  --card-radius: calc(40px / 2 + var(--card-pad)); /* 40px header controls + 16px inset = 36px */
  --action-gap: 12px;
  --content: 880px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: light;
}

body.dark {
  --paper: #141614;
  --surface: #1b1d1a;
  --raised: #2a2d29;
  --ink: #efeee8;
  --muted: #9b9e94;
  --faint: #686b63;
  --line: #2a2d28;
  --line-strong: #3a3e37;
  --inset: #1f221e;
  --accent: #f08b6b;
  --accent-ink: #1a1310;
  --accent-soft: rgba(240, 139, 107, .12);
  --good: #7cc597;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, .25), 0 8px 24px -8px rgba(0, 0, 0, .5);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, .3), 0 24px 64px -16px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

/* ==========================================================================
   Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100svh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -.005em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: background-color .3s var(--ease), color .3s var(--ease);
}
::selection { background: var(--accent-soft); color: var(--ink); }
button, input, select { font: inherit; color: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
h1, h2 { font-family: var(--font-display); font-weight: 600; letter-spacing: -.02em; margin: 0; }
h2 { font-size: 22px; line-height: 1.25; }

/* ==========================================================================
   Buttons
   ========================================================================== */
button {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--control-size);
  padding: 10px 18px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  color: var(--ink);
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background-color .18s var(--ease), border-color .18s var(--ease), color .18s var(--ease), box-shadow .18s var(--ease), transform .12s var(--ease), opacity .18s var(--ease);
}
button:hover { border-color: var(--line-strong); background: var(--surface); }
button:active { transform: scale(.96); }
button:disabled { opacity: .35; cursor: default; transform: none; }
button.primary { background: var(--ink); border-color: var(--ink); color: var(--paper); box-shadow: var(--shadow-md); }
button.primary:hover { background: var(--ink); opacity: .88; }
button.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

button.icon-button {
  flex-shrink: 0;
  width: var(--control-size);
  height: var(--control-size);
  min-width: var(--control-size);
  padding: 0;
}
button.icon-button { border-radius: 50%; }
button.icon-button.with-label { width: auto; padding: 0 20px 0 16px; border-radius: var(--pill); }
.icon-button svg { display: block; width: 20px; height: 20px; flex-shrink: 0; pointer-events: none; }

/* Quiet buttons: icon actions that sit inside content */
.ghost,
.header-actions button,
.row-right button,
.timer-remove,
.close {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--muted);
}
.ghost:hover,
.header-actions button:hover,
.row-right button:hover,
.timer-remove:hover { background: var(--inset); border-color: transparent; color: var(--ink); }
.row-right button[data-remove]:hover,
.row-right button[data-delete]:hover,
.timer-remove:hover { color: var(--accent); background: var(--accent-soft); }

/* ==========================================================================
   Header & navigation
   ========================================================================== */
header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  max-width: 1280px;
  height: 72px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 40px);
}
.header-actions { display: flex; align-items: center; gap: 4px; }

nav {
  display: flex;
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 12px auto 0;
  padding: 4px;
  gap: 2px;
  background: var(--inset);
  border-radius: var(--pill);
  box-shadow: inset 0 0 0 1px var(--line);
}
nav a {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 18px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
  transition: color .2s var(--ease), background-color .2s var(--ease), box-shadow .2s var(--ease);
}
nav a:hover { color: var(--ink); }
nav a.active { color: var(--ink); background: var(--raised); box-shadow: var(--shadow-md); }

/* ==========================================================================
   Layout
   ========================================================================== */
main {
  min-height: calc(100svh - 160px);
  max-width: calc(var(--content) + 2 * clamp(16px, 5vw, 48px));
  margin: 0 auto;
  padding: clamp(40px, 7vh, 72px) clamp(16px, 5vw, 48px) 64px;
}
.hero { text-align: center; }
.subtle { color: var(--muted); line-height: 1.6; }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 24px;
}
.section-head h2 { font-size: 28px; }
.section-head .count { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-sm);
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 56px 24px;
  text-align: center;
  color: var(--muted);
}
.empty strong { color: var(--ink); font-weight: 600; font-size: 16px; }

/* ==========================================================================
   Numerals
   ========================================================================== */
.clock-digits,
.digits,
.world-time {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
.clock-digits,
.digits { font-weight: 300; letter-spacing: -.045em; line-height: 1; }
.sep { color: var(--faint); margin: 0 .01em; position: relative; top: -.06em; }

/* ==========================================================================
   Clock
   ========================================================================== */
.clock-hero {
  display: grid;
  place-content: center;
  min-height: calc(100svh - 300px);
}
.clock-digits {
  margin: 0;
  font-size: clamp(76px, 17vw, 248px);
  white-space: nowrap;
}
.seconds { color: var(--accent); }
.period {
  font-family: var(--font);
  font-size: max(14px, .1em);
  font-weight: 600;
  letter-spacing: .06em;
  margin-left: .35em;
  color: var(--muted);
  vertical-align: .9em;
}
.date { margin: clamp(16px, 3vh, 28px) 0 6px; font-size: clamp(17px, 1.8vw, 22px); font-weight: 500; letter-spacing: -.01em; }
.zone { margin: 0; color: var(--muted); font-size: 14px; }

/* ==========================================================================
   World clock & alarm lists
   ========================================================================== */
.world-list,
.alarm-list {
  --row: 96px;
  --list-pad: 8px;
  padding: var(--list-pad);
  border-radius: calc(var(--row) / 2 + var(--list-pad));
}
.world-row,
.alarm-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: var(--row);
  /* Right inset centres the 44px circle in the pill's end cap. */
  padding: 0 calc((var(--row) - var(--control-size)) / 2) 0 calc(var(--row) / 2 - 12px);
  border-radius: var(--pill);
  transition: background-color .2s var(--ease), opacity .2s var(--ease);
}
.world-row + .world-row::before,
.alarm-row + .alarm-row::before {
  content: "";
  position: absolute;
  top: 0;
  left: calc(var(--row) / 2);
  right: calc(var(--row) / 2);
  height: 1px;
  background: var(--line);
}
.world-row:hover,
.alarm-row:hover { background: var(--raised); box-shadow: var(--shadow-sm); }
.world-row:hover::before, .world-row:hover + .world-row::before,
.alarm-row:hover::before, .alarm-row:hover + .alarm-row::before { opacity: 0; }
.city { font-size: 20px; font-weight: 600; letter-spacing: -.015em; line-height: 1.3; }
.world-meta { margin-top: 2px; font-size: 13px; color: var(--muted); }
.world-time { font-size: 40px; font-weight: 300; letter-spacing: -.035em; line-height: 1; }
.world-time .period { font-size: 12px; vertical-align: 1.5em; margin-left: 6px; }
.row-right { display: flex; align-items: center; gap: var(--action-gap); }
@media (hover: hover) {
  .row-right button { opacity: 0; }
  .world-row:hover .row-right button,
  .alarm-row:hover .row-right button,
  .row-right button:focus-visible { opacity: 1; }
}
.alarm-row.off .world-time,
.alarm-row.off .world-meta { opacity: .45; }

/* ==========================================================================
   Forms
   ========================================================================== */
.form-row { display: flex; align-items: flex-end; flex-wrap: wrap; gap: var(--action-gap); }
label { display: flex; flex-direction: column; gap: 8px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); text-align: left; }
input, select {
  min-height: var(--field-size);
  padding: 0 20px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  color: var(--ink);
  font-size: 16px;
  font-weight: 400;
  letter-spacing: -.005em;
  text-transform: none;
  box-shadow: var(--shadow-sm);
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
input::placeholder { color: var(--faint); }
input:hover, select:hover { border-color: var(--line-strong); }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); outline: none; }
input[type=time] { font-family: var(--font-display); font-size: 20px; font-variant-numeric: tabular-nums; }
input[type=time]::-webkit-calendar-picker-indicator { opacity: .5; cursor: pointer; }
body.dark input[type=time]::-webkit-calendar-picker-indicator { filter: invert(1); }
/* Listbox: 34px pill options inset 6px -> 17 + 6 = 23px corners. */
select[size] { padding: 6px; height: auto; border-radius: 23px; }
select[size] option { padding: 8px 14px; border-radius: var(--pill); }
select[size] option:checked { background: var(--accent-soft) linear-gradient(var(--accent-soft), var(--accent-soft)); color: var(--ink); font-weight: 500; }

.alarm-form { padding: 12px; margin-bottom: 16px; gap: 8px; border-radius: calc(var(--field-size) / 2 + 12px); align-items: center; }
.alarm-form label:nth-child(2) { flex: 1; min-width: 160px; }
.alarm-form input { width: 100%; }
.alarm-form button { min-height: var(--field-size); }

/* Switch */
input[type=checkbox] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex-shrink: 0;
  width: 48px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  margin: 0 4px;
  border: 0;
  border-radius: 999px;
  background: var(--line-strong);
  box-shadow: none;
  cursor: pointer;
  transition: background-color .22s var(--ease);
}
input[type=checkbox]::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
  transition: transform .22s var(--ease);
}
input[type=checkbox]:checked { background: var(--accent); }
input[type=checkbox]:checked::after { transform: translateX(20px); }
input[type=checkbox]:focus { box-shadow: none; }
input[type=checkbox]:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ==========================================================================
   Stopwatch
   ========================================================================== */
.digits { font-size: clamp(64px, 13vw, 176px); margin: 8px 0 40px; white-space: nowrap; }
.digits small { font-size: .38em; letter-spacing: -.02em; color: var(--muted); margin-left: .04em; }

.controls { display: flex; align-items: center; justify-content: center; gap: 20px; }
.controls .icon-button { --control-size: 60px; border-radius: 50%; }
.controls .icon-button svg { width: 22px; height: 22px; }
.controls .icon-button.primary { --control-size: 76px; }
.controls .icon-button.primary svg { width: 26px; height: 26px; }
.controls .icon-button.primary[aria-label^=Pause] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.laps { --row: 48px; --list-pad: 6px; max-width: 560px; margin: 48px auto 0; padding: var(--list-pad); border-radius: calc(var(--row) / 2 + var(--list-pad)); list-style: none; text-align: left; }
.laps:empty { display: none; }
.laps li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 32px;
  align-items: center;
  position: relative;
  height: var(--row);
  padding: 0 calc(var(--row) / 2);
  border-radius: var(--pill);
  font-variant-numeric: tabular-nums;
}
.laps li + li::before { content: ""; position: absolute; top: 0; left: calc(var(--row) / 2); right: calc(var(--row) / 2); height: 1px; background: var(--line); }
.laps li span:first-child { color: var(--muted); font-weight: 500; }
.laps li span:nth-child(3) { color: var(--muted); min-width: 7.5ch; text-align: right; }
.laps small { color: var(--muted); }
.laps li.best span:nth-child(2) { color: var(--good); }
.laps li.worst span:nth-child(2) { color: var(--accent); }

/* ==========================================================================
   Timers
   ========================================================================== */
.timers { text-align: center; }
#timer-list { display: grid; gap: 20px; }
.timer-panel { position: relative; padding: var(--card-pad) var(--card-pad) 36px; border-radius: var(--card-radius); transition: border-color .3s var(--ease); }
.timer-panel.running { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.timer-header { display: flex; align-items: center; justify-content: space-between; gap: var(--action-gap); }
.timer-name {
  width: 260px;
  min-width: 0;
  min-height: 40px;
  padding: 0 16px;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
}
.timer-name:hover { background: var(--inset); border-color: transparent; }
.timer-name:focus { background: var(--raised); }
.timer-remove { --control-size: 40px; border-radius: 50%; }

.timer-digits {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 16px 0 28px;
  font-size: clamp(56px, 11vw, 148px);
  white-space: nowrap;
}
.timer-digits .timer-unit {
  width: 2.15ch;
  min-width: 0;
  min-height: 0;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: var(--pill);
  box-shadow: none;
  color: var(--ink);
  font: inherit;
  letter-spacing: inherit;
  line-height: 1.08;
  text-align: center;
  font-variant-numeric: tabular-nums;
  caret-color: var(--accent);
  transition: background-color .18s var(--ease), color .3s var(--ease);
}
.timer-unit:not([readonly]):hover { background: var(--inset); }
.timer-unit:not([readonly]):focus { background: var(--accent-soft); box-shadow: none; }
.timer-unit[readonly] { cursor: default; }
.timer-digits > span { width: .3em; flex-shrink: 0; color: var(--faint); position: relative; top: -.06em; }
.timer-panel.running .timer-unit { color: var(--ink); }
.timer-panel.done .timer-unit { color: var(--accent); }

.timer-progress { position: absolute; left: var(--card-radius); right: var(--card-radius); bottom: 16px; height: 4px; border-radius: var(--pill); overflow: hidden; background: transparent; }
.timer-panel.running .timer-progress { background: var(--inset); }
.timer-progress span { display: block; height: 100%; border-radius: var(--pill); background: var(--accent); transform-origin: left; transform: scaleX(0); transition: transform .25s linear; }

.presets { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin: 20px 0 0; }
.presets button {
  min-height: 34px;
  padding: 0 14px;
  border-radius: var(--pill);
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  font-size: 13px;
}
.presets button:hover:not(:disabled) { color: var(--ink); background: var(--inset); border-color: var(--line-strong); }

.timers > #add-timer {
  width: 100%;
  min-height: 64px;
  margin-top: 20px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--pill);
  background: transparent;
  box-shadow: none;
  color: var(--muted);
}
.timers > #add-timer:hover { color: var(--ink); border-color: var(--muted); background: var(--surface); }

/* ==========================================================================
   Dialogs
   ========================================================================== */
dialog {
  --dialog-pad: 24px;
  width: min(440px, calc(100% - 32px));
  padding: var(--dialog-pad);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: calc(var(--field-size) / 2 + var(--dialog-pad));
  box-shadow: var(--shadow-lg);
}
dialog[open] { animation: dialog-in .28s var(--ease); }
dialog::backdrop { background: rgba(10, 12, 10, .4); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: fade-in .28s var(--ease); }
dialog h2 { margin: 4px 8px 20px; }
dialog label { padding: 0; }
dialog label > :not(input):not(select) { margin-left: 8px; }
dialog .form-row button { min-height: var(--field-size); }
dialog p { line-height: 1.6; color: var(--muted); }
dialog input, dialog select { width: 100%; }
dialog .form-row { justify-content: flex-end; margin: 24px 0 0; }
#city-error:empty { display: none; }
#city-error { margin: 12px 0 0; color: var(--accent); font-size: 14px; }

#notice { text-align: center; }
#notice::before {
  content: "";
  display: block;
  width: 56px;
  height: 56px;
  margin: 4px auto 16px;
  border-radius: 50%;
  background: var(--accent-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23c2492b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 8a6 6 0 1 1 12 0c0 7 3 9 3 9H3s3-2 3-9'/%3E%3Cpath d='M10.3 21a1.94 1.94 0 0 0 3.4 0'/%3E%3C/svg%3E") center / 26px no-repeat;
  animation: ring 1.4s var(--ease) infinite;
}
#notice h2 { margin: 0; font-size: 24px; line-height: 1.3; overflow-wrap: anywhere; }
#notice p { margin: 8px 0 0; }
.notice-actions { display: flex; gap: 12px; margin-top: 24px; }
#notice .notice-actions .icon-button { flex: 1; width: auto; height: var(--field-size); min-height: var(--field-size); border-radius: var(--pill); }
#notice .notice-actions svg { width: 22px; height: 22px; }

/* ==========================================================================
   Motion
   ========================================================================== */
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes ring {
  0%, 60%, 100% { transform: rotate(0); }
  10%, 30% { transform: rotate(-8deg); }
  20%, 40% { transform: rotate(8deg); }
}

/* ==========================================================================
   Small screens
   ========================================================================== */
@media (max-width: 640px) {
  body { font-size: 14px; }
  header { height: 60px; }
  .header-actions { gap: 0; }
  #fullscreen { display: none; }
  nav { width: calc(100% - 32px); margin-top: 4px; }
  nav a { flex: 1 1 0; min-width: 0; padding: 0 2px; font-size: 13px; min-height: 38px; }
  nav .long { display: none; }
  main { padding: 40px 16px 48px; min-height: calc(100svh - 140px); }
  .clock-hero { min-height: calc(100svh - 260px); }
  .clock-digits { font-size: 17.5vw; }
  .section-head h2 { font-size: 24px; }
  .world-list, .alarm-list { --row: 80px; --list-pad: 6px; }
  .city { font-size: 17px; }
  .world-time { font-size: 30px; }
  .row-right { gap: 4px; }
  .alarm-form label:first-child { flex: 1; }
  .alarm-form label:nth-child(2) { flex-basis: 100%; order: -1; }
  .digits { margin: 16px 0 40px; }
  .controls { gap: 16px; }
  .laps li { gap: 16px; }
  .timer-panel { padding-bottom: 32px; }
  .timer-digits { font-size: clamp(48px, 15vw, 72px); margin: 12px 0 24px; }
  .timer-name { width: 180px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
