/* =============================================================================
 *  style.css  —  matched to the original Links page
 *  Serif type, gradient-over-image bg, grayscale icons that wake on hover,
 *  fixed circular dark-mode toggle, 1090px breakpoint, 90%-wide centered body.
 * ===========================================================================*/

:root {
  /* Light mode (original palette) */
  --bg-base: #3a3f8f;
  --wash-a: rgba(95,3,184,0.30);
  --wash-b: rgba(5,4,179,0.30);
  --pattern-opacity: 0.07;
  --text-color: #f7f2f2;
  --link-bg: rgba(255,255,255,0.30);
  --link-border: #ccc;
  --button-bg: #6c7ec5;
  --button-hover: #4a6990;

  /* Aurora blob colors (light) */
  --aur-1: rgba(123,90,221,0.30);
  --aur-2: rgba(6,182,212,0.22);
  --aur-3: rgba(95,110,200,0.28);

  /* Whisper-quiet film grain — hides gradient banding. Shared by both modes. */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");

  --grid-max: 4;
  --gap: 20px;
  --serif: Georgia, "PT Serif", "Times New Roman", serif;
}

body.dark-mode {
  --bg-base: #0f1a2a;
  --wash-a: rgba(61,82,160,0.22);
  --wash-b: rgba(6,182,212,0.10);
  --pattern-opacity: 0.06;
  --text-color: #e6f0ff;
  --link-bg: rgba(42,59,83,0.7);
  --link-border: #375a82;
  --button-bg: #375a82;
  --button-hover: #4b6d94;

  /* Aurora blob colors (dark) */
  --aur-1: rgba(61,82,160,0.42);
  --aur-2: rgba(6,182,212,0.26);
  --aur-3: rgba(108,126,197,0.30);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* text-size-adjust + overflow-x kill the "starts zoomed in" behaviour */
html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  width: 90%;
  min-height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  font-family: var(--serif);
  color: var(--text-color);
  transition: color 0.3s ease;
  overflow-x: hidden;
}

/* Atmospheric wash (+ optional --bg-image set from config) */
/* Drifting aurora + grain (+ optional --bg-image from config, + base) */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    var(--grain) 0 0 / 160px 160px repeat,
    radial-gradient(circle at 30% 32%, var(--aur-1) 0%, transparent 58%) 12% 18% / 135% 135% no-repeat,
    radial-gradient(circle at 70% 68%, var(--aur-2) 0%, transparent 58%) 82% 72% / 135% 135% no-repeat,
    radial-gradient(circle at 55% 28%, var(--aur-3) 0%, transparent 60%) 62% 24% / 140% 140% no-repeat,
    var(--bg-image, none) right bottom / cover no-repeat,
    var(--bg-base);
  animation: aurora-drift 80s ease-in-out infinite;
}

@keyframes aurora-drift {
  0%, 100% { background-position: 0 0, 12% 18%, 82% 72%, 62% 24%, right bottom; }
  50%      { background-position: 0 0, 30% 42%, 60% 54%, 42% 44%, right bottom; }
}

