/* ==========================================================================
   Sync-up styles

   1. Fonts
   2. Design tokens (edit here first)
   3. Base
   4. App layout
   5. Location list
   6. Location row: swipe actions, reorder ghost
   7. Home clock: header and date
   8. Home clock: wheel
   9. Home clock: footer and reset
   10. Add button
   11. Search sheet
   12. Confirm dialog and toast
   13. Motion and accessibility
   ========================================================================== */


/* 1. Fonts ---------------------------------------------------------------- */

@font-face {
  font-family: "Inter";
  src: url("fonts/inter-variable.woff2") format("woff2-variations"),
       url("fonts/inter-variable.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}


/* 2. Design tokens -------------------------------------------------------- */

:root {
  /* Colour: light */
  --bg: #E9EAE6;              /* page */
  --surface: #F7F7F5;         /* row background on press, hover, swipe */
  --text: #1A1A1A;
  --muted: #62635F;
  --line: rgba(26, 26, 26, .13);
  --scrollbar: rgba(26, 26, 26, .22);
  --accent: #D63A25;          /* delete */
  --shift: #f07421;           /* different day */
  --reset: #45463F;           /* reset button */

  --day: #FAFAF8;             /* clocks where the sun is up */
  --day-ink: #161616;
  --night: #1E1F22;           /* clocks where it's dark */
  --night-ink: #EDEDEA;
  --tile-day: #FFFFFF;        /* location time tile, daytime */
  --tile-night: #1C1C1C;      /* location time tile, night */
  --frame: #FFFFFF;           /* ring around the home clock */

  --sheet: #F7F7F4;
  --field: #FFFFFF;
  --action-edit: #6B6C68;

  /* Type */
  --font: "Inter", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --fs-wheel: clamp(48px, calc(var(--wheel-size) * .23), 92px);
  --fs-loc-time: clamp(26px, 8vw, 34px);
  --fs-loc-name: 17px;
  --fs-home-city: 20px;
  --fs-body: 15px;
  --fs-small: 14px;
  --stretch-display: 84%;     /* font-stretch for big numbers */
  --stretch-ui: 92%;

  /* Space */
  --gutter: 20px;             /* page side padding */
  --row-pad-y: 10px;
  --row-pad-x: 12px;
  --row-gap: 2px;
  --stack-gap: 6px;

  /* Shape */
  --r-row: 12px;
  --r-tile: 4px;
  --r-wheel: 8%;
  --frame-width: 6px;

  /* Size */
  --max-w: 480px;
  --wheel-size: clamp(240px, min(calc(100vw - 2 * var(--gutter)), 40dvh), 400px); /* floor keeps the clock and city name legible; page scrolls instead of shrinking past this */
  --actions-w: 152px;         /* swipe-to-reveal width; keep in sync with ACTIONS_W in app.js */

  /* Motion */
  --ease: cubic-bezier(.2, .8, .2, 1);
  --t-fast: .15s;
  --t-med: .25s;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #202124;
    --surface: #2C2E32;
    --text: #F0F0EC;
    --muted: #A3A49F;
    --line: rgba(240, 240, 236, .15);
    --scrollbar: rgba(240, 240, 236, .25);
    --tile-night: #0F1012;
    --frame: #34363A;
    --sheet: #26282B;
    --field: #323438;
    --reset: #C9CAC4;
  }
}

/* Dev-only tweak panel forcing light or dark regardless of the OS setting.
   Higher specificity than the media query above so it always wins. */
:root[data-t-theme="dark"] {
  --bg: #202124; --surface: #2C2E32; --text: #F0F0EC; --muted: #A3A49F;
  --line: rgba(240, 240, 236, .15); --scrollbar: rgba(240, 240, 236, .25);
  --tile-night: #0F1012; --frame: #34363A; --sheet: #26282B; --field: #323438; --reset: #C9CAC4;
}
:root[data-t-theme="light"] {
  --bg: #E9EAE6; --surface: #F7F7F5; --text: #1A1A1A; --muted: #62635F;
  --line: rgba(26, 26, 26, .13); --scrollbar: rgba(26, 26, 26, .22);
  --tile-night: #1C1C1C; --frame: #FFFFFF; --sheet: #F7F7F4; --field: #FFFFFF; --reset: #45463F;
}


/* 3. Base ----------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-body);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

/* Thin scrollbar instead of the system default, wherever something scrolls */
html, .locs, .results {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}
html::-webkit-scrollbar, .locs::-webkit-scrollbar, .results::-webkit-scrollbar { width: 6px; }
html::-webkit-scrollbar-track, .locs::-webkit-scrollbar-track, .results::-webkit-scrollbar-track { background: transparent; }
html::-webkit-scrollbar-thumb, .locs::-webkit-scrollbar-thumb, .results::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 999px;
}
html::-webkit-scrollbar-thumb:hover, .locs::-webkit-scrollbar-thumb:hover, .results::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

