/* GB Timer: a stage confidence monitor. One deliberate look, dark by design. */

:root {
  --ground: #0b0c0e;
  --surface: #14161a;
  --surface-raised: #1c1f25;
  --line: #2a2e36;
  --ink: #f2efe8;
  --ink-soft: #b9b4aa;
  --ink-faint: #9a958c;
  --amber: #e8a33d;
  --live: #5fd08a;
  --danger: #ff7a6b;
  --focus: #8fb8ff;
  --rail: #0e1013;
  --glow: #15181d;
  --btn-hover-bg: #242831;
  --btn-hover-line: #3d434e;
  --btn-go-hover: #ffffff;
  --shadow: #000000;

  --font-ui: "Inter", "SF Pro Text", system-ui, -apple-system, "Segoe UI", "Noto Sans Arabic", Roboto, sans-serif;
  --font-display: "SF Pro Display", "Inter", system-ui, -apple-system, "Segoe UI", "Noto Sans Arabic", sans-serif;

  --gutter: clamp(1rem, 0.6rem + 2vw, 3rem);
  --radius: 14px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  color-scheme: dark;
}

/* Light mode: a real second palette, contrast-checked, not an inversion. */
:root[data-theme="light"] {
  --ground: #f6f3ec;
  --surface: #fffdf9;
  --surface-raised: #ffffff;
  --line: #dcd5c7;
  --ink: #16181c;
  --ink-soft: #454850;
  --ink-faint: #64666d;
  --amber: #955f0c;
  --live: #1d7f45;
  --danger: #b3261e;
  --focus: #2458c6;
  --rail: #efebe2;
  --glow: #fffdf9;
  --btn-hover-bg: #f1ede4;
  --btn-hover-line: #b9b1a1;
  --btn-go-hover: #000000;
  --shadow: #7a6f5a55;

  color-scheme: light;
}

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

[hidden] { display: none !important; }

.eyebrow {
  margin: 0;
  color: var(--ink-faint);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* ---------- Buttons ---------- */

.btn {
  min-height: 44px;
  padding: 0.6rem 1.15rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--ink);
  font: 600 1rem/1 var(--font-ui);
  cursor: pointer;
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease), transform 120ms var(--ease);
}

.btn:hover:not(:disabled) { border-color: var(--btn-hover-line); background: var(--btn-hover-bg); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn:focus-visible,
input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.btn-go {
  min-width: 8.5rem;
  border-color: transparent;
  background: var(--ink);
  color: var(--ground);
}
.btn-go:hover:not(:disabled) { background: var(--btn-go-hover); border-color: transparent; }

.btn-quiet {
  background: transparent;
  color: var(--ink-soft);
}
.btn-quiet:hover:not(:disabled) { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 55%, transparent); background: transparent; }

.btn-block { width: 100%; }

/* ---------- Screen layout: tiny header, then timer 80% | messages 20% ---------- */

.screen {
  display: grid;
  grid-template-columns: 4fr 1fr;
  grid-template-rows: auto 1fr;
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding-inline: var(--gutter) clamp(0.25rem, 1vw, 1rem);
  border-bottom: 1px solid var(--line);
  background: var(--rail);
}

.brand-mark {
  display: block;
  width: auto;
  height: 22px;
  color: var(--ink);
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 160ms var(--ease), background-color 160ms var(--ease);
}
.theme-toggle:hover { color: var(--ink); background: var(--btn-hover-bg); }
.theme-toggle:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.theme-toggle .icon { width: 18px; height: 18px; }

/* Show the mode you would switch TO. */
.icon-moon { display: none; }
:root[data-theme="light"] .icon-sun { display: none; }
:root[data-theme="light"] .icon-moon { display: block; }

.stage {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  padding: clamp(1rem, 2.5vh, 2rem) var(--gutter);
  background:
    radial-gradient(90% 90% at 50% 45%, var(--glow) 0%, transparent 70%),
    var(--ground);
}

.stage-label { text-align: left; }

/* The clock box is a size container, so the digits scale to fill whatever
   space the 80% column actually has, on any screen. */
