/* SLUH Exam Timer — palette and base cribbed from the SLUH time-visualizer so
   the two tools feel like a set. */

:root {
  --accent: #005588; /* SLUH Blue */
  --accent-rgb: 0, 85, 136;
}

:root,
[data-theme="dark"] {
  --bg: #0b0b0d;
  --panel: #17181c;
  --border: #232429;
  --track: #1c1d21;
  --text: #e7e7ea;
  --text-dim: #6c6d74;
  --done: #35363d;
  --overlay-bg: rgba(0, 0, 0, 0.55);
  --danger: #fb7185;
  color-scheme: dark;
}

/* SLUH brand palette: Navy #003366, Blue #005588, Spirit Blue #88ccec,
   Dark Gray #777777, Light Gray #eeeeee, Warm Gray #ccccbb */
[data-theme="light"] {
  --bg: #ffffff;
  --panel: #ffffff;
  --border: #dcdcd6;
  --track: #eeeeee;
  --text: #003366;
  --text-dim: #777777;
  --done: #ccccbb;
  --overlay-bg: rgba(0, 51, 102, 0.35);
  --danger: #b3261e;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: 0 1.5rem 2.5rem;
}

/* --- topbar --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  max-width: 760px;
  margin: 0 auto;
  padding: 1rem 0 0.6rem;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
}

.title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
}

.header-controls { display: flex; gap: 0.5rem; }

.icon-btn {
  appearance: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
  line-height: 1;
}
.icon-btn:hover { color: var(--text); border-color: var(--text-dim); }
#settings-btn { font-size: 1.1rem; }

main {
  max-width: 760px;
  margin: 0 auto;
}

/* --- main control buttons --- */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1.1rem 0 0;
}

.btn {
  appearance: none;
  background: var(--track);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.4rem 1rem;
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--text-dim); }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-accent:hover:not(:disabled) { border-color: #fff; }

/* Start button, once a valid timer is set up: a slow, low-key colour drift to
   nudge "this is the next step" without being loud. */
.btn-accent.is-ready:not(:disabled) {
  border-color: transparent;
  background-image: linear-gradient(
    100deg,
    var(--accent) 0%,
    #3f8fbf 25%,
    var(--accent) 45%,
    #5aa9a0 65%,
    var(--accent) 85%,
    #3f8fbf 100%);
  background-size: 300% 100%;
  animation: start-ready-drift 6s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0.45);
}
@keyframes start-ready-drift {
  0%   { background-position:   0% 50%; box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0.35); }
  50%  { background-position: 100% 50%; box-shadow: 0 0 0 6px rgba(var(--accent-rgb), 0); }
  100% { background-position:   0% 50%; box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0); }
}
@media (prefers-reduced-motion: reduce) {
  .btn-accent.is-ready:not(:disabled) { animation: none; box-shadow: none; }
}

.setup-hint {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin: 0.9rem 0 0;
}
.setup-hint[hidden] { display: none; }

/* --- exam title + instructions --- */

.exam-title {
  margin: 1.4rem 0 0;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
}
.exam-title[hidden] { display: none; }

.instructions {
  margin-top: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 1rem;
}
.instructions[hidden] { display: none; }

.instructions-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
}

.instructions-body {
  font-size: 1.05rem;
  line-height: 1.55;
  color: var(--text);
  outline: none;
}
.instructions-body[contenteditable="true"] {
  border: 1px dashed var(--accent);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
}

.link-btn {
  appearance: none;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}

/* --- current / start / finish --- */

.clock-row {
  display: flex;
  gap: 1rem;
  margin-top: 1.6rem;
}

.clock-cell { flex: 1; }
.clock-cell[hidden] { display: none; }

.clock-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 0.2rem;
}

