:root {
  color-scheme: light;
  --paper: #f6f3ed;
  --ink: #27231e;
  --quiet: #655e56;
  --line: #dcd5ca;
  --orange: #ff774e;
  --dark: #282019;
  --display: "Arial Black", "Aptos Display", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; position: relative; isolation: isolate; background: var(--paper); color: var(--ink); font-family: "Aptos", Arial, sans-serif; }

.cover-ready::before {
  content: "";
  position: fixed;
  z-index: -1;
  inset: 28% 0 0 auto;
  width: min(730px, 92vw);
  background: var(--team-photo) center 21% / cover no-repeat;
  mask-image: radial-gradient(ellipse at 70% 51%, #000 5%, #0009 40%, transparent 76%);
  filter: grayscale(65%);
  opacity: .105;
  pointer-events: none;
}
h1, h2, h3, p, figure, dl, dd { margin: 0; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .6; }
:focus-visible { outline: 3px solid #9c371d; outline-offset: 4px; }
.wrap { width: min(1112px, calc(100% - 64px)); margin-inline: auto; }
.site-header { border-bottom: 1px solid var(--line); }
.topbar { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.header-actions { display: flex; gap: 8px; align-items: center; }
.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; font-weight: 800; }
.brand img { flex: none; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 19px; border: 1px solid transparent; border-radius: 10px; color: #2a1b15; background: var(--orange); font-size: .975rem; font-weight: 800; white-space: nowrap; text-decoration: none; }
.button:hover:not(:disabled) { background: #ff8966; }
.button.compact { min-height: 42px; padding-inline: 15px; }
.button.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
.button.secondary:hover:not(:disabled) { background: #eee7dc; }

.hero { isolation: isolate; position: relative; overflow: hidden; display: flex; align-items: flex-end; min-height: 355px; margin-top: 30px; border-radius: 22px; background: var(--dark); color: #fbf6ed; }
.cover-ready .hero::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 0 0 25%;
  background: var(--team-photo) center 3% / cover no-repeat;
  mask-image: linear-gradient(90deg, transparent, #000b 7%, #000 17%);
  filter: grayscale(50%) brightness(.94);
  opacity: .32;
  pointer-events: none;
}
.cover-ready .track { display: none; }
.hero-text { z-index: 1; padding: 42px 46px; }
.hero h1 { font-family: var(--display); font-weight: 900; font-size: clamp(3.4rem, 9vw, 7.65rem); line-height: .86; letter-spacing: -.08em; }
.hero h1 em { color: var(--orange); font-style: normal; }
.hero p { margin-top: 25px; color: #e4d7c7; line-height: 1.4; font-size: clamp(1rem, 2vw, 1.15rem); }
.latest-race { display: grid; justify-items: start; gap: 5px; width: fit-content; max-width: min(30rem, 100%); margin-top: 17px; padding: 0 0 0 13px; border-left: 3px solid var(--orange); color: #fbf6ed; text-decoration: none; }
.latest-race > span, .latest-race time { color: #e4d7c7; line-height: 1.25; font-size: .875rem; }
.latest-race strong { font-size: 1.15rem; line-height: 1.15; overflow-wrap: anywhere; }
.latest-race:hover strong { text-decoration: underline; text-underline-offset: 3px; }
.latest-race:focus-visible { outline-color: var(--orange); }
.track { position: absolute; top: -94px; left: 54%; width: 590px; height: 500px; transform: rotate(-29deg); opacity: .9; pointer-events: none; }
.track::after { content: ""; position: absolute; top: 0; left: 49%; width: 3px; height: 147px; background: #ff774e; }
.track i { position: absolute; inset: var(--inset, 0px); border: 2px solid #aa6249; border-radius: 260px; }
.track i:nth-child(2) { --inset: 25px; }
.track i:nth-child(3) { --inset: 50px; }
.track i:nth-child(4) { --inset: 75px; }
.track i:nth-child(5) { --inset: 100px; }

.totals { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 16px; padding-block: 22px; background: #fffdf8; border: 1px solid var(--line); border-radius: 15px; }
.totals > div { display: flex; flex-direction: column-reverse; justify-content: flex-end; gap: 5px; padding: 0 clamp(14px, 4vw, 34px); }
.totals > div + div { border-left: 1px solid var(--line); }
.totals dt { color: var(--quiet); font-size: .9rem; }
.totals dd { font-weight: 850; font-size: clamp(1.55rem, 4vw, 2.35rem); letter-spacing: -.06em; line-height: 1; font-variant-numeric: tabular-nums; }
.totals small { font-size: .9rem; letter-spacing: normal; color: var(--quiet); }

.journal { padding: 43px 0 60px; }
.section-heading { display: flex; align-items: center; gap: 20px; margin-bottom: 18px; }
.section-heading h2 { font-size: clamp(1.5rem, 4vw, 2.1rem); letter-spacing: -.05em; }
.rule { flex: 1; height: 1px; background: var(--line); }
.state-message { padding: 20px 0; color: var(--quiet); }
.save-message { margin-bottom: 12px; padding: 10px 12px; border-radius: 8px; background: #e6eddf; color: #2f4b25; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 13px; padding: 33px 22px; border: 1px dashed #b6a99a; border-radius: 15px; text-align: center; }
.empty-icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 14px; background: #f9e3d6; color: #8b381f; }
.empty h3 { font-size: 1.34rem; }
.empty p { color: var(--quiet); line-height: 1.45; max-width: 32rem; }
.empty .button { margin-top: 3px; }
.signin { display: grid; gap: 14px; max-width: 390px; padding: 21px; border: 1px solid var(--line); border-radius: 15px; background: #fffdf8; }
.signin .form-error { margin-top: 0; }
.signin-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.race { padding: 21px; border: 1px solid var(--line); border-radius: 15px; background: #fffdf8; scroll-margin-top: 14px; }
.race + .race { margin-top: 16px; }
.race-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.race h3 { margin-top: 5px; font-size: clamp(1.3rem, 3.4vw, 1.85rem); letter-spacing: -.04em; overflow-wrap: anywhere; }
.race-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--quiet); font-size: .875rem; }
.race-distance { margin-left: 4px; padding-left: 10px; border-left: 1px solid var(--line); }
.race-gallery, .upload-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 11px; }
.pace { --tile-bg: #f7e5d9; --tile-fg: #803d26; }
.run { --tile-bg: #e8eadf; --tile-fg: #44543b; }
.medal { --tile-bg: #f7ebcd; --tile-fg: #71531d; }
.tile-image { display: grid; place-content: center; justify-items: center; gap: 9px; position: relative; width: 100%; aspect-ratio: 4 / 3; overflow: hidden; border: 0; border-radius: 9px; background: var(--tile-bg); color: var(--tile-fg); padding: 0; }
.tile-image img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pace .tile-image img { object-fit: contain; }
.tile-image:hover { box-shadow: inset 0 0 0 2px currentColor; }
.tile-image:not(.placeholder) { cursor: zoom-in; }
.tile-image span { padding-inline: 3px; font-size: .875rem; font-weight: 700; }
.tile figcaption { margin-top: 8px; color: var(--quiet); font-size: .875rem; overflow-wrap: anywhere; }

dialog { color: var(--ink); border: 0; border-radius: 19px; background: var(--paper); box-shadow: 0 20px 85px #1d15126b; }
dialog::backdrop { background: #19120eb5; }
.editor { width: min(670px, calc(100% - 24px)); max-height: calc(100% - 24px); padding: clamp(16px, 4vw, 28px); }
.editor-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.editor-head h2 { font-size: 1.85rem; letter-spacing: -.055em; }
.icon-button { display: grid; place-items: center; flex: none; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); color: var(--ink); }
.icon-button { font-size: 1.65rem; line-height: 1; }
.icon-button:hover { background: #eee7dc; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; margin-bottom: 22px; }
.field { display: grid; gap: 7px; align-content: start; font-weight: 700; font-size: .9rem; }
.field.full { grid-column: 1 / -1; }
.field input { width: 100%; min-height: 44px; padding: 9px 10px; border: 1px solid #c8bdb1; border-radius: 8px; background: #fffdf8; color: inherit; font-size: 1rem; }
.optional, .field-hint { color: var(--quiet); font-weight: 400; }
.field-hint { margin: 6px 0 13px; line-height: 1.45; }
.upload { position: relative; display: grid; grid-template-rows: 69px 1fr; border: 1px solid var(--line); border-radius: 10px; background: #fffdf8; overflow: hidden; cursor: pointer; }
.upload:hover { border-color: #8c634f; }
.upload:focus-within { outline: 3px solid #9c371d; outline-offset: 2px; }
.upload input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.upload-preview { display: grid; place-content: center; position: relative; color: var(--tile-fg); background: var(--tile-bg); overflow: hidden; }
.upload-preview img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.upload-text { display: grid; gap: 4px; min-width: 0; align-content: start; padding: 9px; font-size: .875rem; }
.upload-text > span { color: var(--quiet); overflow-wrap: anywhere; line-height: 1.25; }
.form-actions { margin-top: 19px; padding-top: 15px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.form-error { margin-top: 14px; color: #8f2a1d; line-height: 1.4; }
.lightbox { width: fit-content; max-width: calc(100% - 22px); max-height: calc(100% - 22px); padding: 10px; }
.lightbox .icon-button { margin: 0 0 8px auto; }
.lightbox img { display: block; max-width: 100%; max-height: calc(100dvh - 100px); object-fit: contain; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 610px) {
  .wrap { width: calc(100% - 28px); }
  .topbar { min-height: 64px; }
  .brand { gap: 7px; font-size: .9rem; }
  .brand img { width: 31px; height: 31px; }
  .button.compact { padding-inline: 10px; font-size: .875rem; }
  .hero { min-height: 270px; margin-top: 15px; border-radius: 16px; }
  .hero-text { padding: 23px 19px; }
  .hero p { margin-top: 18px; }
  .track { left: 43%; top: -126px; opacity: .52; transform: rotate(-32deg) scale(.75); transform-origin: left center; }
  .cover-ready .hero::before { inset: 0; mask-image: linear-gradient(110deg, #000c, #000 28%); opacity: .25; background-position: center 4%; }
  .cover-ready::before { inset-block-start: 33%; width: 100vw; opacity: .085; }
  .totals { margin-top: 10px; padding-block: 15px; }
  .totals > div { padding-inline: 9px; }
  .totals dt { font-size: .875rem; line-height: 1.2; }
  .journal { padding-top: 32px; }
  .race { padding: 12px; }
  .race-gallery, .upload-grid { gap: 6px; }
  .tile-image { aspect-ratio: 1; }
  .upload-text { padding-inline: 5px; }
}
