/* Self-hosted (not a Google Fonts CDN call) so the offline-installable PWA
   (see sw.js) keeps working without network, and nothing flashes in a
   system fallback font on first paint. Both are variable fonts covering
   weight 400-700 in a single file - see fonts/OFL-*.txt for license terms. */
@font-face {
  font-family: 'Pixelify Sans';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/PixelifySans-Variable.woff2') format('woff2');
}

@font-face {
  font-family: 'Quicksand';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/Quicksand-Variable.woff2') format('woff2');
}

/* Design tokens - kept in sync with js/theme.js's DARK/LIGHT objects by
   hand (documented there). Canvas code reads js/theme.js directly since it
   can't cheaply read custom properties every frame; DOM/CSS reads these. */
:root {
  --font-display: 'Pixelify Sans', ui-monospace, monospace;
  --font-body: 'Quicksand', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  --radius: 6px;
  --radius-sm: 4px;
  /* Hard-edged, no-blur "pixel UI" shadow - a deliberate departure from the
     soft blurred drop-shadow that reads as default/templated. */
  --shadow-step: 3px;
  --shadow-color: rgba(20, 12, 8, 0.4);

  /* Light mode - soft daylight cream, its own first-class target, not the
     dark palette inverted. */
  --bg-top: #fbf3e7;
  --bg-bottom: #f6e9d8;
  --surface: #fffbf5;
  --surface-border: rgba(74, 51, 36, 0.16);
  /* Translucent variants for the two panels that float directly on the
     scene canvas (timer card, care panel) - frosted-glass rather than a
     flat opaque card, so the panel visibly takes on the color of whatever
     scene/weather is behind it instead of sitting on top as a separate
     layer. Modals/toasts keep the fully-opaque --surface since they sit on
     a dark scrim, not the raw scene. */
  --panel-bg: rgba(255, 251, 245, 0.5);
  --panel-border: rgba(74, 51, 36, 0.22);
  /* Controls that sit directly on the (frosted, scene-tinted) card need
     their own guaranteed contrast independent of --surface/--panel-bg,
     since the scene behind the card can be anything from a pale daytime
     sky to near-black (see js/weather.js's moonlitNight) - a token tied to
     the *card's* surface would vanish exactly when the scene goes darkest.
     Light theme never actually needs the lift (scenes here stay light), so
     these are subtle; the dark-theme values below do the real work. */
  --panel-control-bg: rgba(74, 51, 36, 0.08);
  --panel-control-bg-hover: rgba(74, 51, 36, 0.16);
  --panel-surface: var(--surface);
  --accent: #d98b32;
  /* Darker than --accent - for foreground use (text/stroke/outline) where
     --accent itself doesn't clear AA against this theme's light
     backgrounds. --accent stays as-is for its background-fill role (paired
     with --on-accent text on top, which already contrasts fine). Equal to
     --accent in dark mode, where --accent already clears AA as foreground. */
  --accent-ink: #945c1b;
  --on-accent: #2a1c10;
  --accent-secondary: #c96a4e;
  --tertiary: #8a6bae;
  --sage: #6b9b69;
  --danger: #c1503b;
  --text-strong: #4a3324;
  --text-soft: #786554;
  --ring-track: rgba(74, 51, 36, 0.12);
  --field-bg: #fff6ea;
}

/* Dark mode - dim-room warm charcoal-plum, built first. Applies when the OS
   prefers dark (and no explicit override is set) or the user has manually
   toggled to dark via data-theme. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-top: #221b24;
    --bg-bottom: #2e2320;
    --surface: #2a2220;
    --surface-border: rgba(232, 163, 61, 0.18);
    --panel-bg: rgba(42, 34, 32, 0.5);
    --panel-border: rgba(232, 163, 61, 0.25);
    /* A flat white-wash lift rather than a theme-hued one: over a scene
       this dark (moonlitNight goes near-#000), a colored translucent wash
       stays dark too (18% amber over black is still nearly black) - only
       an additive light overlay reliably separates the control from
       whatever's behind it, dark scene or darker scene alike. */
    --panel-control-bg: rgba(255, 255, 255, 0.10);
    --panel-control-bg-hover: rgba(255, 255, 255, 0.18);
    --panel-surface: #463a33;
    --accent: #e8a33d;
    --accent-ink: #e8a33d;
    --on-accent: #2a1c10;
    --accent-secondary: #d97757;
    --tertiary: #b08bc7;
    --sage: #7bae7a;
    --danger: #e2664b;
    --text-strong: #f3e9da;
    --text-soft: #c9b8a3;
    --ring-track: rgba(243, 233, 218, 0.14);
    --field-bg: #332921;
  }
}