button { font: inherit; color: inherit; }

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

[hidden] { display: none !important; }


/* 4. App layout ----------------------------------------------------------- */

.app {
  height: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
  gap: var(--stack-gap);
  padding:
    calc(env(safe-area-inset-top) + 52px)
    var(--gutter)
    calc(env(safe-area-inset-bottom) + 8px);
}


/* 5. Location list -------------------------------------------------------- */

.locs {
  position: relative;          /* reorder hit-testing measures rows against this */
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--row-gap);
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.locs.empty { align-items: center; justify-content: center; }

.locs-empty {
  background: none; border: 0; cursor: pointer;
  padding: 24px var(--gutter);
  border-radius: var(--r-row);
  color: var(--muted);
  font: inherit;
  font-size: var(--fs-body);
  text-align: center;
  transition: background-color var(--t-fast) ease;
}
.locs-empty:active { background: var(--surface); }
@media (hover: hover) { .locs-empty:hover { background: var(--surface); } }

.loc {
  position: relative;
  flex-shrink: 0;
  border-radius: var(--r-row);
  overflow: hidden;
  transition: opacity .2s ease;
}

.loc-card {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 12px;
  padding: var(--row-pad-y) var(--row-pad-x) var(--row-pad-y) 16px;
  background: var(--bg);       /* covers the swipe actions until revealed */
  border-radius: var(--r-row);
  touch-action: none;
  transition: background-color var(--t-fast) ease;
}
.locs.scrolls .loc-card { touch-action: pan-y; }

.loc:active .loc-card,
.loc.revealed .loc-card { background: var(--surface); }
@media (hover: hover) { .loc-card:hover { background: var(--surface); } }

.loc-info { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }

