/* Mobile-first. Base styles target small screens; min-width queries only add. */

:root {
  color-scheme: dark;
  /* Night sky, blue-indigo */
  --bg1: #0a0920;
  --bg2: #1a114f;
  --bg3: #2c2170;
  --card: rgba(255, 255, 255, 0.05);
  --card-border: rgba(180, 168, 240, 0.28);
  --panel: rgba(26, 17, 79, 0.6);
  --panel-border: rgba(190, 180, 255, 0.16);
  --text: #ece8fb;
  --muted: #a89fd6;
  --accent: #b3a5f2;
  --accent-soft: rgba(179, 165, 242, 0.14);
  --good: #7ee0a3;
  --ok: #f0cd7a;
  --low: #f08a8a;
  /* Per-mode accent: near-white for "go to bed", soft dawn for "wake up" */
  --mode-accent: #e2ddf8;
  --mode-glow: rgba(226, 221, 248, 0.22);
}

body[data-mode="wake"] {
  --mode-accent: #dfb987;
  --mode-glow: rgba(223, 185, 135, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Quicksand", ui-rounded, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: clamp(0.95rem, 0.9rem + 0.4vw, 1.0625rem);
  letter-spacing: 0.01em;
  background: linear-gradient(180deg, var(--bg1) 0%, #140e3d 40%, var(--bg2) 70%, var(--bg3) 100%);
  color: var(--text);
  overflow-x: hidden;
}

/* Stars */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background-image:
    radial-gradient(1.5px 1.5px at 22% 18%, #fff, transparent),
    radial-gradient(1px 1px at 68% 9%, rgba(255, 255, 255, 0.9), transparent),
    radial-gradient(1px 1px at 84% 32%, rgba(255, 255, 255, 0.7), transparent),
    radial-gradient(1.5px 1.5px at 45% 41%, rgba(255, 255, 255, 0.8), transparent),
    radial-gradient(1px 1px at 9% 55%, rgba(255, 255, 255, 0.6), transparent),
    radial-gradient(1px 1px at 33% 74%, rgba(255, 255, 255, 0.5), transparent),
    radial-gradient(1.5px 1.5px at 91% 62%, rgba(255, 255, 255, 0.7), transparent),
    radial-gradient(1px 1px at 57% 88%, rgba(255, 255, 255, 0.4), transparent);
  background-size: 480px 480px, 380px 380px, 320px 320px, 420px 420px, 300px 300px, 360px 360px, 440px 440px, 340px 340px;
}

/* Shooting star: moves along a single rotated axis (vmax) so the angle
   and shape stay identical on every screen size / aspect ratio */
.shooting-star {
  position: fixed;
  top: 14%;
  left: -8%;
  width: clamp(80px, 12vmax, 140px);
  height: 2px;
  z-index: -1;
  pointer-events: none;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.95), transparent);
  opacity: 0;
  transform-origin: left center;
  animation: shoot 9s linear infinite 3s;
}

@keyframes shoot {
  0% {
    transform: rotate(18deg) translateX(0);
    opacity: 0;
  }

  1% {
    opacity: 1;
  }

  10%,
  100% {
    transform: rotate(18deg) translateX(85vmax);
    opacity: 0;
  }
}

/* Mountains: 3 layers of irregular ridgelines from repeating SVG tiles
   with FIXED px size — the shape never deforms with screen size.
   Solid opaque colors, farther = lighter. Tile edges match for seamless repeat. */
.mountains,
.mountains::before,
.mountains::after {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
  pointer-events: none;
  background-repeat: repeat-x;
}

.mountains {
  height: 210px;
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 900 210'><polygon fill='%23453a86' points='0,120 70,55 150,130 240,25 330,105 400,65 480,150 560,45 640,115 720,75 800,140 860,95 900,120 900,210 0,210'/></svg>");
  background-size: 900px 210px;
  background-position: left bottom;
}

