/* ══════════════════════════════════════════════════════
   CLS FIXES — font fallback size-adjust
   These @font-face blocks must come BEFORE :root
   ══════════════════════════════════════════════════════ */

@font-face {
  font-family: 'Inter-fallback';
  src: local('Arial');
  ascent-override: 90.49%;
  descent-override: 22.48%;
  line-gap-override: 0%;
  size-adjust: 107.64%;
}

@font-face {
  font-family: 'JetBrains-fallback';
  src: local('Courier New');
  ascent-override: 83%;
  descent-override: 21%;
  line-gap-override: 0%;
  size-adjust: 112%;
}

/* ══════════════════════════════════════════════════════
   DESIGN TOKENS
   ══════════════════════════════════════════════════════ */
:root {
  --bg: #050810;
  --surface: #0c1220;
  --surface2: #111a2e;
  --border: #1e2d4a;
  --accent: #00e5ff;
  --accent2: #ff6b35;
  --accent3: #7c3aed;
  --text: #e8edf5;
  --text1: #e8edf5;
  --text2: #8899b4;
  --gold: #ffd166;
  --green: #06ffa5;
  --red: #ff4060;

  /* Updated font stacks include size-matched fallbacks */
  --font-display: 'Inter', 'Inter-fallback', sans-serif;
  --font-mono: 'JetBrains Mono', 'JetBrains-fallback', monospace;
}

/* ══════════════════════════════════════════════════════
   RESET & BASE
   ══════════════════════════════════════════════════════ */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 16px;
  overflow-x: hidden;
  min-height: 100vh;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% 20%, rgba(0,229,255,.07) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 80%, rgba(124,58,237,.07) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(0,229,255,.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,229,255,.03) 1px, transparent 1px);
  background-size: 60px 60px;
  pointer-events: none;
  z-index: 0;
}

/* ══════════════════════════════════════════════════════
   LAYOUT
   ══════════════════════════════════════════════════════ */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
  position: relative;
  z-index: 1;
}

/* ══════════════════════════════════════════════════════
   CLS FIX — INJECTED REGIONS
   Reserve space for every element loaded asynchronously
   ══════════════════════════════════════════════════════ */

/* Ticker bar loaded by ticker.js */
.utc-bar {
  min-height: 36px;   /* measure: inspect .utc-bar in DevTools → offsetHeight */
  overflow: hidden;
  contain: layout;
}

/* Header injected via fetch('/header.html') or JS */
#header {
  min-height: 61px;   /* header-inner height 60px + 1px border */
  contain: layout;
}

/* Tools CTA injected by tools-cta.js */
#tools-cta {
  min-height: 100px;  /* measure your rendered tools-cta height */
  contain: layout;
}

/* Footer injected via fetch('/footer.html') */
#footer-container {
  min-height: 214px;  /* 44+44px padding + ~56px links + 70px margin-top */
  contain: layout;
}

/* ══════════════════════════════════════════════════════
   HEADER
   ══════════════════════════════════════════════════════ */
header {
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  background: rgba(5,8,16,.96);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  max-width: 1100px;
  margin: 0 auto;
  height: 60px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.logo-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  animation: spin 20s linear infinite;
  box-shadow: 0 0 16px rgba(0,229,255,0.3);
  /* Prevent animation from causing compositing shifts */
  will-change: transform;
}

@keyframes spin { to { transform: rotate(360deg); } }

.logo-text { font-size: 20px; font-weight: 800; color: var(--text); }
.logo-text span { color: var(--accent); }

.back-btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.3px;
  transition: color 0.3s ease;
  z-index: 1;
}

.back-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s ease;
  z-index: -1;
}

.back-btn:hover::before { transform: scaleX(1); }
.back-btn:hover { color: #051a2e; }
.back-btn:active { transform: scale(0.97); }

/* ══════════════════════════════════════════════════════
   HERO
   ══════════════════════════════════════════════════════ */
.hero { padding: 48px 24px 36px; text-align: center; }

.breadcrumb {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text2);
  font-family: var(--font-mono);
  margin-bottom: 20px;
}
.breadcrumb a { color: var(--text2); text-decoration: none; transition: color .2s; }
.breadcrumb a:hover { color: var(--accent); }

/* ══════════════════════════════════════════════════════
   FLAG — explicit size prevents ANY image CLS
   ══════════════════════════════════════════════════════ */
.city-flag {
  width: 80px;
  height: 56px;
  display: block;
  margin: 0 auto 20px;
  /* aspect-ratio is a backup; width+height are the primary CLS guard */
  aspect-ratio: 80 / 56;
  object-fit: contain;
}

