/* showclock.app — selector + fullscreen mode surfaces.
   Two distinct UI surfaces: the launcher (tile grid) and the fullscreen
   mode viewport (massive numbers + optional controls). */

:root {
  --bg:    #0a0a0a;
  --bg2:   #141414;
  --ink:   #ffffff;
  --ink2:  #b8b8b8;
  --ink3:  #6a6a6a;
  --rule:  #222222;
  --rule2: #2c2c2c;
  --accent: #58a6ff;
  --green:  #3fb950;
  --amber:  #d29922;
  --red:    #f85149;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  font-feature-settings: 'ss01';
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: contain;
}

#app { width: 100vw; height: 100vh; height: 100dvh; }

/* ============ Launcher grid ============ */
.selector { display: flex; flex-direction: column; width: 100%; height: 100%; }
.selector-head {
  flex: 0 0 auto;
  padding-top:    max(18px, env(safe-area-inset-top));
  padding-right:  max(24px, env(safe-area-inset-right));
  padding-bottom: 12px;
  padding-left:   max(24px, env(safe-area-inset-left));
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1px solid var(--rule);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand-mark { width: 26px; height: 26px; display: inline-block; line-height: 0; flex-shrink: 0; }
.brand-mark svg { width: 100%; height: 100%; display: block; }
.brand .ext {
  color: var(--ink3);
  font-weight: 400;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 13px;
  margin-left: 2px;
}
.hint {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 13px;
  color: var(--ink3);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  line-height: 1.2;
  text-align: right;
}
.hint .hint-shift { color: var(--ink2); font-weight: 600; }
@media (hover: none), (max-width: 600px) {
  .selector-head .hint { display: none; }
}

/* 4×3 grid on desktop, 3×4 on tablet, 2×6 on phone. */
.grid {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 18px;
  padding: 22px;
  overflow: hidden;
  align-content: stretch;
  justify-content: stretch;
}

.tile {
  position: relative;
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 80ms ease, border-color 80ms ease, box-shadow 80ms ease;
  display: flex;
  align-items: stretch;
  outline: none;
  /* Tiles are buttons -> reset the browser defaults */
  padding: 0;
  font: inherit;
  color: inherit;
  aspect-ratio: 16 / 9;
  min-height: 0;
}
@media (hover: hover) {
  .tile:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent) inset;
    transform: translateY(-1px);
  }
}
.tile:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.tile:active { transform: scale(0.97); border-color: var(--accent); }
.tile canvas { width: 100%; height: 100%; display: block; }
.tile-label {
  position: absolute;
  left: 10px;
  bottom: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.6);
  padding: 3px 8px;
  border-radius: 4px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.tile-kind {
  position: absolute;
  right: 10px;
  top: 8px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 9px;
  font-weight: 600;
  color: var(--ink3);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ============ Fullscreen viewport ============ */
.viewport {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.viewport.transparent { background: transparent; }
.viewport .host {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: max(24px, env(safe-area-inset-top))
           max(24px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom))
           max(24px, env(safe-area-inset-left));
}

/* "← Back" pill in the top-left corner. Hidden by .controls-hidden flag too. */
.back-pill {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.55);
  color: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 6px 12px;
  font: 600 11px/1 'JetBrains Mono', ui-monospace, monospace;
  letter-spacing: 0.04em;
  cursor: pointer;
  z-index: 2;
  transition: opacity 200ms ease, transform 80ms ease;
}
.back-pill:hover { background: rgba(255, 255, 255, 0.10); }
.back-pill:active { transform: scale(0.96); }
.host.controls-hidden ~ .back-pill { opacity: 0; pointer-events: none; }

/* ============ Mode: timer (countdown + count-up) ============ */
.mode { width: 100%; height: 100%; position: relative; }

.mode .msg {
  position: absolute;
  top: 12vh;
  left: 0;
  right: 0;
  text-align: center;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: clamp(20px, 4vw, 56px);
  color: rgba(255, 255, 255, 0.85);
}
.mode .label {
  position: absolute;
  top: 6vh;
  left: 0;
  right: 0;
  text-align: center;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: clamp(11px, 1.4vw, 18px);
  color: var(--ink3);
}

/* The big number. CSS clamp + tabular nums + viewport-driven sizing. */
.mode .time {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1, 'ss01' 1;
  letter-spacing: -0.02em;
  /* Size scales with the smaller of the two viewport dimensions so it fills
     comfortably on portrait phones too. 26vmin reads big without overflowing. */
  font-size: min(28vw, 44vh);
  line-height: 0.9;
  color: var(--ink);
  margin: 0;
}

.mode .state {
  position: absolute;
  bottom: 14vh;
  left: 0; right: 0;
  text-align: center;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-weight: 600;
  letter-spacing: 0.12em;
  font-size: clamp(12px, 1.4vw, 18px);
  color: rgba(255, 255, 255, 0.5);
  text-transform: uppercase;
}

/* Threshold colors painted on the host. */
.mode-timer.green .time   { color: var(--green); }
.mode-timer.amber .time   { color: var(--amber); }
.mode-timer.red   .time   { color: var(--red);   }
.mode-timer.overtime .time {
  color: var(--red);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}