.clock {
  container-type: size;
  display: grid;
  place-items: center;
  min-height: 0;
}

.timer {
  display: block;
  font-family: var(--font-display);
  font-size: min(30cqw, 80cqh); /* first paint only; app.js fits it exactly */
  font-weight: 650;
  line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--ink-faint);
  transition: color 240ms var(--ease);
}

[data-timer="running"] .timer { color: var(--ink); }
[data-timer="paused"] .timer { color: var(--amber); }
/* Ten seconds before the limit, and after it: red, whatever else is going on. */
[data-alert="warning"] .timer,
[data-alert="over"] .timer { color: var(--danger); }

.limit-label { color: var(--ink-soft); letter-spacing: 0.08em; }

.limit-field {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0 0.4rem 0 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  font-size: 0.95rem;
  font-weight: 600;
}

.limit-field input {
  width: 4.2rem;
  min-height: 36px;
  padding: 0 0.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: 600 1rem var(--font-ui);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.limit-field span:last-child { padding-right: 0.6rem; }

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
}

/* ---------- Messages rail ---------- */

.rail > .btn,
.rail > .error { flex: none; }

.rail {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
  min-height: 0;
  padding: clamp(1rem, 2.5vh, 2rem) clamp(0.75rem, 1.2vw, 1.25rem);
  border-left: 1px solid var(--line);
  background: var(--rail);
}

.link {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.dot {
  flex: none;
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: var(--ink-faint);
}

.link[data-state="live"] .dot { background: var(--live); box-shadow: 0 0 0 4px color-mix(in srgb, var(--live) 22%, transparent); }
.link[data-state="error"] { color: var(--danger); }
.link[data-state="error"] .dot { background: var(--danger); }
.link[data-state="connecting"] .dot { animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.3; } }

.error {
  margin: 0;
  padding: 0.6rem 0.75rem;
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  color: var(--danger);
  font-size: 0.9rem;
}

.feed {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.empty {
  margin: 0;
  padding: 1rem 0;
  color: var(--ink-faint);
  font-size: 1rem;
}
.empty strong { color: var(--ink-soft); font-weight: 600; overflow-wrap: anywhere; }

.messages {
  display: grid;
  gap: 0.6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.msg {
  display: grid;
  gap: 0.25rem;
  padding: 0.7rem 0.8rem;
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink-soft);
}

.msg-time {
  color: var(--ink-faint);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.msg-text {
  margin: 0;
  font-size: clamp(1rem, 0.6rem + 0.7vw, 1.4rem);
  font-weight: 500;
  line-height: 1.25;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  text-align: start;
}

.msg-latest {
  padding-block: 0.9rem;
  background: var(--surface-raised);
  box-shadow: inset 4px 0 0 var(--amber), 0 18px 40px -24px var(--shadow);
  color: var(--ink);
  animation: arrive 420ms var(--ease);
}

.msg-latest .msg-text {
  font-size: clamp(1.25rem, 0.7rem + 1.3vw, 2.25rem);
  font-weight: 650;
  letter-spacing: -0.01em;
}

@keyframes arrive {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

/* Phones and narrow portrait screens: timer on top, messages underneath. */
@media (max-width: 700px) {
  .screen { grid-template-columns: 1fr; grid-template-rows: auto 50dvh 1fr; }
  .rail { border-left: 0; border-top: 1px solid var(--line); }
  .controls .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- Sign-in gate ---------- */

.gate {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding-inline: 1rem;
  background:
    radial-gradient(80% 60% at 50% 0%, var(--glow) 0%, transparent 70%),
    var(--ground);
}

.gate-card {
  width: min(100%, 24rem);
  padding: 2rem;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 30px 80px -40px var(--shadow);
}

.gate-title {
  margin: 0.35rem 0 1.5rem;
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.gate-form { display: grid; gap: 1rem; }

.field { display: grid; gap: 0.4rem; color: var(--ink-soft); font-size: 0.9rem; font-weight: 600; }

.field input {
  min-height: 48px;
  padding: 0 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--ground);
  color: var(--ink);
  font: 1rem var(--font-ui);
}

.gate-form .error { margin: 0; }
