/* styles.css - base layout, the header, the search box and the city card.
   Colour literals live in tokens.css; nothing here may introduce one. */

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1100px 620px at 12% -10%, var(--accent-soft), transparent 62%),
    linear-gradient(180deg, var(--bg), var(--bg-deep));
  /* The shorthand above resets background-color to transparent; restate it so the page
     never falls through to the browser default while the gradient paints. */
  background-color: var(--bg);
  background-attachment: fixed;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.is-hidden { display: none !important; }

.skip-link {
  position: absolute; left: var(--s4); top: -100px; z-index: 20;
  padding: var(--s2) var(--s4); border-radius: var(--r-sm);
  background: var(--accent); color: var(--accent-text); text-decoration: none;
}
.skip-link:focus { top: var(--s4); }

/* ---------- header ---------- */

.app-header {
  position: sticky; top: 0; z-index: 10;
  padding: var(--s4) var(--s4) var(--s3);
  background: linear-gradient(180deg, var(--bg), transparent);
  backdrop-filter: blur(10px);
}
.app-header__bar {
  max-width: 1180px; margin: 0 auto var(--s3);
  display: flex; align-items: center; gap: var(--s3);
}
/* Without this the buttons are block-level and stack on top of each other. */
.app-header__actions { display: flex; align-items: center; gap: var(--s2); flex: none; }
.brand {
  flex: 1 1 auto; margin: 0;
  display: flex; align-items: center; gap: var(--s2);
  font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; letter-spacing: -.01em;
}
.brand__mark { display: grid; place-items: center; width: 26px; height: 26px; color: var(--accent); }
.brand__mark svg { width: 100%; height: 100%; }
.brand__amp { color: var(--text-faint); }

.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; flex: none;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text); cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.icon-btn:active { transform: scale(.94); }
.icon-btn--bare { border-color: transparent; background: none; width: 34px; height: 34px; }
.icon-btn.is-busy svg { animation: spin 900ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- search ---------- */

.search { position: relative; max-width: 1180px; margin: 0 auto; display: flex; align-items: center; }
.search__icon {
  position: absolute; left: var(--s3); display: grid; place-items: center;
  width: 20px; height: 20px; color: var(--text-faint); pointer-events: none;
}
.search__icon svg { width: 100%; height: 100%; }
.search__input {
  width: 100%; padding: var(--s3) var(--s7) var(--s3) var(--s6);
  font: inherit; color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-solid); box-shadow: var(--shadow-sm);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.search__input::placeholder { color: var(--text-faint); }
.search__input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
#search-clear { position: absolute; right: var(--s2); }

.search__results {
  position: absolute; top: calc(100% + var(--s2)); left: 0; right: 0; z-index: 12;
  max-height: 340px; overflow-y: auto; margin: 0; padding: var(--s1); list-style: none;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-solid); box-shadow: var(--shadow-md);
}
.search__option {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s2) var(--s3); border-radius: var(--r-sm); cursor: pointer;
}
.search__option[aria-selected="true"] { background: var(--accent-soft); }
.search__option__flag { font-size: 1.15rem; line-height: 1; }
.search__option__name { flex: 1 1 auto; }
.search__option__zone { color: var(--text-faint); font-size: .8rem; }
.search__option__added { color: var(--accent); font-size: .78rem; font-weight: 700; }

/* ---------- layout ---------- */

.main { max-width: 1180px; margin: 0 auto; padding: var(--s4) var(--s4) var(--s7); }
.notice-area { max-width: 1180px; margin: 0 auto; padding: 0 var(--s4); }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--s3); margin-bottom: var(--s4);
}
.section-title {
  margin: 0; font-family: var(--font-display); font-size: 1rem;
  letter-spacing: .02em; text-transform: uppercase; color: var(--text-muted);
}
.section-meta { margin: 0; font-size: .82rem; color: var(--text-faint); font-variant-numeric: tabular-nums; }

.card-grid { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); }

/* ---------- card ---------- */