/* Controls bar (the pause / +30 / reset / mute strip). */
.mode .controls {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 999px;
  padding: 6px;
  z-index: 2;
  transition: opacity 200ms ease;
}
.mode .controls button {
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  border: none;
  border-radius: 999px;
  font: 600 12px/1 'JetBrains Mono', ui-monospace, monospace;
  letter-spacing: 0.04em;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 80ms ease;
}
.mode .controls button:hover { background: rgba(255, 255, 255, 0.08); }
.mode .controls button:active { background: rgba(255, 255, 255, 0.15); }
.mode.controls-hidden .controls { opacity: 0; pointer-events: none; }
.mode.controls-hidden .state    { opacity: 0; }

/* Transparent (OBS browser source) variant — drop the bg + the controls.
   The producer doesn't want a control bar baked into their stream. */
.mode-transparent .controls,
.mode-transparent .back-pill,
.mode-transparent .state { display: none; }
.mode-transparent .time  { text-shadow: 0 2px 12px rgba(0, 0, 0, 0.4); }

/* ============ Mode: clock ============ */
.mode-clock .time {
  font-size: min(22vw, 38vh);
  letter-spacing: -0.02em;
}
.mode-clock .date {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: clamp(14px, 2.2vw, 26px);
  color: var(--ink3);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-top: 1.5vh;
}

/* ============ Mode: clock — source toggle ============ */
/* Ambient by design — pinned to the bottom, monochrome, low opacity. Should
   read as a quiet status line, not compete with the main clock. */