.loc-name {
  background: none; border: 0; padding: 0; cursor: pointer;
  font-size: var(--fs-loc-name);
  font-weight: 650;
  font-stretch: var(--stretch-ui);
  text-align: left;
  max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.loc-date {
  display: flex; gap: 8px;
  font-size: var(--fs-small);
  font-variant-numeric: tabular-nums;
}
.loc-diff { opacity: .75; }
.loc-diff:empty { display: none; }
.loc-date.shifted { color: var(--shift); font-weight: 700; }

/* Time tile, flip-clock style */
.loc-time {
  position: relative;
  display: flex; align-items: center;
  border: 0; cursor: copy;
  padding: 4px 10px;
  border-radius: var(--r-tile);
  background: var(--tile-night);
  color: var(--night-ink);
  font-size: var(--fs-loc-time);
  font-weight: 500;
  font-stretch: 90%;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  transition: background-color .45s ease, color .45s ease;
}
.loc-time::after {               /* the split line across a flip tile */
  content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px;
  background: rgba(0, 0, 0, .25);
}
.loc-time.day {
  background: var(--tile-day);
  color: var(--day-ink);
  box-shadow: inset 0 0 0 1px var(--line);
}
.loc-time.copied { animation: copied .35s ease-out; }

.digit { display: inline-block; width: .62em; text-align: center; }
.digit > i { font-style: normal; display: inline-block; }
.digit.flip > i { animation: flip .22s ease-in-out; }
.colon { display: inline-block; width: .34em; text-align: center; transform: translateY(-.06em); }
.ampm { font-size: .38em; font-weight: 650; margin-left: 3px; align-self: flex-end; padding-bottom: .4em; }
.ampm:empty { display: none; }

@keyframes flip { 0% { transform: scaleY(1); } 50% { transform: scaleY(0); } 100% { transform: scaleY(1); } }
@keyframes copied { 0% { transform: scale(.94); } 100% { transform: scale(1); } }


/* 6. Location row: swipe actions, reorder ghost --------------------------- */

.loc-actions {
  position: absolute; top: 0; right: 0; bottom: 0;
  display: flex;
  visibility: hidden;
}
.loc.revealed .loc-actions { visibility: visible; }
.loc-actions button {
  width: calc(var(--actions-w) / 2);
  border: 0; cursor: pointer;
  color: #fff;
  font-size: var(--fs-small);
  font-weight: 650;
}
.act-edit { background: var(--action-edit); }
.act-delete { background: var(--accent); }

.loc-card.sliding { transition: transform var(--t-med) var(--ease), background-color var(--t-fast) ease; }

.loc.placeholder { opacity: .22; }
.locs.no-motion, .locs.no-motion * { transition: none !important; }

.ghost {
  position: fixed; z-index: 30; margin: 0;
  list-style: none;
  pointer-events: none;
  border-radius: var(--r-row);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .22), 0 2px 6px rgba(0, 0, 0, .12);
  transition: transform .16s ease-out, box-shadow .16s ease-out;
}
.ghost .loc-card { background: var(--surface); }
.ghost.settle { transition: transform .22s var(--ease), box-shadow .22s ease; box-shadow: none; }


/* 7. Home clock: header and date ------------------------------------------ */

.home {
  width: var(--wheel-size);
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.home-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 32px;
}

.home-city {
  background: none; border: 0; padding: 2px 0; cursor: pointer;
  font-size: var(--fs-home-city);
  font-weight: 700;
  font-stretch: var(--stretch-ui);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: transform .2s ease;
}
.home-city.pressing { transform: scale(.96); }

.home-date {
  position: relative;
  font-size: var(--fs-body);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: pointer;
}
.home-date.shifted { color: var(--shift); font-weight: 700; }

/* The native date input sits invisibly over the date text, so a tap opens the iOS picker */
.datepick {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  margin: 0; padding: 0; border: 0;
  opacity: 0; cursor: pointer;
  font-size: 16px;             /* stops iOS zooming on focus */
  -webkit-appearance: none; appearance: none;
}

.home.drop .wheel { outline: 3px solid var(--accent); outline-offset: 5px; }


/* 8. Home clock: wheel ---------------------------------------------------- */

.wheel {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
  gap: .04em;
  overflow: hidden;
  border: var(--frame-width) solid var(--frame);
  outline: 1px solid var(--line);
  border-radius: var(--r-wheel);
  background: var(--day);
  color: var(--day-ink);
  font-size: var(--fs-wheel);
  font-weight: 600;
  font-stretch: var(--stretch-display);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  touch-action: none;
  cursor: ns-resize;
}
.wheel.night { background: var(--night); color: var(--night-ink); }

/* Fade the rows above and below into the face */
.wheel::before, .wheel::after {
  content: ""; position: absolute; left: 0; right: 0; height: 30%;
  pointer-events: none; z-index: 1;
}
.wheel::before { top: 0; background: linear-gradient(var(--day), transparent); }
.wheel::after { bottom: 0; background: linear-gradient(transparent, var(--day)); }
.wheel.night::before { background: linear-gradient(var(--night), transparent); }
.wheel.night::after { background: linear-gradient(transparent, var(--night)); }

.wheel-col {
  height: 100%;
  display: flex; align-items: center;
  padding: 0 .06em;
  border-radius: 14px;
  transition: background-color var(--t-fast);
}
.wheel-col.active { background: color-mix(in srgb, currentColor 7%, transparent); }