.mountains::before {
  content: "";
  height: 150px;
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 700 150'><polygon fill='%232b2166' points='0,80 60,110 130,40 210,100 290,55 360,115 440,35 520,95 600,60 660,105 700,80 700,150 0,150'/></svg>");
  background-size: 700px 150px;
  background-position: 120px bottom;
}

.mountains::after {
  content: "";
  height: 100px;
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 500 100'><polygon fill='%23120c33' points='0,55 50,75 110,30 180,70 250,40 320,80 390,25 450,60 500,55 500,100 0,100'/></svg>");
  background-size: 500px 100px;
  background-position: 60px bottom;
}

main {
  min-height: 100dvh;
  max-width: 64rem;
  margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top)) 1.25rem max(1rem, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(0.75rem, 2.2vh, 1.1rem);
}

/* Title stays attached to the content group; auto margins here and on
   footer split the free space so the group centers vertically */
header {
  margin-top: auto;
  padding-bottom: clamp(0.25rem, 2vh, 1rem);
}

h1 {
  margin: 0;
  text-align: center;
  font-size: clamp(1.5rem, 1.2rem + 2vw, 2rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(179, 165, 242, 0.45);
}

h1 a {
  color: inherit;
  text-decoration: none;
}

/* Settings gear pinned to the viewport corner, out of the content flow */
#settingsBtn {
  position: fixed;
  top: max(1rem, env(safe-area-inset-top));
  right: max(1rem, env(safe-area-inset-right));
  z-index: 10;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border: 1px solid var(--card-border);
  border-radius: 50%;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--accent);
}

.intro {
  /* pull the label toward the toggle it belongs to */
  margin: 0 0 -0.4rem;
  color: var(--text);
  font-size: clamp(0.9rem, 0.85rem + 0.3vw, 1rem);
}

.mode {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.25rem;
  padding: 0.25rem;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: var(--card);
}

.mode button {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.55rem clamp(0.8rem, 3vw, 1.2rem);
  font: inherit;
  font-weight: 600;
  font-size: clamp(0.85rem, 0.8rem + 0.3vw, 0.95rem);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.mode button[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--mode-accent);
  color: var(--text);
}

.time-row {
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 0.5rem;
}

.time-box {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 0.2rem clamp(0.8rem, 4vw, 1.2rem);
  font-size: clamp(1.5rem, 1.2rem + 2.5vw, 2.2rem);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.time-box input {
  font: inherit;
  width: 2.2ch;
  text-align: center;
  color: var(--mode-accent);
  background: transparent;
  border: 0;
  padding: 0;
}

.time-box span {
  color: var(--muted);
}

#ampm {
  font-size: clamp(1rem, 0.9rem + 1.2vw, 1.5rem);
  font-weight: 650;
  padding: 0.2rem 1rem;
  color: var(--mode-accent);
}

.pill {
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 0.55rem 1.4rem;
  font: inherit;
  font-weight: 600;
  font-size: clamp(0.9rem, 0.85rem + 0.3vw, 0.95rem);
  background: var(--card);
  color: var(--accent);
  cursor: pointer;
}

.pill:hover {
  background: var(--accent-soft);
}

.cta {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 0;
  border-radius: 999px;
  padding: 0.65rem 1.6rem;
  font: inherit;
  font-weight: 700;
  font-size: clamp(0.95rem, 0.9rem + 0.3vw, 1rem);
  background: var(--mode-accent);
  color: #17123a;
  cursor: pointer;
  box-shadow: 0 4px 24px var(--mode-glow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
}

.cta:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px var(--mode-glow);
}

.results {
  display: contents;
}

.results.hidden {
  display: none;
}

.lead {
  margin: 0;
  text-align: center;
  color: var(--text);
  font-size: clamp(1.05rem, 1rem + 0.5vw, 1.25rem);
  font-weight: 600;
}

.tip {
  margin: 0;
  max-width: 30rem;
  text-align: center;
  color: var(--muted);
  font-size: clamp(0.8rem, 0.75rem + 0.3vw, 0.9rem);
  line-height: 1.5;
}

