@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=Inter:wght@400;500;600;700&family=KaTeX_Math:ital@1&display=swap");

:root {
  --bg-950: #e9f4fb;
  --bg-900: #fff4dd;
  --bg-800: #ffffff;
  --text-100: #123140;
  --text-300: #4b6570;
  --gold-500: #0f7e9b;
  --gold-400: #0b5f77;
  --surface: rgba(255, 255, 255, 0.96);
  --surface-alt: rgba(247, 252, 255, 0.98);
  --border: #c8dbe3;
  --shadow-lg: 0 12px 24px rgba(12, 54, 68, 0.12);

  --bg-top: #e9f4fb;
  --bg-bottom: #fff4dd;
  --card: #ffffff;
  --ink: #123140;
  --muted: #4b6570;
  --accent: #0f7e9b;
  --accent-strong: #095f76;
  --warm: #d67b19;
  --ok: #1a7f4e;
  --warn: #9a5d00;
  --shadow: 0 12px 24px rgba(12, 54, 68, 0.12);

  --app-bg:
    radial-gradient(1200px 700px at 8% 2%, rgba(19, 143, 176, 0.18), transparent 62%),
    radial-gradient(900px 600px at 92% 98%, rgba(220, 132, 32, 0.18), transparent 66%),
    linear-gradient(165deg, #e9f4fb, #fff4dd);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Inter", "IBM Plex Sans", sans-serif;
  color: var(--text-100);
  background: var(--app-bg);
  line-height: 1.45;
  overflow-x: hidden;
}

.bg-grid {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(15, 126, 155, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(214, 123, 25, 0.06) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at center, black 42%, transparent 95%);
}

h1,
h2,
h3,
h4,
p,
dl,
dt,
dd,
summary,
ul,
ol,
li {
  margin: 0;
}

.shell {
  width: min(1200px, calc(100% - 1.2rem));
  margin-inline: auto;
  padding-bottom: 2rem;
}

.hero {
  margin-top: 1.2rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.2rem 1.4rem;
  background: linear-gradient(160deg, #ffffff, #f7fbfd);
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
  margin-bottom: 1rem;
}

.hero::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 12px;
  background: var(--accent);
  border-radius: 14px 0 0 14px;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #0f7e9b;
  background: #eaf4f7;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  margin-bottom: 0.4rem;
  border: 1px solid #c8dbe3;
  text-decoration: none;
  transition: all 0.15s ease;
}

.brand-badge:hover {
  background: #d4ecf4;
  color: #0b5f77;
}

.lab-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: #b5640e;
  background: #fff3e5;
  border: 1px solid #fedbb3;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  margin-left: 0.5rem;
}

.kicker {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent-strong);
  font-weight: 700;
}

.hero h1 {
  font-size: clamp(1.6rem, 2.4vw, 2.3rem);
  margin-top: 0.35rem;
  color: var(--ink);
  line-height: 1.15;
}

.subtitle {
  margin: 0.38rem 0 0;
  color: var(--muted);
  max-width: 85ch;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem;
  background: var(--surface);
  box-shadow: 0 6px 16px rgba(12, 54, 68, 0.08);
}

.full {
  width: 100%;
}

.hint,
.info-line {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.88rem;
}

