@font-face {
  font-family: "Barlow Condensed";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("./assets/fonts/barlow-condensed-latin-600-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Barlow Condensed";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("./assets/fonts/barlow-condensed-latin-700-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./assets/fonts/inter-latin-400-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("./assets/fonts/inter-latin-600-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("./assets/fonts/inter-latin-700-normal.woff2") format("woff2");
}

:root {
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #061d31;
  background: var(--color-page);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --color-ink: #061d31;
  --color-ink-soft: #18354b;
  --color-header: #031a2d;
  --color-page: #faf9f6;
  --color-surface: #f0f2f3;
  --color-surface-pressed: #dde2e5;
  --color-border: #d2d7db;
  --color-text-muted: #4c5965;
  --color-accent: #ffbf1f;
  --color-accent-hover: #ecae12;
  --color-accent-pressed: #d99a00;
  --color-group-idle: #fff8df;
  --color-group-idle-border: #eadca8;
  --color-group-idle-hover: #fff1bf;
  --color-open-on-dark: #7be349;
  --color-sync-on-dark: #26c7e8;
  --color-success: #087a43;
  --color-danger: #b42318;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-width: 320px;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  color: inherit;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  position: relative;
  z-index: 2;
  outline: 3px solid #1977b8;
  outline-offset: 2px;
}

.app-stage {
  display: grid;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  overflow: hidden;
}

.bib-logger {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background: var(--color-page);
}

.race-header {
  min-height: 52px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  color: #fff;
  background: var(--color-header);
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
}

.header-row-primary {
  height: 36px;
}

.race-header h1 {
  overflow: hidden;
  margin: 0;
  padding-right: 2px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.015em;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.race-time {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.race-time svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.race-time time {
  width: 76px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.logger-content {
  display: grid;
  min-height: 0;
  grid-template-rows: 156px 150px 48px minmax(264px, 1fr) 60px;
  gap: 8px;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
}

.recent-section {
  min-height: 0;
  padding-inline: 4px;
}

.recent-section h2,
.bib-section h2 {
  margin: 0;
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.035em;
  line-height: 1;
}

.recent-list {
  height: 132px;
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
}

.recent-row-shell {
  position: relative;
  height: 44px;
  overflow: hidden;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-danger);
}

.recent-row {
  position: relative;
  z-index: 1;
  display: grid;
  height: 44px;
  grid-template-columns: 1fr 1.55fr 0.95fr;
  align-items: center;
  background: var(--color-page);
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  touch-action: pan-y;
  transition: transform 160ms ease-out;
  will-change: transform;
}

.recent-row-dragging {
  transition: none;
}

.recent-delete-action {
  position: absolute;
  z-index: 0;
  display: flex;
  width: 88px;
  align-items: center;
  justify-content: center;
  gap: 4px;
  inset: 0 0 0 auto;
  border: 0;
  color: #fff;
  background: var(--color-danger);
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.025em;
  cursor: pointer;
  touch-action: manipulation;
}

.recent-delete-action svg {
  width: 17px;
  height: 17px;
}

.recent-value-button {
  width: 100%;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  font-variant-numeric: inherit;
  line-height: 1;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.recent-value-button:focus-visible {
  outline-offset: -3px;
}

.recent-time-button {
  justify-self: start;
}

.recent-group-button {
  font-size: 17px;
  letter-spacing: 0.025em;
}

.recent-status {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 6px;
  color: var(--color-text-muted);
  font-family: "Inter", sans-serif;
  font-size: 13px;
  font-weight: 700;
}

.recent-status svg {
  width: 18px;
  height: 18px;
}

.recent-status-local {
  color: var(--color-success);
}

.recent-status-group {
  color: var(--color-ink-soft);
}

.recent-row-new {
  animation: local-entry-highlight 200ms ease-out;
}

.recent-empty {
  display: flex;
  height: 132px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-top: 6px;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.035em;
}

.recent-empty small {
  font-family: "Inter", sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.bib-section {
  position: relative;
  display: grid;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr) 20px;
  padding-top: 2px;
}

.bib-display-layout {
  display: grid;
  width: 100%;
  min-width: 0;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr);
}

.bib-section.group-mode-active .bib-display-layout {
  grid-template-columns: minmax(112px, 36%) minmax(0, 1fr);
  column-gap: 10px;
}

.current-bib-panel,
.group-roster {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: 22px minmax(0, 1fr);
}

.current-bib-panel h2,
.group-roster h2 {
  align-self: center;
  justify-self: center;
}

.group-roster {
  overflow: hidden;
  padding-right: 10px;
  border-right: 1px solid var(--color-border);
}

.group-roster[hidden] {
  display: none;
}

.group-roster h2 {
  justify-self: start;
  font-size: 16px;
  white-space: nowrap;
}

.group-member-list {
  display: grid;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: repeat(4, minmax(0, 1fr));
  list-style: none;
}

.group-member-list-two-column {
  grid-auto-flow: column;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.group-member {
  display: flex;
  min-width: 0;
  align-items: center;
  overflow: hidden;
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-size: clamp(20px, 6vw, 24px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 0.9;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bib-value {
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: center;
  justify-content: center;
  padding-bottom: 0.06em;
  overflow: visible;
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-size: clamp(104px, 32vw, 124px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.015em;
  line-height: 0.9;
  white-space: nowrap;
}

.group-mode-active .bib-value {
  font-size: clamp(76px, 25vw, 106px);
}

.group-mode-active .bib-value-empty {
  font-size: clamp(60px, 20vw, 78px);
}

.bib-value-empty {
  color: var(--color-text-muted);
  font-size: 82px;
}

.bib-value-submitted {
  color: var(--color-success);
}

.bib-value-confirmed {
  animation: submitted-bib-confirm 180ms ease-out;
}

.submitted-bib-digits {
  display: inline-flex;
  gap: 0.015em;
}

.submitted-bib-digit {
  display: inline-block;
  letter-spacing: 0;
}

.submitted-bib-digit-removed {
  opacity: 0;
  transform: translateY(-4px);
}

.submitted-bib-digit-removing {
  animation: submitted-bib-digit-out var(--bib-exit-step-ms) ease-in forwards;
}

.inline-message {
  width: 100%;
  overflow: hidden;
  margin: 0;
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 20px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.capture-section {
  min-width: 0;
  margin: 0 5px;
  padding: 0;
  border: 0;
}

.capture-options {
  display: grid;
  height: 48px;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-surface);
}

.capture-options button {
  border: 0;
  background: transparent;
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.015em;
  cursor: pointer;
}

.capture-options button + button {
  border-left: 1px solid var(--color-border);
}

.capture-options button.selected {
  background: var(--color-accent);
}

.keypad {
  display: grid;
  min-height: 0;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(44px, 1fr));
  gap: 6px;
}

.keypad-key {
  display: flex;
  min-width: 0;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border: 1px solid #e0e3e5;
  border-radius: 10px;
  background: var(--color-surface);
  box-shadow: inset 0 -1px 0 rgb(6 29 49 / 4%);
  cursor: pointer;
  transition: background-color 80ms ease, transform 80ms ease;
  touch-action: manipulation;
  user-select: none;
}

.number-key {
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-size: clamp(44px, 13vw, 56px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.group-mode-key {
  flex-direction: column;
  gap: 2px;
  border-color: var(--color-group-idle-border);
  background: var(--color-group-idle);
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
}

.group-mode-key-active {
  border-color: var(--color-accent-pressed);
  background: var(--color-accent);
  animation: group-mode-pulse 1400ms ease-in-out infinite;
}

.group-mode-key svg {
  width: 26px;
  height: 26px;
}

.backspace-key svg {
  width: 38px;
  height: 38px;
}

.keypad-key:disabled {
  color: #7b8790;
  cursor: not-allowed;
}

.log-action {
  min-height: 56px;
  border: 0;
  border-radius: 10px;
  background: var(--color-accent);
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-size: clamp(25px, 8vw, 30px);
  font-weight: 700;
  letter-spacing: 0.015em;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.log-action:disabled {
  color: #5f6a72;
  background: var(--color-surface);
  cursor: not-allowed;
}

.modal-backdrop {
  position: absolute;
  z-index: 10;
  display: grid;
  inset: 0;
  padding: 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgb(3 26 45 / 58%);
  -webkit-overflow-scrolling: touch;
  place-items: center;
}

.entry-modal {
  width: min(100%, 350px);
  max-height: 100%;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-page);
  box-shadow: 0 12px 32px rgb(3 26 45 / 28%);
}

.entry-modal form {
  padding: 22px;
}

.delete-confirm-content {
  padding: 22px;
}

.entry-modal h2,
.entry-modal label,
.modal-actions button {
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-weight: 700;
  letter-spacing: 0.035em;
}

.entry-modal h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1;
}

.modal-context {
  margin: 7px 0 20px;
  color: var(--color-text-muted);
  font-size: 14px;
  font-weight: 600;
}

.delete-confirm-entry {
  margin: 9px 0 0;
  color: var(--color-ink);
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.delete-confirm-copy {
  margin: 16px 0 22px;
  color: var(--color-text-muted);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
}

.entry-modal label {
  display: block;
  margin-bottom: 7px;
  font-size: 16px;
}

.entry-modal input {
  width: 100%;
  height: 58px;
  padding: 6px 12px;
  border: 2px solid var(--color-border);
  border-radius: 9px;
  color: var(--color-ink);
  background: #fff;
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-size: 32px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.entry-modal input:focus {
  border-color: #1977b8;
  outline: 2px solid #1977b8;
  outline-offset: 1px;
}

.group-editor-fields {
  display: grid;
  gap: 8px;
}

.group-editor-fields-two-column {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.group-editor-field {
  min-width: 0;
}

.group-editor-field label {
  margin-bottom: 4px;
  font-size: 14px;
}

.group-editor-field input {
  height: 48px;
  font-size: 27px;
}

.modal-hint {
  margin: 7px 0 0;
  color: var(--color-text-muted);
  font-size: 13px;
  font-weight: 600;
}

.modal-error {
  min-height: 36px;
  margin: 5px 0 8px;
  color: #b42318;
  font-size: 13px;
  font-weight: 700;
  line-height: 18px;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.modal-actions button {
  min-height: 50px;
  border-radius: 9px;
  font-size: 18px;
  cursor: pointer;
}

.modal-cancel {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.modal-save {
  border: 1px solid var(--color-accent);
  background: var(--color-accent);
}

.modal-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--color-danger);
  color: #fff;
  background: var(--color-danger);
}

.modal-delete svg {
  width: 18px;
  height: 18px;
}

@media (hover: hover) and (pointer: fine) {
  .keypad-key:hover:not(:disabled) {
    background: #e7eaec;
  }

  .group-mode-key:hover:not(:disabled) {
    background: var(--color-group-idle-hover);
  }

  .group-mode-key-active:hover:not(:disabled),
  .log-action:hover:not(:disabled),
  .capture-options button.selected:hover {
    background: var(--color-accent-hover);
  }

  .recent-value-button:hover {
    color: #115f91;
    text-decoration: underline;
    text-underline-offset: 3px;
  }

  .recent-delete-action:hover,
  .modal-delete:hover {
    background: #8f1c14;
  }

  .modal-cancel:hover {
    background: var(--color-surface-pressed);
  }

  .modal-save:hover {
    background: var(--color-accent-hover);
  }
}

.keypad-key:active:not(:disabled),
.log-action:active:not(:disabled),
.capture-options button:active {
  background: var(--color-surface-pressed);
  transform: translateY(1px);
}

.group-mode-key:active:not(:disabled) {
  background: #f4d878;
}

.group-mode-key-active:active:not(:disabled),
.log-action:active:not(:disabled),
.capture-options button.selected:active {
  background: var(--color-accent-pressed);
}

.group-mode-key-active:active:not(:disabled) {
  animation-play-state: paused;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes local-entry-highlight {
  from {
    background-color: #fff0b8;
  }

  to {
    background-color: var(--color-page);
  }
}

@keyframes group-mode-pulse {
  0%,
  100% {
    border-color: var(--color-accent-pressed);
    background-color: var(--color-accent);
    box-shadow: inset 0 0 0 1px rgb(6 29 49 / 8%);
  }

  50% {
    border-color: #b97a00;
    background-color: #ffd36a;
    box-shadow: inset 0 0 0 3px rgb(6 29 49 / 18%);
  }
}

@keyframes submitted-bib-confirm {
  from {
    opacity: 0.7;
    transform: scale(0.98);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes submitted-bib-digit-out {
  from {
    opacity: 1;
    transform: translateY(0);
  }

  to {
    opacity: 0.3;
    transform: translateY(-4px);
  }
}

@media (max-width: 380px) {
  .race-header h1 {
    font-size: 21px;
  }
}

@media (max-width: 350px) {
  .race-header {
    padding-inline: 12px;
  }

  .logger-content {
    padding-inline: 8px;
  }

  .race-header h1 {
    font-size: 19px;
  }

  .recent-row {
    grid-template-columns: 0.9fr 1.45fr 0.85fr;
  }
}

@media (max-height: 820px) {
  .race-header {
    min-height: 48px;
    padding-top: calc(5px + env(safe-area-inset-top));
    padding-bottom: 5px;
  }

  .logger-content {
    grid-template-rows: 110px 118px 46px minmax(200px, 1fr) 54px;
    gap: 5px;
    padding-top: 7px;
    padding-bottom: calc(7px + env(safe-area-inset-bottom));
  }

  .recent-section h2 {
    font-size: 16px;
  }

  .recent-list {
    height: 88px;
    margin-top: 4px;
  }

  .recent-row {
    height: 44px;
    font-size: 16px;
  }

  .recent-row-shell:first-child:nth-last-child(3) {
    display: none;
  }

  .recent-empty {
    height: 88px;
    margin-top: 4px;
    font-size: 16px;
  }

  .recent-empty small {
    font-size: 11px;
  }

  .bib-section {
    grid-template-rows: minmax(0, 1fr) 18px;
  }

  .current-bib-panel,
  .group-roster {
    grid-template-rows: 18px minmax(0, 1fr);
  }

  .group-roster h2 {
    font-size: 14px;
  }

  .group-member {
    font-size: clamp(18px, 5.8vw, 21px);
  }

  .bib-value {
    font-size: 96px;
  }

  .group-mode-active .bib-value {
    font-size: clamp(68px, 23vw, 88px);
  }

  .group-mode-active .bib-value-empty {
    font-size: 58px;
  }

  .capture-options {
    height: 46px;
  }

  .group-mode-key svg {
    width: 22px;
    height: 22px;
  }

  .entry-modal form {
    padding: 18px;
  }
}

@media (max-height: 620px) {
  .race-header {
    min-height: 44px;
    padding-top: calc(4px + env(safe-area-inset-top));
    padding-bottom: 4px;
  }

  .header-row-primary {
    height: 32px;
  }

  .race-header h1 {
    font-size: 20px;
  }

  .race-time {
    font-size: 16px;
  }

  .logger-content {
    grid-template-rows: 88px 96px 44px minmax(188px, 1fr) 44px;
    gap: 4px;
    padding-top: 4px;
    padding-bottom: calc(4px + env(safe-area-inset-bottom));
  }

  .bib-value {
    font-size: 78px;
  }

  .bib-value-empty {
    font-size: 58px;
  }

  .group-mode-active .bib-value {
    font-size: clamp(60px, 20vw, 76px);
  }

  .group-mode-active .bib-value-empty {
    font-size: 54px;
  }

  .capture-options {
    height: 44px;
  }

  .keypad {
    grid-template-rows: repeat(4, minmax(44px, 1fr));
    gap: 4px;
  }

  .number-key {
    font-size: clamp(38px, 11vw, 46px);
  }

  .group-mode-key {
    font-size: 13px;
  }

  .group-mode-key svg {
    width: 20px;
    height: 20px;
  }

  .backspace-key svg {
    width: 32px;
    height: 32px;
  }

  .log-action {
    min-height: 44px;
    font-size: 24px;
  }

  .group-entry-modal form {
    padding: 14px;
  }

  .group-entry-modal .modal-context {
    margin-bottom: 12px;
  }

  .group-entry-modal .group-editor-fields {
    gap: 6px;
  }

  .group-entry-modal .group-editor-field input {
    height: 44px;
    font-size: 24px;
  }

  .group-entry-modal .modal-error {
    min-height: 18px;
    margin-bottom: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .group-mode-key-active {
    border-color: var(--color-accent-pressed);
    background: var(--color-accent);
    box-shadow: inset 0 0 0 2px rgb(6 29 49 / 16%);
  }
}