.cards {
  align-self: center;
  width: 100%;
  max-width: 22rem;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

/* One shared card design; rating shows only in the time color */
.card {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  padding: 1rem;
  border-radius: 1.25rem;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(10px) saturate(1.2);
  animation: rise 0.45s ease-out backwards;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
}

.card .face {
  line-height: 0;
}

.card .face svg {
  width: clamp(1.4rem, 1.2rem + 1.2vw, 2rem);
  height: auto;
}

.card .time {
  font-size: clamp(1.2rem, 1rem + 1.6vw, 1.8rem);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  color: var(--text);
}

.card .meta {
  font-size: clamp(0.75rem, 0.7rem + 0.3vw, 0.85rem);
  color: #beb5e3;
  line-height: 1.3;
}

/* Rating shows on the face color, time stays white */
.card.good .face {
  color: var(--good);
}

.card.ok .face {
  color: var(--ok);
}

.card.low .face {
  color: var(--low);
}

footer {
  margin-top: auto;
  padding-top: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  /* sits over the mountains — keep text readable */
  text-shadow: 0 1px 10px rgba(8, 6, 26, 0.9);
}

.hint {
  margin: 0;
  text-align: center;
  color: #c4bce8;
  font-size: clamp(0.75rem, 0.7rem + 0.3vw, 0.85rem);
}

.pill-small {
  padding: 0.4rem 1.1rem;
  font-size: clamp(0.8rem, 0.75rem + 0.3vw, 0.85rem);
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  align-self: center;
}

.hidden {
  display: none;
}

/* Dialogs: indigo panel, no pure black anywhere */
dialog {
  border: 1px solid var(--card-border);
  border-radius: 1rem;
  background: linear-gradient(180deg, #251a63, var(--bg2));
  color: var(--text);
  padding: 1.25rem;
  width: min(90vw, 20rem);
}

dialog::backdrop {
  background: rgba(19, 12, 56, 0.55);
  backdrop-filter: blur(4px);
}

dialog h2 {
  margin: 0 0 1rem;
  font-size: 1rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

dialog label {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

dialog select,
dialog input {
  font: inherit;
  color: var(--text);
  background: rgba(10, 9, 32, 0.6);
  border: 1px solid var(--card-border);
  border-radius: 0.6rem;
  padding: 0.55rem 0.7rem;
}

/* About dialog: minimal — centered title, quiet text, ghost button */
#about {
  width: min(90vw, 26rem);
}

#about h2 {
  text-align: center;
  text-transform: none;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
  color: var(--accent);
}

.about-body p {
  margin: 0 0 0.7rem;
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--muted);
}

.about-body strong {
  color: var(--text);
  font-weight: 600;
}

.about-body .about-note {
  font-size: 0.75rem;
}


#settingsClose,
#aboutClose {
  width: 100%;
  border: 0;
  border-radius: 999px;
  padding: 0.6rem;
  font: inherit;
  font-weight: 650;
  background: var(--accent);
  color: #17123a;
  cursor: pointer;
}

/* ghost variant for the about dialog */
#aboutClose {
  background: transparent;
  border: 1px solid var(--card-border);
  color: var(--accent);
}

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

/* ≥40rem: room for 3 cards per row (max 3) */
@media (min-width: 40rem) {
  .cards {
    grid-template-columns: repeat(3, 1fr);
    max-width: 34rem;
  }
}

@media (prefers-reduced-motion: reduce) {

  .card,
  .shooting-star,
  .cta {
    animation: none;
    transition: none;
  }
}

/* Short landscape (phones): keep everything on screen */
@media (max-height: 26rem) {
  main {
    gap: 0.4rem;
    padding-top: max(0.75rem, env(safe-area-inset-top));
  }

  .cards {
    grid-template-columns: repeat(3, 1fr);
  }

  footer {
    display: none;
  }
}