label {
  display: block;
  font-size: 0.91rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

label i, label sub, label sup, label span {
  display: inline;
}

input,
button,
canvas,
select {
  font: inherit;
}

input[type="number"],
input[type="range"],
select {
  border: 1px solid #a9c4cf;
  border-radius: 8px;
  background: #f9fdff;
  color: var(--ink);
  padding: 0.46rem 0.56rem;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

.range-label {
  margin-top: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

button {
  border-radius: 8px;
  color: #ffffff;
  font-weight: 700;
  padding: 0.58rem 0.82rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.1s ease, opacity 0.2s ease, background 0.2s ease;
}

button.primary {
  color: #fff;
}

button.ghost {
  background: #eef8fb;
  color: var(--accent-strong);
  border-color: #0d839f;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button:focus-visible,
input:focus-visible,
.tab-btn:focus-visible,
select:focus-visible {
  outline: 3px solid #ffad3b;
  outline-offset: 2px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.button-row.compact {
  margin-top: 0.45rem;
}

.sim-canvas {
  margin-top: 0.65rem;
  width: 100%;
  display: block;
  border-radius: 10px;
  border: 1px solid #b8d1db;
  background: linear-gradient(180deg, #f8fcff, #f2f8fb);
  cursor: default;
}

.sim-canvas.interactive-drag {
  cursor: grab;
}

.sim-canvas.interactive-drag:active {
  cursor: grabbing;
}

/* Activity Mode Switcher Nav */
.activity-nav {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.8rem;
  background: #dbeef7;
  padding: 0.4rem;
  border-radius: 10px;
  border: 1px solid #b8dbe5;
  flex-wrap: wrap;
}

.activity-tab-btn {
  flex: 1;
  min-width: 200px;
  text-align: center;
  background: transparent;
  color: var(--accent-strong);
  border: none;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.activity-tab-btn.active {
  background: #ffffff;
  color: var(--accent-strong);
  box-shadow: 0 3px 8px rgba(12, 54, 68, 0.15);
  border: 1px solid #a9c4cf;
}

.activity-tab-btn:hover:not(.active) {
  background: rgba(255, 255, 255, 0.5);
}

/* Sub-Mode Switcher Pill Bar */
.sub-nav {
  display: flex;
  gap: 0.4rem;
  background: #eef8fb;
  padding: 0.3rem;
  border-radius: 8px;
  border: 1px solid #c8dbe3;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
}

.sub-tab-btn {
  flex: 1;
  min-width: 150px;
  text-align: center;
  background: transparent;
  color: var(--accent-strong);
  border: none;
  padding: 0.45rem 0.8rem;
  font-size: 0.88rem;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sub-tab-btn.active {
  background: #0f7e9b;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(15, 126, 155, 0.25);
}

.sub-tab-btn:hover:not(.active) {
  background: rgba(15, 126, 155, 0.12);
}

.tab-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.5rem;
}

.tab-btn {
  background: #edf7fb;
  color: var(--accent-strong);
  border: 1px solid #7fb5c4;
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: linear-gradient(160deg, #0d839f, #0b5f77);
  color: #fff;
  border-color: #0a5d74;
}

.tab-panel {
  display: none;
  margin-top: 0.75rem;
  color: var(--muted);
}

.tab-panel.active {
  display: block;
}

.tab-panel h2 {
  margin-bottom: 0.55rem;
  color: var(--ink);
}

details {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f7fcff;
  padding: 0.7rem 0.8rem;
}

details + details {
  margin-top: 0.6rem;
}

summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-weight: 700;
  outline: none;
  font-size: 0.98rem;
}

details p {
  margin-top: 0.5rem;
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.5;
}

details ul, details ol {
  margin-top: 0.4rem;
  padding-left: 1.3rem;
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.5;
}

details li {
  margin-bottom: 0.35rem;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #ffffff;
}

th,
td {
  border: 1px solid #d2e2e8;
  padding: 0.5rem 0.7rem;
  font-size: 0.88rem;
  text-align: center;
}

th {
  background: #edf7fb;
  color: var(--accent-strong);
  font-weight: 700;
}

tr:nth-child(even) td {
  background: #fcfdfe;
}

.speed-btn, .avg-speed-btn, .walker-speed-btn, .custom-speed-btn {
  cursor: pointer;
  border: none;
  background: transparent;
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 6px;
  transition: all 0.1s ease;
}

.speed-btn.active, .avg-speed-btn.active, .walker-speed-btn.active, .custom-speed-btn.active {
  background: var(--accent) !important;
  color: white !important;
}

.speed-btn:hover:not(.active), .avg-speed-btn:hover:not(.active), .walker-speed-btn:hover:not(.active), .custom-speed-btn:hover:not(.active) {
  background: #dee2e6;
}

.alert-box {
  margin-top: 0.6rem;
  padding: 0.8rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
}

.alert-box.info {
  background: #ebfbee;
  border: 1px solid #c3fae8;
  color: #087f5b;
}

.alert-box.warning {
  background: #fff9db;
  border: 1px solid #ffd8a8;
  color: #d9480f;
}

/* Custom table highlights */
.logged-cell {
  background-color: #e6fcf5 !important;
  color: #099268;
  font-weight: bold;
}

/* Math expression styling */
.math-expr {
  font-family: "IBM Plex Serif", "Times New Roman", Cambria, serif;
  font-size: 1.02em;
  color: #0b5f77;
  background: #eef8fb;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  border: 1px solid #d2e8ef;
  display: inline-block;
  vertical-align: middle;
  white-space: nowrap;
}

.math-expr.display {
  display: block;
  text-align: center;
  margin: 0.6rem auto;
  padding: 0.4rem 1rem;
  font-size: 1.15em;
  background: #f4faff;
  border-color: #b8dbe5;
  width: fit-content;
}

.math-expr i {
  font-style: italic;
  font-family: serif;
}

.math-expr sub, .math-expr sup {
  font-size: 0.75em;
  line-height: 0;
}

/* Manual Split Button Pulse */
.manual-split-btn {
  background: linear-gradient(160deg, #d67b19, #b1620e);
  border-color: #9c5307;
  color: #ffffff;
  font-size: 0.95rem;
  padding: 0.55rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: 0 4px 10px rgba(214, 123, 25, 0.25);
  animation: pulse-split 2s infinite ease-in-out;
}

@keyframes pulse-split {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

.manual-split-btn:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 6px 14px rgba(214, 123, 25, 0.35);
}

.timing-mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
}

.timing-mode-pill.auto {
  background: #e6fcf5;
  color: #099268;
  border: 1px solid #b2f2bb;
}

.timing-mode-pill.manual {
  background: #fff4e6;
  color: #d9480f;
  border: 1px solid #ffd8a8;
}

/* Metric summary card for Average Velocity */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.8rem;
  margin-top: 0.8rem;
}

.metric-card {
  background: #f8fcfe;
  border: 1px solid #c8dbe3;
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  text-align: center;
}

.metric-card.highlight {
  background: #f0fdf4;
  border-color: #86efac;
}

.metric-card.accent {
  background: #fff8eb;
  border-color: #fcd34d;
}

.metric-card .title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.metric-card .val {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--ink);
  font-family: monospace;
}

.metric-card .sub {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.dir-toggle-btn {
  padding: 0.2rem 0.5rem;
  font-size: 0.78rem;
  background: #eef8fb;
  color: var(--accent-strong);
  border: 1px solid #b8d1db;
  border-radius: 4px;
}

.dir-toggle-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent-strong);
}

/* Multi-Stopwatch Cards */
.multi-timer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.6rem;
}

.timer-box {
  background: #123140;
  color: #00f0ff;
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  text-align: center;
  font-family: monospace;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.timer-box .timer-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: #a9c4cf;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.timer-box .timer-digit {
  font-size: 1.25rem;
  font-weight: bold;
}

@media (max-width: 768px) {
  .tables-grid {
    grid-template-columns: 1fr !important;
  }
  #equationDisplay {
    grid-template-columns: 1fr !important;
  }
}