.mode-clock .time-source {
  position: absolute;
  bottom: max(6px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: stretch;
  gap: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  z-index: 2;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  opacity: 0.55;
  transition: opacity 160ms ease;
}
.mode-clock .time-source:hover { opacity: 0.95; }
.mode-clock.controls-hidden .time-source { opacity: 0; pointer-events: none; }

.mode-clock .ts-btn {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: transparent;
  color: #6a6a6a;
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  font-family: inherit;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.10em;
  cursor: pointer;
  transition: color 100ms ease;
}
.mode-clock .ts-btn:hover { color: #b8b8b8; }
.mode-clock .ts-btn.active {
  color: #d0d0d0;
  font-weight: 600;
}
.mode-clock .ts-meta {
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 0.02em;
  color: #4a4a4a;
  min-width: 28px;
  text-align: left;
}
.mode-clock .ts-btn.active .ts-meta { color: #888; }
.mode-clock .ts-meta.warn { color: #8a6a1f; }
.mode-clock .ts-btn.active .ts-meta.warn { color: #b88820; }

.mode-clock .ts-resync {
  background: transparent;
  border: none;
  color: #4a4a4a;
  border-radius: 4px;
  padding: 4px 8px;
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  transition: color 100ms ease, transform 200ms ease;
}
.mode-clock .ts-resync:hover { color: #b8b8b8; }
.mode-clock .ts-resync:active { transform: rotate(180deg); }

@media (max-width: 600px) {
  .mode-clock .time-source { bottom: max(4px, env(safe-area-inset-bottom)); }
  .mode-clock .ts-btn { padding: 3px 8px; font-size: 9px; }
  .mode-clock .ts-meta { font-size: 8px; min-width: 22px; }
}

/* OBS / transparent — drop the source toggle, it shouldn't burn into the
   broadcast feed. */
.mode-transparent.mode-clock .time-source { display: none; }

/* ============ Mode: count-up ============ */
.mode-countup .laps {
  position: absolute;
  right: max(24px, env(safe-area-inset-right));
  top: 22vh;
  margin: 0; padding: 0;
  list-style: none;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: clamp(12px, 1.4vw, 18px);
  color: var(--ink3);
  text-align: right;
}
.mode-countup .laps li {
  display: grid;
  grid-template-columns: 28px 1fr 1fr;
  gap: 10px;
  align-items: baseline;
  padding: 4px 0;
  border-bottom: 1px solid var(--rule);
}
.mode-countup .laps .lap-n     { color: var(--ink3); text-align: right; }
.mode-countup .laps .lap-split { color: var(--accent); text-align: right; }
.mode-countup .laps .lap-total { color: var(--ink); text-align: right; }

/* ============ Mode: intermission ============ */
.mode-intermission {
  background: linear-gradient(180deg, #1a1410 0%, #0a0a0a 100%);
}
.mode-intermission .headline {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--amber);
  font-size: clamp(20px, 4vw, 56px);
  margin-bottom: 3vh;
}
.mode-intermission .time { color: var(--ink); font-size: min(26vw, 42vh); }
.mode-intermission .sub {
  margin-top: 3vh;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: clamp(14px, 1.6vw, 22px);
  color: var(--ink3);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.mode-intermission.ended .time { color: var(--green); animation: pulse 1.1s ease-in-out infinite; }

/* ============ Mode: custom picker ============ */
.mode-custom {
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.picker {
  background: var(--bg2);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 28px 32px;
  width: min(520px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}
.picker-title {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.picker-input {
  background: var(--bg);
  border: 1px solid var(--rule2);
  color: var(--ink);
  font: 600 28px/1.2 'JetBrains Mono', ui-monospace, monospace;
  padding: 14px 16px;
  border-radius: 8px;
  outline: none;
  width: 100%;
  letter-spacing: 0.04em;
  text-align: center;
}
.picker-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(88,166,255,0.18); }
.picker-input::placeholder { color: var(--ink3); font-weight: 500; }
.picker-hint {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  color: var(--ink3);
  text-align: center;
  letter-spacing: 0.04em;
}
.picker-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
.picker-row button {
  background: var(--bg);
  border: 1px solid var(--rule);
  color: var(--ink2);
  font: 600 11px/1 'JetBrains Mono', ui-monospace, monospace;
  letter-spacing: 0.04em;
  padding: 8px 0;
  border-radius: 6px;
  cursor: pointer;
}
.picker-row button:hover { border-color: var(--accent); color: var(--ink); }
.picker-error {
  color: var(--red);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  text-align: center;
}

/* ============ Footer (matches the rest of the suite) ============ */
.selector-foot{
  flex: 0 0 auto;
  min-height: 28px;
  padding:
    0
    max(16px, env(safe-area-inset-right))
    max(0px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  color: var(--ink3);
  border-top: 1px solid var(--rule);
  background: var(--bg2, #161b22);
  display: flex;
  align-items: center;
  justify-content: space-between;
  letter-spacing: 0;
  line-height: 1;
}
.selector-foot a { color: var(--ink3); text-decoration: none; }
.selector-foot a:hover { color: var(--ink); text-decoration: underline; }
.selector-foot .foot-r { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.selector-foot .foot-r .sep { color: var(--rule2); }
.selector-foot .foot-r [title^="App"],
.selector-foot .foot-r [title^="Git"],
.selector-foot .foot-r [title^="Build"] { color: var(--rule2); }
.selector-foot .foot-r [title^="App"]:hover,
.selector-foot .foot-r [title^="Git"]:hover,
.selector-foot .foot-r [title^="Build"]:hover { color: var(--ink3); cursor: help; }
.selector-foot .feedback-link { color: var(--ink3); text-decoration: none; }
.selector-foot .feedback-link:hover { color: var(--ink); text-decoration: underline; }

.suite-badges { display: inline-flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.suite-badges .badge {
  padding: 2px 8px;
  border-radius: 3px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10px;
  color: var(--ink3);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--rule);
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: 0;
}
.suite-badges .badge:hover { color: var(--ink); border-color: var(--rule2); text-decoration: none; }
.suite-badges .badge.current {
  background: rgba(63, 185, 80, 0.15);
  border-color: rgba(63, 185, 80, 0.4);
  color: var(--green);
  pointer-events: none;
}

.sw-status { display: inline-flex; align-items: center; gap: 6px; cursor: help; }
.sw-status .sw-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--rule2);
  box-shadow: 0 0 0 0 transparent;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
.sw-status .sw-text { color: var(--rule2); transition: color 0.2s ease; }
.sw-status.green .sw-dot { background: var(--green); box-shadow: 0 0 6px rgba(63,185,80,0.5); }
.sw-status.green .sw-text { color: var(--green); }
.sw-status.amber .sw-dot { background: var(--amber); box-shadow: 0 0 6px rgba(210,153,34,0.45); }
.sw-status.amber .sw-text { color: var(--amber); }
.sw-status.red   .sw-dot { background: var(--red);   box-shadow: 0 0 6px rgba(248,81,73,0.45); }
.sw-status.red   .sw-text { color: var(--red);   }
@media (max-width: 720px) {
  .selector-foot .foot-r [title^="App"],
  .selector-foot .foot-r [title^="Git"],
  .selector-foot .foot-r [title^="Build"] { display: none; }
  .selector-foot .foot-r .sep { display: none; }
  .sw-status .sw-text { display: none; }
}

/* ============ Responsive grid ============ */
/* Tablet: 3 cols. */
@media (max-width: 960px) {
  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: clamp(10px, 2vw, 16px);
    padding: clamp(12px, 2vw, 18px);
  }
}
/* Phone: 2 cols + scroll vertically. */
@media (max-width: 600px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: auto;
    gap: clamp(8px, 3vw, 14px);
    padding: clamp(10px, 3vw, 16px);
    overflow-y: auto;
    align-content: start;
    width: 100%;
    max-width: 540px;
    margin-inline: auto;
  }
  .selector-head {
    padding-top:    max(12px, env(safe-area-inset-top));
    padding-right:  max(16px, env(safe-area-inset-right));
    padding-bottom: 10px;
    padding-left:   max(16px, env(safe-area-inset-left));
  }
  .brand { font-size: 16px; }
  .tile-label { font-size: 12px; padding: 3px 9px; }
  .tile-kind  { font-size: 10px; }

  /* Phones: bring the time number in a touch on portrait. */
  .mode .time      { font-size: min(34vw, 38vh); }
  .mode-clock .time { font-size: min(26vw, 32vh); }
  .mode-countup .laps { display: none; }   /* not enough room next to a phone-portrait timer */
}