:root[data-theme="dark"] {
  --bg-top: #221b24;
  --bg-bottom: #2e2320;
  --surface: #2a2220;
  --surface-border: rgba(232, 163, 61, 0.18);
  --panel-bg: rgba(42, 34, 32, 0.5);
  --panel-border: rgba(232, 163, 61, 0.25);
  --panel-control-bg: rgba(255, 255, 255, 0.10);
  --panel-control-bg-hover: rgba(255, 255, 255, 0.18);
  --panel-surface: #463a33;
  --accent: #e8a33d;
  --accent-ink: #e8a33d;
  --on-accent: #2a1c10;
  --accent-secondary: #d97757;
  --tertiary: #b08bc7;
  --sage: #7bae7a;
  --danger: #e2664b;
  --text-strong: #f3e9da;
  --text-soft: #c9b8a3;
  --ring-track: rgba(243, 233, 218, 0.14);
  --field-bg: #332921;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  background: var(--bg-bottom);
  color: var(--text-strong);
}

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

button:focus-visible,
input:focus-visible,
#scene:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: 2px;
}

#scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  cursor: pointer;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

#app {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.card {
  pointer-events: auto;
  margin-top: 36px;
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 2px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: 2px 2px 0 var(--shadow-color);
  padding: 20px 28px 16px;
  min-width: 280px;
  text-align: center;
  transition: padding 0.2s ease, background-color 0.2s ease,
    border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Collapses to just the bare time - hovering (or, on touch devices
   without a persistent :hover, tapping the clock to add the .peek class
   via js/ui.js) reveals the rest temporarily. Rows that leave the layout
   (.tabs/.controls/.session-info) animate via max-height instead of
   display:none so the collapse/expand has something to transition; the
   max-height targets below are each row's measured height plus a small
   buffer, not an arbitrary round number. */
.card.compact {
  padding: 14px 20px;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.card.compact .tabs,
.card.compact .controls,
.card.compact .session-info {
  max-height: 0;
  margin-bottom: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  transition: max-height 0.2s ease, margin-bottom 0.2s ease,
    opacity 0.15s ease;
}

.card.compact .progress-ring {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.card.compact .time-display {
  font-size: 3rem;
  opacity: 0.7;
  transition: font-size 0.2s ease, opacity 0.15s ease;
}

.card.compact:hover,
.card.compact.peek {
  padding: 20px 28px 16px;
  background: var(--panel-bg);
  border-color: var(--panel-border);
  box-shadow: 2px 2px 0 var(--shadow-color);
}

.card.compact:hover .tabs,
.card.compact.peek .tabs {
  max-height: 34px;
  margin-bottom: 14px;
  opacity: 1;
  pointer-events: auto;
}

.card.compact:hover .controls,
.card.compact.peek .controls {
  max-height: 48px;
  margin-bottom: 12px;
  opacity: 1;
  pointer-events: auto;
}

.card.compact:hover .session-info,
.card.compact.peek .session-info {
  max-height: 32px;
  opacity: 1;
  pointer-events: auto;
}

.card.compact:hover .progress-ring,
.card.compact.peek .progress-ring {
  opacity: 1;
}

.card.compact:hover .time-display,
.card.compact.peek .time-display {
  font-size: 2.1rem;
  opacity: 1;
}

.card.compact .ring-wrap {
  margin-bottom: 0;
  transition: margin-bottom 0.2s ease;
}

.card.compact:hover .ring-wrap,
.card.compact.peek .ring-wrap {
  margin-bottom: 14px;
}

.tabs {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 14px;
}

.tab {
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.tab:hover { background: var(--surface-border); }
.tab:active { transform: scale(0.95); }

.tab.active {
  background: var(--accent);
  color: var(--on-accent);
}

.ring-wrap {
  position: relative;
  width: 168px;
  height: 168px;
  margin: 0 auto 14px;
}

.progress-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
  display: block;
}

.progress-ring__bg {
  fill: none;
  stroke: var(--ring-track);
  stroke-width: 8;
}

.progress-ring__fg {
  fill: none;
  stroke: var(--accent-ink);
  stroke-width: 8;
  /* Square, not round, end caps - a small graphic/blocky choice that fits
     the pixel-adjacent direction better than the softer default. */
  stroke-linecap: square;
  stroke-dasharray: 339.292;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.25s linear, stroke 0.3s ease;
}

.time-display {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Quicksand, not the display font: Pixelify Sans draws "5" as a shape
     indistinguishable from "S"/"8" at this size, which made the countdown
     genuinely misreadable (confirmed: "25:00" read as "28:00"). Pixelify
     Sans is a fine display face for headings/labels where misreading a
     glyph has no consequence - it just can't be trusted for the one
     number on screen a user is actually timing themselves against. */
  font-family: var(--font-body);
  font-size: 2.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-strong);
}

.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 12px;
}

.controls button {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 24px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--shadow-color);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.2s ease;
}

.controls button:hover { filter: brightness(1.06); }
.controls button:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 var(--shadow-color);
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}

.btn-secondary {
  /* --panel-surface, not --surface: this button sits on the frosted card,
     which can go as dark as the scene behind it (moonlitNight's near-black
     sky) - --panel-surface is a dedicated, lighter-in-dark-theme token so
     the button stays visibly separate from the card instead of blending
     into it. */
  background: var(--panel-surface);
  color: var(--text-soft);
  border: 2px solid var(--text-soft) !important;
}

