/* Shark Run UI shell. The .ti-* classes belong to keyboard.js (it injects its own styles). */

:root {
  --bg-0: #031423;
  --bg-1: #072540;
  --bg-2: #0b3a5c;
  --card: rgba(7, 30, 52, 0.82);
  --card-strong: rgba(5, 22, 40, 0.92);
  --panel: rgba(3, 16, 30, 0.74);
  --line: rgba(110, 220, 230, 0.2);
  --text: #eaf8ff;
  --muted: #9cc2d6;
  --faint: #6f97ad;
  --teal: #22d3c2;
  --teal-deep: #0b8f86;
  --sun: #ffcf3f;
  --sun-deep: #c99300;
  --coral: #ff6f6f;
  --ink: #062033;
  --radius: 18px;
  --radius-sm: 10px;
  --font-display: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  --panel-h: max(35vh, 220px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(ellipse 80% 60% at 15% 0%, rgba(34, 211, 194, 0.22), transparent 60%),
    radial-gradient(ellipse 70% 60% at 100% 100%, rgba(30, 136, 229, 0.25), transparent 60%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  background-attachment: fixed;
  background-color: var(--bg-0);
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.15;
  margin: 0;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: progress; opacity: 0.6; }

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

kbd {
  display: inline-block;
  font-family: var(--font-body);
  font-size: 0.72em;
  font-weight: 600;
  line-height: 1;
  padding: 0.3em 0.45em;
  border-radius: 6px;
  border: 1px solid currentColor;
  opacity: 0.75;
  vertical-align: 0.12em;
}

/* ---------- screens ---------- */

.screen { display: none; }
.screen.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.card h2 {
  font-size: 1.35rem;
  color: var(--teal);
  margin-bottom: 8px;
}

/* ---------- 1. title ---------- */

#screen-title {
  min-height: 100vh;
  padding: 14px 16px 12px;
  /* layered waves along the bottom edge */
  background:
    radial-gradient(120% 40px at 50% 100%, rgba(34, 211, 194, 0.12) 98%, transparent 100%) bottom / 220px 40px repeat-x;
}

.title-grid {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.title-main, .title-side { display: grid; gap: 18px; min-width: 0; }

.hero { text-align: center; }

.logo {
  position: relative;
  width: min(100%, 440px);
  margin: 0 auto;
  container-type: inline-size;
}

/* The PNG has empty space top-left; crop to its artwork (222,201)-(1375,901). */
.logo-crop {
  aspect-ratio: 1153 / 700;
  overflow: hidden;
}
.logo-crop img {
  display: block;
  width: 119.254%;
  height: auto;
  margin-left: -19.254%;
  margin-top: -17.433%;
  filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.25));
}

/* "SHARK" sticker in the empty space left of "RUN" (which starts 35.7cqw in),
   so the logo reads SHARK RUN / CLUB. */
.logo-sticker {
  position: absolute;
  left: 1cqw;
  top: 3.6cqw;
  z-index: 1;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 8.4cqw;
  line-height: 1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--teal);
  padding: 0.08em 0.28em 0.12em;
  border-radius: 0.28em;
  transform: rotate(-7deg);
  box-shadow: 0 0.07em 0 var(--teal-deep), 0 0.2em 0.4em rgba(0, 0, 0, 0.35);
}

.tagline {
  margin: 10px auto 0;
  max-width: 440px;
  color: var(--muted);
  font-size: 1rem;
}

.setup { display: grid; gap: 16px; }

.field { display: grid; gap: 6px; }
.field-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--teal);
}

#name-input {
  font: inherit;
  font-size: 1.1rem;
  color: var(--text);
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  width: 100%;
}
#name-input:focus { outline: none; border-color: var(--teal); }
#name-input.invalid { border-color: var(--coral); }

.shark-picker {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
}
@media (max-width: 520px) {
  .shark-picker { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.shark-opt {
  --c: #888;
  position: relative;
  aspect-ratio: 1;
  padding: 3px;
  border-radius: 14px;
  border: 3px solid transparent;
  background: rgba(255, 255, 255, 0.06);
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}
.shark-opt:hover { transform: translateY(-2px); background: rgba(255, 255, 255, 0.12); }
.shark-opt[aria-checked="true"] {
  border-color: var(--c);
  background: color-mix(in srgb, var(--c) 35%, transparent);
  transform: translateY(-3px) scale(1.05);
}
.shark-opt img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.shark-dot {
  width: 72%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  color: rgba(0, 0, 0, 0.55);
}

.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.mode-btn {
  --face: var(--teal);
  --deep: var(--teal-deep);
  border: 0;
  border-radius: 16px;
  padding: 12px 10px 10px;
  color: var(--ink);
  background: var(--face);
  box-shadow: 0 6px 0 var(--deep), 0 10px 20px rgba(0, 0, 0, 0.3);
  display: grid;
  justify-items: center;
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.12s ease;
}
.mode-btn:hover { filter: brightness(1.08); }
.mode-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--deep), 0 4px 10px rgba(0, 0, 0, 0.3); }
.mode-endurance { --face: var(--sun); --deep: var(--sun-deep); }
.mode-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.7rem;
  line-height: 1.1;
}
.mode-sub { font-weight: 600; font-size: 0.9rem; opacity: 0.8; }

.msg { margin: 0; min-height: 1.5em; color: var(--muted); }
.msg.error { color: var(--coral); }

.howto p { margin: 0; color: var(--text); }

/* leaderboards */

.boards-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  margin-bottom: 10px;
}
.boards-head h2 { margin: 0; }
.board-date { color: var(--muted); font-weight: 600; }