/* Soft botanical sprig — calm, rounded, no eyes or spindles */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: var(--pattern-opacity);
  background-repeat: repeat;
  background-size: 480px 480px;
  background-image: url("data:image/svg+xml;utf8,\
<svg xmlns='http://www.w3.org/2000/svg' width='480' height='480' viewBox='0 0 480 480'>\
<g fill='%239fb4dd' stroke='%239fb4dd' stroke-width='2.4' stroke-linecap='round'>\
<g>\
<path fill='none' d='M240 206 C 232 172 248 132 240 92'/>\
<ellipse cx='221' cy='176' rx='15' ry='7' transform='rotate(-34 221 176)'/>\
<ellipse cx='259' cy='148' rx='15' ry='7' transform='rotate(34 259 148)'/>\
<ellipse cx='223' cy='118' rx='12' ry='6' transform='rotate(-30 223 118)'/>\
<circle cx='240' cy='86' r='4.5'/>\
</g>\
<g transform='rotate(90 240 240)'>\
<path fill='none' d='M240 206 C 232 172 248 132 240 92'/>\
<ellipse cx='221' cy='176' rx='15' ry='7' transform='rotate(-34 221 176)'/>\
<ellipse cx='259' cy='148' rx='15' ry='7' transform='rotate(34 259 148)'/>\
<ellipse cx='223' cy='118' rx='12' ry='6' transform='rotate(-30 223 118)'/>\
<circle cx='240' cy='86' r='4.5'/>\
</g>\
<g transform='rotate(180 240 240)'>\
<path fill='none' d='M240 206 C 232 172 248 132 240 92'/>\
<ellipse cx='221' cy='176' rx='15' ry='7' transform='rotate(-34 221 176)'/>\
<ellipse cx='259' cy='148' rx='15' ry='7' transform='rotate(34 259 148)'/>\
<ellipse cx='223' cy='118' rx='12' ry='6' transform='rotate(-30 223 118)'/>\
<circle cx='240' cy='86' r='4.5'/>\
</g>\
<g transform='rotate(270 240 240)'>\
<path fill='none' d='M240 206 C 232 172 248 132 240 92'/>\
<ellipse cx='221' cy='176' rx='15' ry='7' transform='rotate(-34 221 176)'/>\
<ellipse cx='259' cy='148' rx='15' ry='7' transform='rotate(34 259 148)'/>\
<ellipse cx='223' cy='118' rx='12' ry='6' transform='rotate(-30 223 118)'/>\
<circle cx='240' cy='86' r='4.5'/>\
</g>\
<circle cx='240' cy='216' r='3'/><circle cx='264' cy='240' r='3'/>\
<circle cx='240' cy='264' r='3'/><circle cx='216' cy='240' r='3'/>\
</g></svg>");
}
body.no-pattern::after { display: none; }

/* ---- Header --------------------------------------------------------------- */
#title-btn {
  font-family: var(--serif);
  color: var(--text-color);
  font-size: 72px;
  font-weight: 700;
  text-align: center;
  background: none;
  border: none;
  cursor: pointer;
  margin: 7px 0 0;
  padding: 0;
  width: 100%;
  transition: opacity 0.15s ease;
}
#title-btn:hover { opacity: 0.85; }

/* ---- Dark-mode toggle (fixed circle, original placement) ------------------ */
#theme-btn {
  position: fixed;
  top: 15px;
  right: 15px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--button-bg);
  border: 1px solid var(--link-border);
  color: #fff;
  cursor: pointer;
  z-index: 1000;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
  transition: background-color 0.3s ease, opacity 0.3s ease;
}
#theme-btn:hover { background: var(--button-hover); opacity: 1; }

#loc-btn {
  position: fixed;
  top: 15px;
  right: 63px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--button-bg);
  border: 1px solid var(--link-border);
  color: #fff;
  cursor: pointer;
  z-index: 1000;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
  transition: background-color 0.3s ease, opacity 0.3s ease;
}
#loc-btn:hover { background: var(--button-hover); opacity: 1; }

