/* Kids Timer -- design tokens
   Color: deep slate-blue ground with a warm amber accent (the "clock hand"),
   plus semantic green (time available) and coral (time's up / alarm).
   Type: Nunito for headings/labels (friendly, rounded), IBM Plex Mono with
   tabular numerals for the countdown itself (reads like a real clock/timer).
*/

:root {
  --bg: #eef1f6;
  --bg-grad: radial-gradient(circle at 50% -10%, #dfe7f5 0%, #eef1f6 55%);
  --surface: #ffffff;
  --surface-2: #f5f7fb;
  --border: #dde3ee;
  --text: #1c2333;
  --text-muted: #5b6478;
  --accent: #d97b1f;
  --accent-strong: #b8630f;
  --accent-contrast: #fff8ef;
  --good: #1f9d63;
  --good-bg: #e4f7ee;
  --danger: #d63b3b;
  --danger-bg: #fdeaea;
  --danger-strong: #b52c2c;
  --shadow: 0 20px 45px -25px rgba(28, 35, 51, 0.35);
  --focus-ring: 0 0 0 3px rgba(217, 123, 31, 0.45);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151f;
    --bg-grad: radial-gradient(circle at 50% -10%, #1c2233 0%, #12151f 60%);
    --surface: #1a1e2b;
    --surface-2: #21273a;
    --border: #2c3348;
    --text: #eef1f8;
    --text-muted: #9aa3ba;
    --accent: #f2a039;
    --accent-strong: #ffb85c;
    --accent-contrast: #2a1a04;
    --good: #4ad999;
    --good-bg: #113627;
    --danger: #ff6b6b;
    --danger-bg: #3a1a1a;
    --danger-strong: #ff8a8a;
    --shadow: 0 20px 45px -25px rgba(0, 0, 0, 0.6);
    --focus-ring: 0 0 0 3px rgba(242, 160, 57, 0.5);
  }
}

:root[data-theme="dark"] {
  --bg: #12151f;
  --bg-grad: radial-gradient(circle at 50% -10%, #1c2233 0%, #12151f 60%);
  --surface: #1a1e2b;
  --surface-2: #21273a;
  --border: #2c3348;
  --text: #eef1f8;
  --text-muted: #9aa3ba;
  --accent: #f2a039;
  --accent-strong: #ffb85c;
  --accent-contrast: #2a1a04;
  --good: #4ad999;
  --good-bg: #113627;
  --danger: #ff6b6b;
  --danger-bg: #3a1a1a;
  --danger-strong: #ff8a8a;
  --shadow: 0 20px 45px -25px rgba(0, 0, 0, 0.6);
  --focus-ring: 0 0 0 3px rgba(242, 160, 57, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg-grad), var(--bg);
  color: var(--text);
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input {
  font-family: inherit;
}

.app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.screen {
  width: 100%;
  max-width: 420px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.title {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 800;
  text-wrap: balance;
}

.subtitle {
  margin: -8px 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: center;
}

/* Role picker */
.role-grid {
  display: grid;
  gap: 12px;
}

.role-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  padding: 16px;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}

.role-btn:hover { background: var(--border); }
.role-btn:active { transform: scale(0.98); }
.role-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.role-btn--parent {
  background: var(--surface-2);
  border-style: dashed;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  font-weight: 800;
  font-size: 1rem;
  padding: 14px 20px;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
}

.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary { background: var(--accent); color: var(--accent-contrast); }
.btn--primary:hover:not(:disabled) { filter: brightness(1.05); }

.btn--ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn--ghost:hover { background: var(--surface-2); }

.btn--go { background: var(--good); color: #05271a; flex: 1; padding: 18px; font-size: 1.15rem; }
.btn--stop { background: var(--danger); color: #300; flex: 1; padding: 18px; font-size: 1.15rem; }

.link-btn {
  appearance: none;
  background: none;
  border: none;
  color: var(--text-muted);
  text-decoration: underline;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px;
}

/* PIN entry */
.pin-form {
  display: flex;
  gap: 10px;
}

.pin-form--stacked {
  flex-direction: column;
  gap: 8px;
}

.pin-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 12px;
  padding: 14px;
  font-size: 1.3rem;
  letter-spacing: 0.3em;
  text-align: center;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

.pin-input:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.error {
  color: var(--danger-strong);
  font-size: 0.85rem;
  margin: -6px 0 0;
}

/* Kid clock */
.kid-header, .parent-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.clock {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.clock__time {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 3.4rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
}

.clock--running .clock__time { color: var(--good); }
.clock--empty .clock__time { color: var(--danger); }

.clock__status {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.button-row {
  display: flex;
  gap: 12px;
}

.alarm {
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.alarm__text {
  margin: 0;
  color: var(--danger-strong);
  font-weight: 800;
}

/* Parent dashboard */
.kid-tiles {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.kid-tile {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 18px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.kid-tile__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.kid-tile__name {
  font-weight: 800;
  font-size: 1.1rem;
}

.kid-tile__time {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 1.6rem;
  font-weight: 600;
}

.kid-tile__status {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 10px;
  border-radius: 999px;
  width: fit-content;
}

.status--running { background: var(--good-bg); color: var(--good); }
.status--stopped { background: var(--surface); color: var(--text-muted); border: 1px solid var(--border); }
.status--alarm { background: var(--danger-bg); color: var(--danger-strong); }

.kid-tile__time--negative { color: var(--danger-strong); }

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

.kid-tile__actions .btn {
  padding: 10px 14px;
  font-size: 0.85rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.kid-tile__actions .btn:hover { background: var(--border); }

.kid-tile__actions .btn--reset { color: var(--danger-strong); }

.kid-tile__actions .btn--sub {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger-strong);
}

.kid-tile__actions .btn--sub:hover { filter: brightness(1.05); }

.kid-tile__custom {
  display: flex;
  gap: 8px;
  align-items: center;
}

.custom-minutes-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}

.custom-minutes-input:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.btn--custom {
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 10px 16px;
  font-size: 0.85rem;
  white-space: nowrap;
}

.btn--custom:hover:not(:disabled) { filter: brightness(1.05); }

.text-input {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
}

.text-input:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.parent-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
}

/* Dialog */
.dialog {
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 26px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  max-width: 340px;
  width: calc(100vw - 48px);
}

.dialog::backdrop {
  background: rgba(10, 12, 20, 0.55);
}

.dialog-title {
  margin: 0 0 6px;
  font-size: 1.2rem;
}

.field-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 700;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

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