/* ══════════════════════════════════════════════════════
   HEADINGS
   ══════════════════════════════════════════════════════ */
h1 {
  font-size: clamp(26px, 4vw, 42px);
  font-weight: 700;
  letter-spacing: -1px;
  margin-bottom: 10px;
  line-height: 1.15;
}

.sub-title {
  font-size: 15px;
  color: var(--text2);
  margin-bottom: 36px;
  letter-spacing: 0.2px;
}

/* ══════════════════════════════════════════════════════
   CLOCK DISPLAY
   CLS Fix: explicit height so JS paint doesn't shift layout
   ══════════════════════════════════════════════════════ */
.clock-display {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 36px 60px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: linear-gradient(160deg, var(--surface), rgba(0,229,255,.03));
  position: relative;
  overflow: hidden;
  margin-bottom: 20px;
  box-shadow: 0 0 60px rgba(0,229,255,.04), inset 0 1px 0 rgba(255,255,255,.04);

  /*
    Height breakdown:
      36px padding-top
    + 16px .clock-label line-height
    +  8px margin-bottom on label
    + 72px .live-time (clamp max)
    + 10px .live-date margin-top
    + 20px .live-date line
    + 36px padding-bottom
    = 198px
  */
  height: 198px;

  /* contain:layout prevents internal reflow from escaping */
  contain: layout;

  min-width: 320px;
}

.clock-display::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.6;
}

.clock-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text2);
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 8px;
  white-space: nowrap;
  /* Reserve line height so label never causes shift */
  line-height: 1.45;
}

/* ══════════════════════════════════════════════════════
   LIVE TIME — tabular-nums prevents per-digit-width shifts
   ══════════════════════════════════════════════════════ */
.live-time {
  font-family: var(--font-mono);
  font-size: clamp(42px, 6vw, 72px);
  color: var(--accent);
  letter-spacing: -2px;
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 0 32px rgba(0,229,255,.28);
  font-variant-numeric: tabular-nums;
  min-width: 8ch;
  text-align: center;

  /*
    Reserve max clamp height so fallback font → web font swap
    does not change the line height
  */
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.live-date {
  font-size: 14px;
  color: var(--text2);
  margin-top: 10px;
  font-family: var(--font-mono);
  letter-spacing: 0.5px;
  /* Reserve height: prevents collapse before JS writes date */
  min-height: 20px;
  line-height: 1.43;
}

/* ══════════════════════════════════════════════════════
   LIVE DOT — animation uses transform only (no layout)
   ══════════════════════════════════════════════════════ */
.live-dot {
  display: inline-block;
  width: 8px; height: 8px;
  background: var(--red);
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
  position: relative;
  box-shadow: 0 0 8px var(--red);
  /* Tell browser this will animate → promote to own layer */
  will-change: transform;
}

.live-dot::before {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 1px solid var(--red);
  animation: livePulse 1.8s ease-out infinite;
  will-change: transform, opacity;
}

@keyframes livePulse {
  0%   { transform: scale(.8); opacity: 1; }
  70%  { transform: scale(2);  opacity: 0; }
  100% { transform: scale(2);  opacity: 0; }
}

/* ══════════════════════════════════════════════════════
   INFO GRID — explicit column count prevents reflow
   ══════════════════════════════════════════════════════ */
.info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 40px 0;
  width: 100%;
}

@media (max-width: 820px) {
  .info-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .info-grid { grid-template-columns: 1fr; }
}

/* ── Card ── */
.info-card {
  background: linear-gradient(150deg, var(--surface) 60%, rgba(0,229,255,.03));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px 18px;
  text-align: left;
  transition: transform .28s ease, box-shadow .28s ease, border-color .28s ease;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(8px);
  /*
    Explicit min-height prevents card from being taller after value loads.
    label (~16px) + 8px gap + value (~23px) + 40px padding = 87px
  */
  min-height: 90px;
  /* Prevent backdrop-filter from triggering stacking context reflows */
  will-change: transform;
}

.info-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 16px 32px rgba(0,0,0,.18), 0 0 0 1px rgba(0,229,255,.15);
  border-color: rgba(0,229,255,.4);
}

.info-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 3px;
  background: linear-gradient(90deg, var(--accent), transparent);
  opacity: 0.7;
}

.info-card .label {
  font-size: 11px;
  color: var(--text2);
  font-family: var(--font-mono);
  letter-spacing: 2px;
  margin-bottom: 8px;
  text-transform: uppercase;
  opacity: 0.85;
  /* Reserve line height */
  min-height: 16px;
  line-height: 1.45;
}