.session-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--text-soft);
}

.icon-btn {
  border: none;
  /* A permanent (not just :hover) subtle chip - several of these glyphs
     (gear, fullscreen, compact-toggle) are plain monochrome symbol
     characters some platforms render in a dark/neutral color regardless of
     CSS `color`, so on a near-black scene (see moonlitNight) a fully
     transparent button leaves them essentially invisible until hovered.
     The chip gives them a visible backing at rest, on any scene. */
  background: var(--panel-control-bg);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: background-color 0.2s ease, transform 0.15s ease;
}

#btn-settings {
  font-size: 1.5rem;
}

.icon-btn:hover {
  background: var(--panel-control-bg-hover);
}

.icon-btn:active {
  transform: scale(0.9);
}

.care-panel {
  pointer-events: auto;
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 2px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 12px 16px;
  text-align: center;
  box-shadow: 2px 2px 0 var(--shadow-color);
  max-width: min(420px, 88vw);
}

.pet-name {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text-strong);
  margin-bottom: 6px;
  font-size: 1rem;
}

.care-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 6px;
}

.care-row:last-of-type {
  margin-bottom: 0;
}

.care-row button {
  border: 2px solid var(--text-soft);
  background: var(--field-bg);
  color: var(--text-strong);
  font-family: var(--font-body);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  width: auto;
  box-shadow: 2px 2px 0 var(--shadow-color);
  transition: background-color 0.15s ease, transform 0.08s ease, box-shadow 0.08s ease;
}

.care-row button:hover {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}

.care-row button:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 var(--shadow-color);
}


#toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  color: var(--text-strong);
  border: 2px solid var(--surface-border);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.85rem;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  box-shadow: 2px 2px 0 var(--shadow-color);
  max-width: 260px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast--milestone {
  background: var(--surface);
  color: var(--accent-ink);
  font-weight: 700;
  border: 2px solid var(--accent-ink);
  max-width: 280px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(20, 12, 8, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface);
  border: 3px solid var(--surface-border);
  border-radius: var(--radius);
  padding: 28px 32px;
  width: min(360px, 90vw);
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 5px 5px 0 var(--shadow-color);
}

.modal h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  color: var(--text-strong);
  font-size: 1.2rem;
  font-weight: 600;
}

.modal p {
  color: var(--text-soft);
  font-size: 0.85rem;
  margin: 0 0 16px;
}

.modal label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--text-strong);
  margin-bottom: 10px;
}

.modal label.checkbox {
  justify-content: flex-start;
}

.modal input[type="number"] {
  width: 70px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--text-soft);
  text-align: right;
  background: var(--field-bg);
  color: var(--text-strong);
  font-family: var(--font-body);
}

.modal input[type="text"],
.modal input:not([type]) {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--text-soft);
  margin-bottom: 16px;
  font-size: 0.95rem;
  font-family: var(--font-body);
  background: var(--field-bg);
  color: var(--text-strong);
}

.modal button {
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: var(--font-body);
  font-weight: 700;
  cursor: pointer;
  background: var(--accent);
  color: var(--on-accent);
  margin-top: 4px;
  box-shadow: 2px 2px 0 var(--shadow-color);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.2s ease;
}

.modal button:hover { filter: brightness(1.06); }
.modal button:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 var(--shadow-color);
}

.data-zone {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 2px solid var(--surface-border);
  display: flex;
  gap: 8px;
}

.modal button.btn-ghost-block {
  background: transparent;
  border: 2px solid var(--text-soft) !important;
  color: var(--text-strong);
  box-shadow: none;
}

.modal button.btn-ghost-block:hover {
  background: var(--surface-border);
  filter: none;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  margin-bottom: 18px;
  font-size: 0.85rem;
}

.stats-grid dt {
  color: var(--text-soft);
}

.stats-grid dd {
  margin: 0;
  font-weight: 700;
  color: var(--text-strong);
  text-align: right;
}

.danger-zone {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 2px solid var(--surface-border);
}

.modal p.danger-caption {
  font-size: 0.75rem;
  margin: 0 0 10px;
  line-height: 1.4;
}

.modal button.btn-danger {
  background: transparent;
  border: 2px solid var(--danger) !important;
  color: var(--danger);
  box-shadow: none;
}

.modal button.btn-danger:hover {
  background: var(--danger);
  color: var(--surface);
}

.dev-panel {
  position: fixed;
  bottom: 10px;
  left: 10px;
  z-index: 30;
  background: rgba(20, 12, 8, 0.85);
  color: #fff;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 0.7rem;
  font-family: var(--font-body);
}

.dev-label {
  font-weight: 700;
  color: var(--accent);
  padding-right: 4px;
}

.dev-panel button {
  background: #555;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 0.7rem;
  cursor: pointer;
}

.dev-panel button:hover {
  background: var(--accent);
  color: var(--on-accent);
}

.dev-fps {
  color: var(--accent);
  font-weight: 700;
  padding-left: 4px;
}