.wheel-stack { display: flex; flex-direction: column; align-items: center; }
.wheel-stack span { height: 1.15em; line-height: 1.15em; opacity: .22; }
.wheel-stack span.cur { opacity: 1; }

.wheel-colon { transform: translateY(-.05em); }
.wheel-ampm { font-size: .3em; font-weight: 650; align-self: center; margin: .9em 0 0 .15em; }
.wheel-ampm:empty { display: none; }


/* 9. Home clock: footer and reset ----------------------------------------- */

.home-foot {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  min-height: 32px;
}

.home-msg {
  grid-column: 2;
  color: var(--muted);
  font-size: var(--fs-small);
  text-align: center;
}
.home-msg.offset { color: var(--text); font-weight: 650; font-size: var(--fs-body); }

.reset {
  grid-column: 3; justify-self: start;
  background: none; border: 0; padding: 6px 4px; cursor: pointer;
  color: var(--reset);
  font-size: var(--fs-body);
  font-weight: 700;
}


/* 10. Add button ---------------------------------------------------------- */

.add-btn {
  position: fixed; z-index: 20;
  top: calc(env(safe-area-inset-top) + 8px);
  right: max(12px, calc((100vw - var(--max-w)) / 2 + 12px));
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.add-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }


/* 11. Search sheet -------------------------------------------------------- */

.sheet {
  position: fixed; inset: 0; z-index: 25;
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 12px) var(--gutter) 0;
  background: var(--sheet);
}

.sheet-title,
.results,
.sheet-bar { width: 100%; max-width: var(--max-w); margin: 0 auto; }

.sheet-title { padding: 4px 2px 6px; color: var(--muted); font-size: 13px; font-weight: 600; }

.results {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  margin-top: 0; margin-bottom: 0; padding: 0;
  list-style: none;
  overflow-y: auto;
}
.results li:first-child { margin-top: auto; }   /* results stack up from the search field */
.results button {
  width: 100%;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  padding: 12px 2px;
  background: none; border: 0; border-bottom: 1px solid var(--line);
  text-align: left; cursor: pointer;
}
.result-name { font-weight: 650; font-size: 17px; }
.result-country { grid-column: 1; color: var(--muted); font-size: var(--fs-small); }
.result-time { grid-row: 1 / span 2; grid-column: 2; align-self: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.results .empty { padding: 16px 2px; color: var(--muted); }

.sheet-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0 calc(env(safe-area-inset-bottom) + 8px);
}
.sheet.keyboard .sheet-bar { padding-bottom: 8px; }

.sheet input {
  flex: 1; min-width: 0;
  padding: 12px 14px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--field); color: var(--text);
  font: inherit; font-size: 17px;
  -webkit-user-select: text; user-select: text;
}
.sheet-cancel { background: none; border: 0; padding: 10px 4px; font-weight: 650; font-size: 16px; cursor: pointer; }


/* 12. Confirm dialog and toast -------------------------------------------- */

.confirm {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, .35);
}
.confirm-box {
  width: 100%; max-width: 320px;
  padding: 20px;
  border-radius: 16px;
  background: var(--sheet);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.confirm-box p { margin: 0 0 6px; font-size: 17px; font-weight: 650; }
.confirm-box small { display: block; margin-bottom: 16px; color: var(--muted); font-size: var(--fs-small); }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
.confirm-actions button { border: 0; border-radius: 10px; padding: 10px 14px; font-weight: 650; cursor: pointer; background: var(--field); }
.confirm-actions .confirm-ok { background: var(--text); color: var(--bg); }

.toast {
  position: fixed; z-index: 40; left: 50%;
  top: calc(env(safe-area-inset-top) + 14px);
  max-width: calc(100vw - 32px);
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--text); color: var(--bg);
  font-size: var(--fs-small); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }


/* 13. Motion and accessibility -------------------------------------------- */

::view-transition-group(*) { animation-duration: .42s; animation-timing-function: var(--ease); }

@media (prefers-reduced-motion: reduce) {
  .digit.flip > i, .loc-time.copied { animation: none; }
  .loc-time, .loc-card { transition: none; }
}