.info-card .value {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
  line-height: 1.25;
  /* Reserve height so value never collapses before JS fills it */
  min-height: 23px;
}

.info-card .value.mono {
  font-family: var(--font-mono);
  font-size: 17px;
  color: var(--accent);
  letter-spacing: 0;
  /* tabular-nums prevents horizontal shift as UTC time ticks */
  font-variant-numeric: tabular-nums;
}

/* ══════════════════════════════════════════════════════
   CONVERTER
   ══════════════════════════════════════════════════════ */
.converter {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 36px;
  margin: 44px 0;
}

.converter h2 {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 24px;
  letter-spacing: -0.5px;
}

.convert-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: center;
}

.tz-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}

.tz-input label {
  display: block;
  font-size: 11px;
  color: var(--text2);
  font-family: var(--font-mono);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.tz-input input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 22px;
  font-family: var(--font-mono);
  font-weight: 700;
  outline: none;
}

.arrow {
  font-size: 28px;
  color: var(--text2);
  text-align: center;
  user-select: none;
}

/* ══════════════════════════════════════════════════════
   SECTION TITLES & FACT LIST
   ══════════════════════════════════════════════════════ */
.section-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.6px;
  margin-bottom: 18px;
}

.fact-list { list-style: none; display: grid; gap: 10px; }

.fact-list li {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  font-size: 15px;
  color: var(--text2);
  line-height: 1.65;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  transition: border-color .2s, background .2s;
}

.fact-list li:nth-child(odd)  { background: var(--surface); }
.fact-list li:nth-child(even) { background: var(--surface2); }
.fact-list li:hover { border-color: rgba(0,229,255,.3); }

.fact-list li::before {
  content: '→';
  color: var(--accent);
  font-family: var(--font-mono);
  flex-shrink: 0;
  margin-top: 1px;
}

/* ══════════════════════════════════════════════════════
   NEARBY GRID
   CLS Fix: min-height based on actual card count
   8 cards in auto-fill minmax(160px,1fr):
     viewport ≥ 960px → 6 cols → 2 rows
     viewport ~640px  → 4 cols → 2 rows
     viewport ~480px  → 3 cols → 3 rows
   Worst case 3 rows × (32px padding + 20+6+16+13px content) ≈ 290px
   ══════════════════════════════════════════════════════ */
.nearby-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 18px;
  min-height: 212px;  /* 2 rows safe floor */
  contain: layout;
}

.nearby-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform .22s ease, border-color .22s ease, box-shadow .22s ease;
  will-change: transform;
}

.nearby-card:hover {
  border-color: rgba(0,229,255,.45);
  transform: translateY(-4px);
  box-shadow: 0 8px 22px rgba(0,0,0,.15);
}

.nearby-card .flag {
  width: 28px; height: 20px;
  display: flex;
  align-items: center;
  font-size: 22px;
  line-height: 1;
}

/* Explicit flag image dimensions — prevents image CLS */
.nearby-card .flag img {
  width: 26px;
  height: 18px;
  object-fit: cover;
  border-radius: 3px;
  aspect-ratio: 26 / 18;
}

.nearby-card .nc-city {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}

.nearby-card .nc-time {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .3px;
  font-variant-numeric: tabular-nums;
  /* Reserve height before JS writes time */
  min-height: 20px;
}

.nearby-card .nc-country {
  font-size: 13px;
  color: var(--text2);
  opacity: .8;
}

/* ══════════════════════════════════════════════════════
   FOOTER
   ══════════════════════════════════════════════════════ */
footer {
  border-top: 1px solid var(--border);
  padding: 44px 24px;
  margin-top: 70px;
  text-align: center;
  font-size: 14px;
  color: var(--text2);
}

footer a {
  color: var(--text2);
  text-decoration: none;
  margin: 0 14px;
  transition: color .2s;
}

footer a:hover { color: var(--accent); }

/* ══════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  .convert-grid {
    grid-template-columns: 1fr;
  }
  .arrow {
    transform: rotate(90deg);
  }
  .clock-display {
    padding: 28px 20px;
    min-width: 0;
    width: 100%;
    /*
      Recalculate height for mobile:
        28px top + 16px label + 8px gap + 52px time + 10px + 20px date + 28px bottom
        = 162px
    */
    height: 162px;
  }
  .live-time {
    /* clamp min on mobile */
    min-height: 52px;
  }
  .converter {
    padding: 22px 16px;
  }
  h1 {
    font-size: clamp(22px, 6vw, 32px);
  }
  /* Nearby grid — mobile: 2 cols × 4 rows */
  .nearby-grid {
    min-height: 376px; /* 4 rows × (90px card + 12px gap) approx */
  }
}