/* ==========================================================================
   uwuapps theme (uwuapps-theme.md section 1)
   ========================================================================== */

/* ---- base ---- */
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  font-family: "Jua", "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

html, body { height: 100%; }
input, textarea { user-select: text; }

:link, :visited { color: var(--brand-ink); }
a:hover { text-decoration: none; }

button {
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
button:disabled { cursor: not-allowed; opacity: 0.6; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---- brand colour tokens (7 swatches) ---- */
:root,
:root[data-color-theme="classic"] {
  --brand: #ccffcc;
  --brand-rgb: 204, 255, 204;
}
:root[data-color-theme="not-green-1"] { --brand: #ffcccc; --brand-rgb: 255, 204, 204; }
:root[data-color-theme="not-green-2"] { --brand: #ccccff; --brand-rgb: 204, 204, 255; }
:root[data-color-theme="not-green-3"] { --brand: #ffffcc; --brand-rgb: 255, 255, 204; }
:root[data-color-theme="not-green-4"] { --brand: #ffccff; --brand-rgb: 255, 204, 255; }
:root[data-color-theme="not-green-5"] { --brand: #ccffff; --brand-rgb: 204, 255, 255; }
:root[data-color-theme="really-light-green"] { --brand: #ffffff; --brand-rgb: 255, 255, 255; }

/* ---- light / dark surface tokens ---- */
:root,
:root[data-mode="light"] {
  --bg: #eef2f0;
  --surface: rgba(255, 255, 255, 0.55);
  --surface-strong: rgba(255, 255, 255, 0.78);
  --surface-border: rgba(255, 255, 255, 0.65);
  --ink: #121815;
  --muted: #5b665f;
  --shadow: 0 10px 30px rgba(20, 40, 30, 0.10);
  --brand-ink: #1f6b3d;
  --ok: #0f7234;
  --warn: #a24b08;
  --busy: #627288;
  --error: #b91c1c;
}

:root[data-mode="dark"] {
  --bg: #0c100e;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-strong: rgba(255, 255, 255, 0.11);
  --surface-border: rgba(255, 255, 255, 0.14);
  --ink: #eef2ef;
  --muted: #9aa7a0;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
  --brand-ink: #bff5cf;
  --ok: #4ade80;
  --warn: #fbbf24;
  --busy: #94a3b8;
  --error: #fa9696;
}

/* Same in both modes: brand tints are pale whatever the mode. */
:root {
  --on-brand: #121815;
  /* Brand-derived fills. Any surface that tracked the brand swatch before
     still tracks it, in both modes. Text on these is always --on-brand. */
  --brand-fill: color-mix(in srgb, var(--brand) 55%, var(--surface-strong));
  --brand-fill-strong: color-mix(in srgb, var(--brand) 75%, var(--surface-strong));
  /* Secondary text on --surface-strong. Plain --muted only reaches 3.6:1
     there in dark mode, since the strong surface lightens the backdrop. */
  --muted-strong: color-mix(in srgb, var(--ink) 70%, transparent);
}

/* flat, static colour derived from theme, no gradients */
body {
  background-color: color-mix(in srgb, var(--brand) 10%, var(--bg));
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* ---- glass primitive ---- */
.glass {
  background: var(--surface);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--surface-border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

/* ---- icon button (theme trigger, modal close) ---- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
  color: var(--ink);
  transition: transform 0.15s ease, background 0.15s ease;
}
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.small { width: 34px; height: 34px; }
.icon-btn.small svg { width: 16px; height: 16px; }

/* ---- modal shell ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(10, 15, 12, 0.35);
  padding: 12px;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease, visibility 0s linear 0s;
}
.modal-backdrop.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, visibility 0s linear 0.18s;
}

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
}

.modal {
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface-strong);
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.18s ease;
}
.modal-backdrop.hidden .modal {
  opacity: 0;
  transform: translateY(14px) scale(0.97);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-head h2 { font-size: 1.1rem; color: var(--brand-ink); }

/* Section labels inside the modal: "Mode", "Brand colour". */
.modal-section-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}

body.modal-open { overflow: hidden; }

/* ---- mode toggle ---- */
.mode-toggle {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface);
}
.mode-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  border-radius: 10px;
  font-size: 0.85rem;
  color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease;
}
.mode-btn svg { width: 16px; height: 16px; }
.mode-btn.active {
  background: var(--brand-fill);
  color: var(--on-brand);
}

/* Time based mode only. Light and dark stay side by side and the third
   spans the row beneath them: two equal columns would put the longer label
   in a box too narrow to read at 320px, and the full width row also signals
   this is a different kind of choice, a rule for picking a mode rather than
   a mode. Omit both rules in an app that ships the two button toggle. */
.mode-btn-wide { grid-column: 1 / -1; }
.mode-note {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ---- swatch grid ---- */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.swatch {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  font-size: 0.78rem;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
/* Ringed in its own colour, plus a containment ring. On a light modal the
   pale swatches reach only 1:1 against the surface on their own, so the
   outer ring is what actually carries the active state, at 3.4:1. */
.swatch.active {
  border-color: var(--swatch-color);
  box-shadow:
    0 0 0 2px var(--swatch-color),
    0 0 0 3px color-mix(in srgb, var(--ink) 50%, transparent);
}
.swatch-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--swatch-color);
  border: 1px solid color-mix(in srgb, var(--ink) 30%, transparent);
  flex-shrink: 0;
}

@media (max-width: 480px) {
  .swatch-grid { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Alarm Clock
   ========================================================================== */

/* Native time picker, select popup and scrollbars follow the mode. */
:root[data-mode="dark"] { color-scheme: dark; }
:root[data-mode="light"] { color-scheme: light; }

::selection {
  background: var(--brand-fill-strong);
  color: var(--on-brand);
}

:focus-visible {
  outline: 2px solid var(--brand-ink);
  outline-offset: 2px;
}

/* ---- update bar (update-bar-spec.md) ---- */
.update-notice {
  background: color-mix(in srgb, var(--brand) 30%, transparent);
  border-bottom: 1px solid var(--surface-border);
  color: var(--ink);
  font-size: 0.875rem;
  animation: update-in 0.2s ease;
  transition: opacity 0.18s ease;
}
.update-notice.hidden { opacity: 0; }

@keyframes update-in {
  from { opacity: 0; transform: translateY(-100%); }
  to { opacity: 1; transform: translateY(0); }
}

.update-notice-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 720px;
  margin: 0 auto;
  padding: 0.5rem 14px;
  /* Under the notch on a phone, where the bar is the topmost thing on screen. */
  padding-top: max(0.5rem, env(safe-area-inset-top));
}

.update-notice p { flex: 1 1 auto; min-width: 0; }
.update-notice .btn { flex: none; padding: 6px 12px; }

/* ---- layout ---- */
.shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--brand-ink);
  display: inline-block;
}

.title {
  letter-spacing: 0.6px;
  font-size: 1.3rem;
}

.accent { color: var(--brand-ink); }

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---- chips (24h switch, volume) ---- */
.switch,
.volume {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--surface-border);
  border-radius: 999px;
  background: var(--surface-strong);
  font-size: 0.85rem;
  color: var(--muted-strong);
}

.switch { cursor: pointer; }

/* Visually hidden rather than display: none, so it stays in the tab order. */
.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

/* ---- on/off track, shared by the 24h switch and each alarm's toggle ---- */
.switch .slider,
.toggle {
  position: relative;
  flex: none;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--ink) 35%, transparent);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.switch .slider::after,
.toggle::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 0.2s ease, background 0.2s ease;
}

.switch input:checked + .slider,
.toggle:checked {
  background: var(--brand-fill-strong);
  border-color: color-mix(in srgb, var(--on-brand) 35%, transparent);
}

.switch input:checked + .slider::after,
.toggle:checked::after {
  background: var(--on-brand);
  transform: translateX(20px);
}

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

.toggle {
  appearance: none;
  cursor: pointer;
}

.volume input[type="range"] {
  width: 110px;
  accent-color: var(--brand-ink);
}

/* ---- buttons ---- */
.btn {
  appearance: none;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.95rem;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
  color: var(--ink);
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px) scale(0.99); }

.btn.primary {
  background: var(--brand-fill);
  color: var(--on-brand);
}
.btn.primary:hover { background: var(--brand-fill-strong); }

.btn.ghost { background: var(--surface); }

.btn.danger {
  background: color-mix(in srgb, var(--error) 14%, transparent);
  border-color: color-mix(in srgb, var(--error) 35%, transparent);
  color: var(--error);
}

/* ---- clock card ---- */
.clock-card { padding: 22px; }

.clock {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.time {
  font-size: clamp(44px, 12vw, 96px);
  letter-spacing: 2px;
  line-height: 1;
  color: var(--ink);
}

.date {
  font-size: 1.05rem;
  color: var(--muted);
  min-height: 1.5em;
}

/* Collapses to nothing when .hidden; the 0fr/1fr row animates the height. */
.ringing {
  display: grid;
  grid-template-rows: 1fr;
  opacity: 1;
  visibility: visible;
  transition: grid-template-rows 0.2s ease, opacity 0.2s ease, visibility 0s linear 0s;
}
.ringing.hidden {
  grid-template-rows: 0fr;
  opacity: 0;
  visibility: hidden;
  transition: grid-template-rows 0.18s ease, opacity 0.18s ease, visibility 0s linear 0.18s;
}

.ringing-inner {
  min-height: 0;
  overflow: hidden;
}

.ringing-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed var(--surface-border);
}

.ringing-label {
  font-size: 1.1rem;
  color: var(--brand-ink);
}

.ringing-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---- composer + list cards ---- */
.composer,
.alarms { padding: 22px; }

.composer h2,
.alarms h2 {
  margin: 0 0 14px;
  font-size: 1.1rem;
  color: var(--brand-ink);
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field > span,
.field legend {
  color: var(--muted);
  font-size: 0.85rem;
}

.field input[type="text"],
.field input[type="time"],
.field input[type="file"],
.field select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--surface-border);
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s ease;
}

.field input:focus-visible,
.field select:focus-visible {
  border-color: var(--brand-ink);
  outline: 2px solid var(--brand-ink);
  outline-offset: 0;
}

.field input::placeholder {
  color: var(--muted-strong);
  opacity: 1;
}

.field input[type="file"] {
  padding: 6px;
  color: var(--muted-strong);
  font-size: 0.85rem;
}

.field input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--surface-border);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.field.days {
  grid-column: 1 / -1;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 10px 12px;
  border: 1px dashed var(--surface-border);
  border-radius: 12px;
}