.boards-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.board h3 {
  font-size: 1.15rem;
  margin-bottom: 6px;
}
.board h3 span { font-family: var(--font-body); font-size: 0.8rem; font-weight: 500; color: var(--faint); }

.board-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-variant-numeric: tabular-nums;
}
.board-table td {
  padding: 4px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  white-space: nowrap;
}
.board-table .col-rank { width: 2.2em; font-family: var(--font-display); font-weight: 600; color: var(--muted); text-align: right; padding-right: 8px; }
.board-table .col-dot { width: 1.3em; }
.board-table .col-name { overflow: hidden; text-overflow: ellipsis; }
.board-table .col-time { width: 5.2em; text-align: right; font-weight: 600; }
.board-table tr:nth-child(1) .col-rank { color: var(--sun); }
.board-table tr.me td { background: rgba(255, 207, 63, 0.16); }
.board-table tr.me td:first-child { border-radius: 8px 0 0 8px; }
.board-table tr.me td:last-child { border-radius: 0 8px 8px 0; }
.board-table tr.me .col-name { color: var(--sun); font-weight: 700; }
.board-table tr.gap td { text-align: center; color: var(--faint); border-bottom: 0; padding: 0; line-height: 1; }

.dot {
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  border-radius: 50%;
  background: var(--c, #888);
  vertical-align: -0.05em;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25);
}

.board-empty { margin: 6px 0; color: var(--faint); font-style: italic; }

.credit {
  max-width: 1200px;
  margin: 18px auto 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--faint);
}

@media (max-width: 900px) {
  .title-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .boards-grid { grid-template-columns: minmax(0, 1fr); }
  .mode-name { font-size: 1.4rem; }
}

/* loading overlay */

.loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(2, 12, 22, 0.72);
  backdrop-filter: blur(3px);
}
.loading[hidden] { display: none; }
.loading-card {
  width: min(360px, calc(100% - 32px));
  text-align: center;
  padding: 26px 24px 22px;
  background: var(--card-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.loading-card p { margin: 10px 0 12px; font-family: var(--font-display); font-weight: 500; font-size: 1.15rem; }

.fin {
  width: 120px;
  height: 46px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  border-bottom: 3px solid var(--teal);
}
.fin::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 30px;
  height: 36px;
  background: #b7d2e0;
  border-radius: 0 100% 0 0 / 0 100% 0 0;
  transform: scaleX(-1);
  animation: swim 1.6s ease-in-out infinite alternate;
}
@keyframes swim {
  from { left: -4px; }
  to { left: 94px; }
}

.bar {
  height: 10px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--sun));
  transition: width 0.15s linear;
}
.bar-fill.indeterminate {
  width: 35%;
  animation: indeterminate 1.1s ease-in-out infinite;
}
@keyframes indeterminate {
  from { transform: translateX(-100%); }
  to { transform: translateX(300%); }
}

/* ---------- 2. race ---------- */

#screen-race {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--bg-0);
}

#race-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.typing-panel {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: min(1100px, calc(100% - 24px));
  height: var(--panel-h);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.4);
}
#screen-race.done .typing-panel { display: none; }

.panel-hint {
  position: absolute;
  top: 8px;
  right: 14px;
  font-size: 0.8rem;
  color: var(--faint);
}

/* Theme keyboard.js through its custom properties (inherited), never its .ti-* rules.
   Key size: the keyboard measures 4.63 keys tall and 11.08 wide; the word strip is ~74px,
   padding + gap + border ~28px. Fit the keyboard in what is left. */
.typing-panel {
  --ti-key: clamp(22px, min(calc((var(--panel-h) - 104px) / 4.65), calc((100vw - 90px) / 11.6)), 52px);
  --ti-accent: var(--teal);
  --ti-font: var(--font-body);
}
/* Left-align the word strip with the keyboard's left edge so the two read as one block. */
.ti-words-host {
  flex: 0 0 auto;
  min-width: 0;
  padding-left: max(0px, calc(50% - var(--ti-key) * 5.54));
  padding-right: 70px;
}
.ti-kbd-host {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: hidden;
}

/* ---------- 3. finish ---------- */

#screen-finish.active {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
  background: rgba(2, 12, 22, 0.55);
  backdrop-filter: blur(3px);
}

.finish-card {
  width: min(520px, 100%);
  text-align: center;
  padding: 22px 24px 24px;
  background: var(--card-strong);
  animation: pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes pop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.finish-shark {
  width: 110px;
  height: auto;
  margin: -6px auto 0;
  display: block;
  animation: bob 1.4s ease-in-out infinite alternate;
}
.finish-shark[hidden] { display: none; }
@keyframes bob {
  from { transform: translateY(0) rotate(-3deg); }
  to { transform: translateY(-6px) rotate(3deg); }
}

#finish-title { font-size: 1.6rem; color: var(--teal); }

.finish-time {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.8rem, 9vw, 4.2rem);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  color: var(--sun);
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

.finish-rank {
  margin: 4px 0 0;
  min-height: 1.5em;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.25rem;
}
.finish-rank.error { color: var(--coral); font-family: var(--font-body); font-size: 1rem; font-weight: 600; }
.finish-ghosts { margin: 0; min-height: 1.5em; color: var(--muted); }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 16px 0 18px;
}
.stats div {
  background: rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  padding: 8px 4px;
}
.stats dt { font-size: 0.75rem; color: var(--muted); }
.stats dd {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 420px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.finish-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.btn {
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.06);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  transition: transform 0.08s ease, filter 0.12s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(2px); }
.btn-primary {
  border-color: transparent;
  background: var(--teal);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--teal-deep);
}

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