.card {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: var(--s3);
  padding: var(--s4); min-height: 208px;
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
  animation: card-in 260ms var(--ease) both;
  transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.card::before { content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.card--dawn::before  { background: var(--grad-dawn); }
.card--day::before   { background: var(--grad-day); }
.card--dusk::before  { background: var(--grad-dusk); }
.card--night::before { background: var(--grad-night); }
.card > * { position: relative; z-index: 1; }
.card:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }
@keyframes card-in { from { opacity: 0; transform: translateY(8px); } }

.card__head { display: flex; align-items: flex-start; gap: var(--s2); }
.card__flag { font-size: 1.3rem; line-height: 1.2; }
.card__names { flex: 1 1 auto; min-width: 0; }
.card__name { margin: 0; font-size: 1.02rem; font-weight: 700; letter-spacing: -.01em; overflow-wrap: anywhere; }
.card__zone { margin: 0; font-size: .76rem; color: var(--text-muted); overflow-wrap: anywhere; }
.card__link { color: inherit; text-decoration: none; }
.card:hover .card__link { color: var(--accent); text-decoration: underline; }

/* The whole card opens the city. The anchor on the name stays the real link - one tab
   stop, a real href, so ctrl-click and middle-click still open a new tab - and this
   overlay merely stretches its hit area over the card.

   The head must NOT be positioned, or the overlay would resolve against the head instead
   of the card. z-index still applies to it because the card is a flex container and the
   head is one of its items. */
.card__head { position: static; z-index: 2; }
.card__link::after { content: ""; position: absolute; inset: 0; }
.card { cursor: pointer; }

/* Above the overlay, so reordering and removing still work. */
.card__actions { position: relative; z-index: 3; }

.card__actions {
  display: flex; justify-content: flex-end; gap: 2px;
  margin-top: var(--s1); padding-top: var(--s1);
  border-top: 1px solid var(--border);
  opacity: .72; transition: opacity var(--dur) var(--ease);
}
.card:hover .card__actions, .card__actions:focus-within { opacity: 1; }
.card__actions .icon-btn { width: 30px; height: 30px; }
.card__actions .icon-btn svg { width: 17px; height: 17px; }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.icon-btn:disabled:hover { background: none; border-color: transparent; }

.clock { display: flex; align-items: baseline; gap: 2px; font-family: var(--font-display); font-variant-numeric: tabular-nums; }
.clock__hm { font-size: 2.5rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.05; }
.clock__sec { font-size: 1.1rem; font-weight: 500; color: var(--text-muted); }
.clock__suffix { font-size: .9rem; font-weight: 500; color: var(--text-muted); margin-left: var(--s1); }
.clock__colon { animation: pulse 1s steps(1, end) infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.card__date { margin: calc(var(--s1) * -1) 0 0; font-size: .82rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.chips { display: flex; flex-wrap: wrap; gap: var(--s1); }
.chip {
  display: inline-flex; align-items: center; gap: var(--s1);
  padding: 2px var(--s2); border-radius: var(--r-pill);
  font-size: .72rem; font-weight: 500; font-variant-numeric: tabular-nums;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.chip--warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

.card__weather { display: flex; align-items: center; gap: var(--s3); margin-top: auto; }
.card__icon { flex: none; width: 40px; height: 40px; color: var(--day); }
.card--night .card__icon, .card--dusk .card__icon { color: var(--night); }
.card__icon svg { width: 100%; height: 100%; }
.card__temp { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.card__cond { font-size: .82rem; color: var(--text-muted); }
.card__meta { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s3); font-size: .78rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ---------- skeleton ---------- */

.skeleton { pointer-events: none; }
.skeleton__bar { border-radius: var(--r-sm); background: var(--surface-2); animation: shimmer 1.4s var(--ease) infinite; }
@keyframes shimmer { 50% { opacity: .45; } }


/* ---------- responsive ---------- */

@media (max-width: 900px) { .card-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); } }
@media (max-width: 560px) {
  .card-grid { grid-template-columns: 1fr; }
  .main, .notice-area, .app-header { padding-left: var(--s3); padding-right: var(--s3); }
  .clock__hm { font-size: 2.2rem; }
}
@media (max-width: 380px) { .brand { font-size: .95rem; } .card { padding: var(--s3); } }

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