@font-face {
  font-family: "Harbour Pixel";
  src: url("assets/HarbourPixel.ttf") format("truetype");
  font-display: swap;
}

:root {
  color-scheme: dark;
  --pixel: "Harbour Pixel", ui-rounded, system-ui, sans-serif;
  --deep: #0a2232;
  --ink: #fff2d2;
  --mist: #c4dcd9;
  --mint: #a6f0d9;
  --gold: #ffda82;
  --edge: #507686;
  --line: #385f6d;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: linear-gradient(155deg, #14393e, var(--deep) 51%) fixed;
  font: 1rem/1.45 system-ui, sans-serif;
}
p, h1, h2, h3 { margin: 0; }
h1, h2, h3 { font-family: var(--pixel); font-weight: 400; }
h2 { font-size: clamp(1.28rem, 2.7vw, 1.7rem); line-height: 1.15; }
h3 { font-size: 1.15rem; }
a { color: var(--mint); text-underline-offset: .22em; }
a:hover { color: var(--ink); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .62; cursor: default; }
:is(a, button, input):focus-visible { outline: 3px solid var(--gold); outline-offset: 4px; }

.derby-shell { width: min(72rem, 100% - 2rem); margin-inline: auto; }
main.derby-shell { padding-block: clamp(1rem, 3vw, 2rem) 3rem; }
.derby-masthead { background: #0d2b38; border-bottom: 1px solid #426572; }
.derby-topline { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .45rem 1.2rem; padding-block: .75rem; }
.back-link { color: var(--ink); font-family: var(--pixel); font-size: 1.06rem; }
.standings-link { font-size: .9375rem; font-weight: 650; }

.event-banner {
  position: relative;
  min-height: clamp(9rem, 18vw, 13rem);
  display: flex;
  align-items: center;
  overflow: hidden;
  border: 2px solid #6aa28f;
  background: linear-gradient(90deg, #0a2637 7%, #0a2637ed 28%, #0a2637b8 50%, #0a26371a 94%), url("assets/scene-reef.webp") center 36% / cover;
  box-shadow: 0 4px 0 #071b27;
  image-rendering: pixelated;
}
.event-copy { padding: clamp(.9rem, 2.6vw, 1.85rem); }
.event-kicker { color: var(--gold); font: 1.2rem/1.15 var(--pixel); }
.event-copy h1 { font-size: clamp(2rem, 5.5vw, 4rem); line-height: 1.03; margin: .4rem 0 .65rem; text-shadow: 0 3px #071b27; }
.event-meta { display: flex; align-items: center; flex-wrap: wrap; gap: .35rem .85rem; color: var(--mist); font-size: .9375rem; }
#event-location { color: var(--mint); font-weight: 700; }
#event-reset:empty { display: none; }

.derby-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); align-items: start; gap: 1rem; margin-top: 1rem; }
.derby-panel { min-width: 0; padding: clamp(.8rem, 2vw, 1.35rem); background: #123242; border: 1px solid var(--edge); box-shadow: 0 3px 0 #061b27; }
.panel-heading { display: flex; align-items: start; justify-content: space-between; flex-wrap: wrap; gap: .65rem .8rem; }
.player-summary { display: flex; flex-wrap: wrap; gap: .25rem .75rem; align-items: baseline; margin-top: .38rem; color: var(--mist); font-size: .9375rem; }
.player-summary strong { color: var(--gold); overflow-wrap: anywhere; }
.gold-button, .secondary-button {
  min-height: 2.75rem;
  padding: .45rem .9rem;
  border: 1px solid #83afa6;
  background: #1c4654;
  color: var(--ink);
  font: 1.04rem/1.2 var(--pixel);
  box-shadow: inset 0 -3px #133343;
}
.gold-button { color: #2e271a; background: #ffcc73; border-color: #ffe7a5; box-shadow: inset 0 -4px #dc9c42; }
.gold-button:not(:disabled):hover { background: #ffdd9a; }
.secondary-button:not(:disabled):hover { background: #285968; }
.join-form { margin-top: 1rem; padding: .9rem; border: 1px solid var(--line); background: #0d2736; }
.join-form label { display: block; margin-bottom: .4rem; font-weight: 700; }
.join-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .5rem; align-items: stretch; }
.join-row input { width: 100%; min-width: 0; min-height: 2.75rem; padding: .45rem .6rem; color: var(--ink); background: #102f40; border: 1px solid #719397; border-radius: 0; }
.join-row input::placeholder { color: #afc5c7; }
.join-form p { margin-top: .5rem; color: var(--mist); font-size: .9375rem; }
.join-form .derby-error { color: #ffe5d8; }

.board-switcher { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .5rem; margin-top: 1rem; }
.board-switcher button { min-height: 3rem; }
.board-switcher [aria-pressed="true"] { color: #262417; background: #ffda82; border-color: #fff1bd; box-shadow: inset 0 -4px #dc9c42; }
.board-switcher [aria-pressed="true"]:hover { background: #ffe4a1; }
.derby-grid[data-stats] { grid-template-columns: minmax(0, 1fr); }
.stat-details { display: grid; gap: .8rem; margin-block: .55rem 1rem; }
.board-description, #sharing-note { color: var(--mist); }
.stats-sharing { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .65rem 1rem; padding: .75rem .85rem; border: 1px solid #528d84; background: #0f323c; }
.stats-save { flex: 1 1 20rem; min-width: 0; }
#saved-score { color: var(--mint); font-weight: 700; font-variant-numeric: tabular-nums; }
#sharing-note { margin-top: .22rem; font-size: .9375rem; }
.stats-sharing .derby-error { flex: 1 1 100%; margin-top: 0; }

.derby-round { display: grid; gap: .65rem; margin-top: .85rem; }
.round-header { display: flex; flex-wrap: wrap; gap: .35rem .8rem; justify-content: space-between; align-items: baseline; color: var(--mist); font-size: .9375rem; }
.round-header > strong { color: var(--mint); }
#run-score, #cast-count, #board-page { font-variant-numeric: tabular-nums; }
#run-score { color: var(--gold); }
.waterside { position: relative; isolation: isolate; width: 100%; aspect-ratio: 16 / 8.25; border: 1px solid #719f9a; overflow: hidden; background: #12616d url("assets/scene-reef.webp") center 44% / cover; image-rendering: pixelated; }
.waterside::before { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(180deg, transparent 66%, #071f3c45); }
.bobber { display: none; position: absolute; left: 46%; top: 39%; width: 47px; height: 47px; transform: translate(-50%, -50%); pointer-events: none; z-index: 1; }
.bobber img { display: block; width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.bobber::before { content: ""; position: absolute; bottom: 55%; left: 74%; width: 1px; height: 6rem; background: #e6ffdbad; transform: rotate(19deg); transform-origin: bottom; }
.waterside:is([data-state="waiting"], [data-state="bite"], [data-state="late"]) .bobber { display: block; }
.waterside[data-state="waiting"] .bobber { animation: bobber-drift 2s ease-in-out infinite; }
.waterside[data-state="bite"] .bobber { transform: translate(-50%, calc(-50% + 13px)) rotate(-13deg); animation: bobber-dip .28s ease-out; }
.waterside[data-state="late"] .bobber { transform: translate(-50%, calc(-50% + 8px)) rotate(-7deg); }
.waterside[data-state="bite"]::after { content: ""; position: absolute; top: 44%; left: 46%; width: 64px; height: 16px; border: 2px solid #f4ffd7; border-radius: 50%; transform: translate(-50%, -50%); box-shadow: 0 0 0 2px #2d8fa28c; pointer-events: none; }

.feeding-ripple { position: absolute; top: 40%; left: 64%; display: grid; place-items: center; width: 68px; height: 46px; padding: 0; transform: translate(-50%, -50%); border: 0; background: none; }
.feeding-ripple::before, .feeding-ripple::after { content: ""; position: absolute; inset: 8px 0; border-radius: 50%; border: 2px solid #fff0a5; box-shadow: 0 0 0 1px #70471b; }
.feeding-ripple::before { animation: ripple-pulse .8s ease-out infinite; }
.feeding-ripple::after { inset: 13px 10px; }
.ripple-label { position: absolute; top: 100%; padding: .16rem .3rem; color: #2a2214; background: #ffe6a7; border: 1px solid #6a4b24; font-size: .8rem; font-weight: 760; white-space: nowrap; }
.feeding-ripple:focus-visible { outline-color: #171e25; background: #f9e79776; }
.cast-controls { display: flex; align-items: center; gap: .65rem; }
.cast-control { min-width: 7.25rem; min-height: 3rem; font-size: 1.25rem; }
#cast-status { min-width: 0; color: var(--mist); font-size: .9375rem; }
.catch-result { color: var(--mint); background: #0d2736; padding: .6rem .75rem; border-left: 3px solid #72bea9; }
.catch-result:empty { display: none; }
.weigh-in { background: #223f43; border: 1px solid #729180; border-bottom-color: #395b59; padding: .55rem .7rem .65rem; }
.weigh-in h3 { color: var(--gold); }
.catch-ruler { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .3rem; margin: .42rem 0 0; padding: 0; list-style-position: inside; color: #fff1cc; }
.catch-ruler li { min-width: 0; padding: .35rem .36rem .55rem; overflow-wrap: anywhere; background: repeating-linear-gradient(90deg, #8a8061 0 1px, transparent 1px 8px) bottom / 100% 4px no-repeat, linear-gradient(90deg, #24534b var(--fill, 0%), #18363b var(--fill, 0%)); border: 1px solid #668179; font-size: .9375rem; font-variant-numeric: tabular-nums; }
.catch-ruler li::marker { color: #adc5ab; }
.catch-ruler:empty { display: none; }

.derby-rules { display: grid; gap: .38rem; margin-top: 1rem; padding-top: .8rem; border-top: 1px solid var(--line); color: var(--mist); font-size: .9375rem; }
.derby-rules :is(h3, strong) { color: var(--ink); }
.derby-error { margin-top: .7rem; padding: .6rem .7rem; background: #4a2630; border: 1px solid #a06462; color: #ffe5d8; }
.board-panel .panel-heading { align-items: center; }
.personal-standing { margin-top: .8rem; padding: .55rem .65rem; color: var(--mint); background: #17494d; border: 1px solid #528d84; font-weight: 700; }
.standings-table { width: 100%; margin-top: .9rem; border-collapse: collapse; table-layout: auto; }
.standings-table :is(th, td) { text-align: left; padding: .5rem .45rem; }
.standings-table thead { color: var(--mint); font-size: .875rem; border-block: 1px solid #567c84; background: #0d2b3a; }
.standings-table tbody tr { border-bottom: 1px solid var(--line); }
.standings-table tbody tr:nth-child(even) { background: #193b49; }
.standings-table tbody tr[data-player] { background: #1d5458; }
.standings-table td { overflow-wrap: anywhere; }
.standings-table :is(th, td):last-child { text-align: right; white-space: nowrap; }
.standings-table :is(th, td):first-child { width: 4.5rem; }
.standings-table :is(th, td):last-child { width: 7.5rem; }
.standings-table td:last-child { color: var(--gold); font-weight: 750; font-variant-numeric: tabular-nums; }
.board-state { padding: .9rem .45rem; color: var(--mist); }
.paging { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .4rem; margin-top: .85rem; color: var(--mist); font-size: .9375rem; }
.paging .secondary-button { padding-inline: .62rem; }

@keyframes bobber-drift {
  0%, 100% { transform: translate(-50%, -50%) rotate(-3deg); }
  50% { transform: translate(-50%, calc(-50% + 4px)) rotate(4deg); }
}
@keyframes bobber-dip {
  0% { transform: translate(-50%, -50%); }
  65% { transform: translate(-50%, calc(-50% + 21px)) rotate(-17deg); }
}
@keyframes ripple-pulse {
  from { transform: scale(.7); opacity: 1; }
  to { transform: scale(1.2); opacity: .46; }
}

@media (max-width: 49rem) {
  .derby-grid { grid-template-columns: minmax(0, 1fr); }
  .event-banner { background-image: linear-gradient(90deg, #0a2637fa 4%, #0a2637cd 50%, #0a263760), url("assets/scene-reef.webp"); }
  .board-switcher { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 26rem) {
  .derby-shell { width: calc(100% - 1.2rem); }
  .event-meta { display: grid; gap: .14rem; }
  .join-form { padding: .65rem; }
  .join-row { grid-template-columns: minmax(0, 1fr); }
  .cast-control { min-width: 6.7rem; }
}
@media (prefers-reduced-motion: reduce) {
  .waterside .bobber, .feeding-ripple::before { animation: none !important; }
}