.clock-value {
  font-size: 1.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.clock-value.accent { color: var(--accent); }

/* --- stage banner --- */

.stage-banner {
  margin-top: 1.6rem;
  font-size: 1.1rem;
  color: var(--text-dim);
}
.stage-banner[hidden] { display: none; }
.stage-banner.is-up { color: var(--danger); font-weight: 700; }

/* --- countdown box --- */

.timebox {
  margin-top: 0.7rem;
  background: var(--track);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 1.6rem 1rem 1.2rem;
  text-align: center;
}
.timebox.is-live { border-color: rgba(var(--accent-rgb), 0.4); }
.timebox.is-up { border-color: var(--danger); }

.timebox-main {
  font-size: clamp(3.2rem, 17vw, 8.5rem);
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.timebox.is-live .timebox-main { color: var(--accent); }
.timebox.is-up .timebox-main { color: var(--danger); }

.timebox-blank .timebox-main {
  font-size: clamp(1.4rem, 5vw, 2.2rem);
  color: var(--text-dim);
  font-weight: 600;
}

.timebox-label {
  margin-top: 0.7rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.btn-add { color: var(--accent); border-color: rgba(var(--accent-rgb), 0.5); }
#btn-add5 { margin-left: auto; }

.timebox.just-added { animation: timebox-bump 0.4s ease; }
@keyframes timebox-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

/* --- progress bar (from the SLUH visualizer) --- */

.bar-row { margin-top: 1.4rem; }
.bar-row[hidden] { display: none; }

.bar-track {
  position: relative;
  height: 12px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}
.bar-track.period { height: 18px; }
.bar-track > div {
  position: absolute;
  top: 0;
  bottom: 0;
}

/* fixed mode: a single fill. period mode: the fill is just the "exam elapsed"
   slice and sits between the lead-in and after-buffer segments. */
.bar-fill {
  left: 0;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
}
.bar-track.period .bar-fill { border-radius: 0; }

/* period mode: the whole bar is the class period. */
.bar-window {           /* faint band marking where the exam sits in the period */
  background: rgba(var(--accent-rgb), 0.16);
}
.bar-seg {              /* lead-in / after-buffer: class time that isn't the exam */
  background: repeating-linear-gradient(
    45deg, var(--text-dim) 0 3px, transparent 3px 7px);
  opacity: 0.55;
}
.bar-now {              /* "right now" marker */
  width: 3px;
  margin-left: -1.5px;
  background: var(--text);
  z-index: 2;
}

.bar-row.is-live .bar-fill {
  background: linear-gradient(90deg, var(--accent), rgba(var(--accent-rgb), 0.5), var(--accent));
  background-size: 300% 100%;
  animation: bar-shift 4s ease infinite;
}
@keyframes bar-shift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.bar-sub {
  margin-top: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* --- debug bar --- */

.debug-bar {
  margin-top: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  font-size: 0.68rem;
  color: var(--text-dim);
}
.debug-bar[hidden] { display: none; }
.debug-label { display: flex; align-items: center; gap: 0.4rem; }
.debug-input {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.68rem;
  padding: 0.15rem 0.35rem;
}
.ghost-btn {
  appearance: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.2rem 0.55rem;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
}
.ghost-btn:hover { color: var(--text); border-color: var(--text-dim); }

/* --- footer --- */

.foot {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  line-height: 1.55;
  color: var(--text-dim);
}
.foot p { margin: 0 0 0.5rem; }
.foot a { color: var(--accent); }

/* --- overlay / panels (from the SLUH visualizer) --- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--overlay-bg);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 3rem 1rem;
  overflow-y: auto;
}
.overlay[hidden] { display: none; }

.panel {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem 1.2rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}
.panel[hidden] { display: none; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.9rem;
}

.panel-section { margin-top: 1.1rem; }
.panel-section:first-of-type { margin-top: 0; }

.panel-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
}

.panel-hint {
  font-size: 0.68rem;
  line-height: 1.5;
  color: var(--text-dim);
  margin: 0.35rem 0 0;
}

.field { display: block; margin-bottom: 0.6rem; }
.field:last-child { margin-bottom: 0; }

.field-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
}
.field-label.spaced { margin-top: 1rem; }

.field input[type="text"],
.field input[type="date"],
.field input[type="time"],
.panel input[type="number"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.5rem;
  width: 100%;
}

.inline-fields { display: flex; gap: 0.6rem; }
.mini {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.mini input[type="number"] { width: 4.5rem; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--text);
  margin-bottom: 0.55rem;
  cursor: pointer;
  line-height: 1.4;
}
.check:last-child { margin-bottom: 0; }
.check input { accent-color: var(--accent); margin-top: 0.15rem; }

/* segmented control */
.seg {
  display: flex;
  gap: 0.4rem;
}
.seg-btn {
  appearance: none;
  flex: 1;
  background: var(--track);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.3rem;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}
.seg-btn.active {
  color: var(--text);
  border-color: var(--accent);
}

.radio-list { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.3rem; }
.radio-opt {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  padding: 0.25rem 0;
}
.radio-opt input { accent-color: var(--accent); }
.radio-opt .muted { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.radio-opt.disabled { color: var(--text-dim); cursor: default; }

.day-summary {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin: 0.1rem 0 0.8rem;
}
.day-summary strong { color: var(--text); }

.theme-row { display: flex; gap: 0.5rem; margin-bottom: 0.7rem; }
.mode-btn {
  appearance: none;
  flex: 1;
  background: var(--track);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}
.mode-btn.active { color: var(--text); border-color: var(--accent); }

.accent-row { display: flex; gap: 0.55rem; }
.accent-dot {
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.accent-dot.active { border-color: var(--text); }

.setup-error {
  margin: 1rem 0 0;
  font-size: 0.78rem;
  color: var(--danger);
}
.setup-error[hidden] { display: none; }

.panel-actions {
  margin-top: 1.2rem;
  display: flex;
  justify-content: flex-end;
}

/* --- responsive --- */

@media (max-width: 560px) {
  body { padding: 0 1rem 2rem; }
  .clock-row { gap: 0.6rem; }
  .clock-value { font-size: 1.15rem; }
  .timebox { border-radius: 12px; padding: 1.2rem 0.5rem 0.9rem; }
}