/* ---- Location modal ------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(2px);
}
.modal-overlay[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 380px;
  background: var(--bg-base);
  color: var(--text-color);
  border: 1px solid var(--link-border);
  border-radius: 12px;
  padding: 22px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.5);
  font-family: var(--serif);
}
.modal h2 { font-size: 22px; margin-bottom: 6px; }
.modal-note { font-size: 13px; opacity: 0.7; margin-bottom: 16px; line-height: 1.4; }
.modal label {
  display: block;
  font-size: 13px;
  opacity: 0.85;
  margin: 10px 0 4px;
}
.modal input {
  width: 100%;
  padding: 9px 11px;
  font-size: 15px;
  font-family: var(--serif);
  color: var(--text-color);
  background: var(--link-bg);
  border: 1px solid var(--link-border);
  border-radius: 7px;
}
.modal input:focus-visible { outline: 2px solid var(--button-bg); outline-offset: 1px; }

.modal-btn {
  font-family: var(--serif);
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 7px;
  border: 1px solid var(--link-border);
  background: var(--link-bg);
  color: var(--text-color);
  cursor: pointer;
  transition: background-color 0.2s ease;
}
.modal-btn:hover { background: var(--button-hover); }
.modal-btn.primary { background: var(--button-bg); }
.modal-btn.primary:hover { background: var(--button-hover); }
.modal-btn.ghost { background: transparent; }
.modal-btn.ghost:hover { background: var(--link-bg); }

#loc-detect { width: 100%; margin-top: 14px; }

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
}
.modal-actions .spacer { flex: 1; }
.modal-msg { font-size: 13px; margin-top: 12px; min-height: 1em; opacity: 0.85; }

/* ---- Shared tile look ----------------------------------------------------- */
.weather, .tile {
  color: var(--text-color);
  border: 1px solid var(--link-border);
  background: var(--link-bg);
  text-align: center;
  box-sizing: border-box;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* ---- Weather strip -------------------------------------------------------- */
.weather {
  display: grid;
  grid-template-columns: repeat(var(--w-cols, 5), 1fr);
  align-items: center;
  justify-items: center;
  gap: 6px 18px;
  margin: 20px 20px 6px;
  padding: 14px 16px;
}
.weather .w {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.4vw;
  white-space: nowrap;
}
.weather .w .ic { font-size: 1.3em; line-height: 1; filter: grayscale(15%); }

/* ---- Grid ----------------------------------------------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-max), 1fr);
  gap: var(--gap);
  margin: 20px;
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 78px;
  padding: 14px;
  font-size: 1.86vw;
  line-height: 1.3;
  text-decoration: none;
  position: relative;
}
.tile:hover { background: var(--button-hover); }

/* The signature: icons sit greyed, wake up on hover */
.tile span {
  font-size: 1.1em;
  display: inline-block;
  filter: grayscale(95%);
  transition: filter 0.3s ease;
}
.tile:hover span { filter: grayscale(5%); }

.tile:focus-visible { outline: 2px solid var(--button-bg); outline-offset: 2px; }
.tile.span-2 { grid-column: span 2; }

/* Desktop tooltip from data-tooltip (hidden on touch widths) */
.tile::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 6px 10px;
  border-radius: 5px;
  font-size: 14px;
  white-space: nowrap;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 5;
}
.tile:hover::after { visibility: visible; opacity: 0.85; }

footer {
  margin: 8px 20px 24px;
  text-align: center;
  font-size: 13px;
  opacity: 0.55;
}

/* ---- Desktop fine-tune (matches original 1090–2000px rule) --------------- */
@media only screen and (min-width: 1090px) and (max-width: 2000px) {
  .tile { font-size: 1.75vw; }
  .weather .w { font-size: 1.2vw; }
}

/* ---- Mobile (original breakpoint: 1090px) --------------------------------
 * Whole page locked to one viewport-height screen. 4-column grid with
 * grid-auto-rows:1fr inside a flex column => the 28 tiles split into 7 rows
 * that evenly fill the leftover height. No scroll, no zoom, nothing oversized.
 * 100dvh accounts for the mobile browser chrome.
 * ------------------------------------------------------------------------- */
@media only screen and (max-width: 1090px) {
  html, body { height: 100%; }
  body {
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  #title-btn { font-size: 30px; margin: 4px 0 0; flex: 0 0 auto; }

  .weather {
    flex: 0 0 auto;
    margin: 6px 6px 4px;
    padding: 8px 8px;
    gap: 3px 8px;
  }
  .weather .w {
    flex-direction: column;
    gap: 2px;
    font-size: clamp(11px, 3.2vw, 15px);
  }
  .weather .w .ic { font-size: 1.5em; }

  .grid {
    flex: 1 1 auto;
    min-height: 0;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 1fr;
    gap: 5px;
    margin: 5px;
  }
  .tile {
    min-height: 0;
    padding: 4px;
    font-size: clamp(18px, 6.5vw, 30px);
    line-height: 1;
  }
  /* On touch, keep icons greyed (no hover state to rely on) */
  .tile span, .tile:hover span { filter: grayscale(95%); transition: none; }
  .tile:active { opacity: 0.7; }
  .tile:hover { background: var(--link-bg); }
  .tile::after { content: none; }

  footer { display: none; }

  #theme-btn { top: 12px; right: 9px; }
  #loc-btn { top: 12px; right: 57px; }
}

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