.field.days legend { padding: 0 4px; }

.field.days label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--ink);
  cursor: pointer;
}

.field.days input { accent-color: var(--brand-ink); }

.actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ---- alarm list ---- */
.alarm-list {
  list-style: none;
  display: grid;
  gap: 10px;
}

.alarm-list.empty { display: none; }

.empty-hint { color: var(--muted); }

.alarm-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  grid-template-areas:
    "time label toggle actions"
    "time days  toggle actions";
  column-gap: 14px;
  row-gap: 2px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--surface-border);
  border-radius: 14px;
  background: var(--surface-strong);
}

.alarm-time {
  grid-area: time;
  font-size: 1.4rem;
  letter-spacing: 0.5px;
}

.alarm-label {
  grid-area: label;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.alarm-days {
  grid-area: days;
  font-size: 0.8rem;
  color: var(--muted-strong);
}

.alarm-item .toggle { grid-area: toggle; }

.alarm-actions {
  grid-area: actions;
  display: flex;
  gap: 8px;
}

/* ---- footer ---- */
.foot {
  color: var(--muted);
  text-align: center;
  font-size: 0.85rem;
  padding: 4px 0 10px;
}

/* Fixed-meaning accent: reads as a heart regardless of brand colour. */
.heart {
  display: inline-flex;
  width: 1em;
  height: 1em;
  vertical-align: -0.125em;
  color: #34c759;
}
.heart svg { width: 100%; height: 100%; }

/* ---- single breakpoint ---- */
@media (max-width: 480px) {
  .shell { padding: 10px; }

  .clock-card,
  .composer,
  .alarms { padding: 16px; }

  .grid { grid-template-columns: 1fr; }

  .volume { flex: 1 1 auto; }
  .volume input[type="range"] { width: 100%; }

  .alarm-item {
    grid-template-columns: 1fr auto auto;
    grid-template-areas:
      "time  toggle actions"
      "label label  label"
      "days  days   days";
  }
}
