:root {
  color-scheme: dark;
  --bg: #0f172a;
  --panel: #182033;
  --panel-strong: #202a40;
  --text: #f8fafc;
  --muted: #a7b0c2;
  --line: rgba(255, 255, 255, 0.11);
  --path: #2f9f80;
  --path-dark: #16745e;
  --road: #d7613a;
  --road-dark: #a33f25;
  --focus: #f8d76e;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 32%),
    var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

button:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

.name-screen {
  min-height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 16px;
  padding: 18px;
}

.ride-ended-screen {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 22px;
  text-align: center;
}

.ride-ended-screen > div {
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 24px 18px;
}

.ride-ended-screen h1 {
  font-size: clamp(32px, 9vw, 54px);
  line-height: 1;
}

.ride-ended-screen p:last-child {
  margin: 14px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.entry-header {
  width: min(460px, 100%);
}

.entry-header h1 {
  margin: 0;
  font-size: 38px;
  line-height: 1;
}

.entry-grid {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.name-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
}

#createRideForm[hidden] + #joinRideForm {
  width: 100%;
  max-width: 460px;
  grid-column: 1 / -1;
  justify-self: center;
}

.name-card h2 {
  margin: 0 0 16px;
  font-size: 24px;
  line-height: 1.1;
}

.name-card label {
  display: block;
  margin: 14px 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.name-card input {
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
  color: var(--text);
  font: inherit;
  font-size: 20px;
  padding: 0 14px;
}

.name-card button {
  width: 100%;
  min-height: 58px;
  margin-top: 12px;
  border-radius: 8px;
  background: var(--path-dark);
  font-weight: 800;
}

.entry-status {
  grid-column: 1 / -1;
  min-height: 22px;
  margin: 0;
  color: var(--focus);
  font-weight: 800;
  text-align: center;
}

.leader-access-link {
  grid-column: 1 / -1;
  margin: 0;
  text-align: center;
  font-weight: 800;
}

.leader-access-link a,
.back-link {
  color: #bfdbfe;
}

.leader-entry-grid {
  max-width: 520px;
  grid-template-columns: 1fr;
}

.name-card .secondary-button {
  background: #24324d;
  border-color: rgba(191, 219, 254, 0.25);
}

.leader-code-display {
  margin: 6px 0 2px;
  border: 1px solid rgba(191, 219, 254, 0.25);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.72);
  color: #facc15;
  font-size: 2.4rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-align: center;
}

.app-shell {
  min-height: 100%;
  width: min(760px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(86px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.tab-panel {
  display: none;
}

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

.bottom-tabs {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 10;
  width: min(760px, 100%);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 6px;
  padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.97);
}

.bottom-tabs button {
  min-height: 54px;
  border-radius: 8px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  font-weight: 900;
}

.bottom-tabs button.active {
  background: #31558f;
  color: var(--text);
}

.alert-status-row {
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
  color: #f8d76e;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.controls-locked-notice {
  margin-bottom: 7px;
  border: 1px solid rgba(248, 215, 110, 0.35);
  border-radius: 8px;
  background: rgba(112, 93, 26, 0.36);
  color: #f8d76e;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 900;
  text-align: center;
}

.leader-message-banner {
  margin-bottom: 7px;
  border: 2px solid rgba(248, 215, 110, 0.75);
  border-radius: 8px;
  background: linear-gradient(180deg, #31290d, #1f1a0b);
  color: #fff7cc;
  padding: 8px 10px;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.16);
}

.leader-message-banner span {
  display: block;
  color: #f8d76e;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.leader-message-banner strong {
  display: block;
  margin-top: 2px;
  font-size: clamp(18px, 5vw, 24px);
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.leader-message-banner.flash {
  animation: pulse 900ms ease-out 1;
}

.leader-panel {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 32, 51, 0.9);
  padding: 12px;
}

.leader-panel > div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
  padding: 10px;
}

.leader-panel span,
.leader-panel strong {
  display: block;
}

.leader-panel span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.leader-panel strong {
  margin-top: 4px;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.leader-panel #leaderRideCode {
  font-size: 32px;
  letter-spacing: 2px;
}

.leader-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  background: transparent !important;
  border: 0 !important;
  padding: 0 !important;
}

.leader-actions button {
  min-height: 52px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: #31558f;
  font-weight: 800;
}

.leader-actions #endRide {
  background: #861f35;
}

.leader-actions #toggleRiderControls.ready,
.leader-actions #toggleAnnouncement.ready {
  background: #16745e;
  color: #eafff7;
}

.leader-rider-actions {
  grid-column: 1 / -1;
}

.leader-message-form {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
  padding: 10px;
}

.leader-message-form label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.leader-message-form .announcement-row {
  grid-template-columns: 1fr 78px 78px;
}

.leader-message-form .clear-leader-message {
  background: #705d1a;
}

.leader-rider-actions > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.leader-rider-actions li {
  grid-template-columns: minmax(0, 1fr);
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.leader-rider-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.leader-rider-buttons button {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: #31558f;
  font-weight: 800;
}

.leader-rider-buttons button:first-child {
  background: #861f35;
}

.leader-rider-buttons button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.copyright-mark {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
}

h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1;
}

.app-version {
  display: inline-block;
  vertical-align: middle;
  margin-left: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(49, 85, 143, 0.32);
  color: #b8d3ff;
  padding: 3px 7px;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

.status-pill {
  flex: 0 0 auto;
  min-width: 112px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.status-pill.online {
  background: rgba(47, 159, 128, 0.18);
  color: #b8f4df;
}

.status-pill.offline {
  background: rgba(215, 97, 58, 0.18);
  color: #ffd0bf;
}

.ride-mode-panel {
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 32, 51, 0.9);
  padding: 12px;
}

.ride-mode-button {
  width: 100%;
  min-height: 58px;
  border-radius: 8px;
  background: #861f35;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #fff1f3;
  font-size: 18px;
  font-weight: 900;
  text-transform: uppercase;
  display: grid;
  place-items: center;
  cursor: default;
  user-select: none;
}

.ride-mode-button.active {
  background: #16745e;
  color: #eafff7;
  border-color: rgba(184, 244, 223, 0.45);
}

.ride-status-grid,
.info-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.ride-status-grid {
  margin-top: 8px;
}

.location-privacy-note {
  margin: 9px 0 0;
  border: 1px solid rgba(184, 211, 255, 0.2);
  border-radius: 8px;
  background: rgba(17, 24, 39, 0.72);
  color: #dbeafe;
  padding: 9px 10px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.25;
}

.info-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 32, 51, 0.9);
  padding: 12px;
}

.ride-status-grid div,
.info-panel div {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
  padding: 8px 10px;
}

.ride-status-grid span,
.ride-status-grid strong,
.info-panel span,
.info-panel strong,
.info-code-button {
  display: block;
}

.ride-status-grid span,
.info-panel span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.ride-status-grid strong,
.info-panel strong {
  margin-top: 4px;
  font-size: 14px;
}

.info-code-button {
  width: 100%;
  margin-top: 4px;
  border-radius: 6px;
  background: #31558f;
  color: var(--text);
  padding: 6px 8px;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 1px;
  line-height: 1;
  text-align: center;
}

.info-action-panel {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 32, 51, 0.9);
  padding: 12px;
}

.ride-status-grid strong[data-state="ok"],
.info-panel strong[data-state="ok"] {
  color: #b8f4df;
}

.ride-status-grid strong[data-state="warn"],
.info-panel strong[data-state="warn"] {
  color: #f8d76e;
}

.secondary-button,
.icon-button,
.quick-row button {
  min-height: 52px;
  border-radius: 8px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  font-weight: 800;
}

.secondary-button.ready {
  background: #213f38;
  color: #c6f8e7;
}

.alert-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.alert-button {
  min-height: clamp(68px, 11vh, 88px);
  border-radius: 8px;
  padding: 7px 6px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.17);
  text-transform: uppercase;
  touch-action: manipulation;
}

.alert-button.path {
  background: linear-gradient(180deg, var(--path), var(--path-dark));
}

.alert-button.road {
  background: linear-gradient(180deg, var(--road), var(--road-dark));
}

.alert-button span {
  font-size: clamp(14px, 3.8vw, 21px);
  font-weight: 800;
  line-height: 1;
}

.alert-button strong {
  margin-top: 3px;
  font-size: clamp(22px, 6.6vw, 38px);
  line-height: 0.95;
}

.alert-button:active,
.quick-row button:active,
.turn-row button:active,
.secondary-button:active,
.icon-button:active {
  transform: translateY(2px);
}

.quick-row,
.turn-row {
  display: grid;
  gap: 6px;
  margin-top: 7px;
}

.quick-row {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.turn-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.quick-row button,
.turn-row button {
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: 5px 6px;
  font-size: clamp(12px, 3.2vw, 15px);
  font-weight: 900;
  line-height: 1.05;
  text-transform: uppercase;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.16);
}

.quick-row .quick-slowing {
  background: linear-gradient(180deg, #d19a22, #8f6110);
  color: #fff8d8;
}

.quick-row .quick-stopping {
  background: linear-gradient(180deg, #d33b45, #8d1f2e);
  color: #fff1f3;
}

.quick-row .quick-all-on {
  background: linear-gradient(180deg, #2f9f80, #16745e);
  color: #eafff7;
}

.quick-row .quick-walkers {
  background: linear-gradient(180deg, #8b5cf6, #5b21b6);
  color: #f5f3ff;
}

.quick-row .quick-clear {
  background: linear-gradient(180deg, #4f6fa8, #31558f);
  color: #eef5ff;
}

.turn-row .turn-button {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
}

.turn-row .turn-left {
  background: linear-gradient(180deg, #4f6fa8, #29466f);
  color: #eef5ff;
}

.turn-row .turn-straight {
  background: linear-gradient(180deg, #40775f, #245442);
  color: #ecfff7;
}

.turn-row .turn-right {
  background: linear-gradient(180deg, #6c5aa8, #413173);
  color: #f4f0ff;
}

.turn-row .turn-button span {
  display: block;
  font-size: clamp(24px, 7vw, 32px);
  font-weight: 900;
  line-height: 0.85;
}

.turn-row .turn-button small {
  display: block;
  font-size: clamp(11px, 3vw, 13px);
  font-weight: 900;
  line-height: 1;
}

.assist-row {
  margin-top: 7px;
}

.assist-row button {
  width: 100%;
  min-height: 52px;
  border-radius: 8px;
  background: linear-gradient(180deg, #bf2f4a, #861f35);
  border: 1px solid rgba(255, 255, 255, 0.16);
  font-size: clamp(17px, 4.8vw, 24px);
  font-weight: 900;
  text-transform: uppercase;
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.17);
}

.assist-row button:active {
  transform: translateY(2px);
}

.latest-panel,
.log-panel,
.announcement-panel,
.voice-panel,
.info-panel,
.riders-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 32, 51, 0.9);
}

.latest-panel,
.announcement-panel,
.voice-panel,
.info-panel,
.riders-panel {
  padding: 12px;
}

.compact-latest {
  margin-top: 7px;
  padding: 9px 12px;
}

.compact-latest p {
  margin-bottom: 3px;
}

.compact-latest strong {
  font-size: 18px;
}

.voice-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.voice-meter {
  min-height: 46px;
  margin-bottom: 10px;
  border-radius: 8px;
  background: #111827;
  border: 1px solid var(--line);
  color: var(--text);
  display: grid;
  place-items: center;
  padding: 10px;
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.25;
}

.voice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.voice-row button {
  min-height: 58px;
  border-radius: 8px;
  background: #7a3650;
  border: 1px solid rgba(255, 255, 255, 0.16);
  font-weight: 800;
}

.voice-row button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.announcement-panel label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.announcement-row {
  display: grid;
  grid-template-columns: 1fr 118px;
  gap: 8px;
}

.announcement-row.rider-message-row {
  grid-template-columns: 1fr 94px 104px;
}

.announcement-panel.leader-only-mode .rider-message-row {
  grid-template-columns: 1fr 112px;
}

.announcement-row input {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
  color: var(--text);
  font: inherit;
  font-size: 18px;
  padding: 0 13px;
}

.announcement-row input::placeholder {
  color: #758095;
}

.announcement-row input:focus {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

.announcement-row button {
  min-height: 48px;
  border-radius: 8px;
  background: #31558f;
  border: 1px solid rgba(255, 255, 255, 0.16);
  font-size: 15px;
  font-weight: 800;
}

.announcement-row .leader-only-button {
  background: #705d1a;
  color: #fff7cc;
}

.latest-panel p {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.latest-panel strong {
  display: block;
  font-size: clamp(23px, 7vw, 40px);
  line-height: 1.05;
}

.play-voice-button,
.log-play-button,
.location-link,
.close-app-button {
  min-height: 44px;
  border-radius: 8px;
  background: #31558f;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text);
  font-weight: 800;
}

.play-voice-button,
.close-app-button {
  width: 100%;
  margin-top: 12px;
}

.close-app-button {
  background: #861f35;
}

.close-help {
  margin: 10px 0 0;
  color: #f8d76e;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
}

.log-play-button {
  grid-column: 1 / -1;
}

.location-link {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  text-decoration: none;
}

.latest-panel.flash {
  animation: flash 420ms ease-out;
}

.log-panel {
  overflow: hidden;
}

.log-tab .log-panel,
.riders-tab .riders-panel {
  max-height: calc(100vh - 170px);
  overflow-y: auto;
}

.log-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.rider-list {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

li strong {
  grid-column: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

li small {
  grid-column: 1;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

li:last-child {
  border-bottom: 0;
}

li span {
  grid-column: 2;
  grid-row: 1 / span 2;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.location-unavailable {
  grid-column: 1 / -1;
  color: #f8d76e;
  font-style: normal;
  font-weight: 800;
}

#riderRoster li {
  grid-template-columns: minmax(0, 1fr) auto;
}

#riderRoster small {
  grid-column: 1 / -1;
}

#riderRoster .rider-offline {
  opacity: 0.68;
}

#riderRoster .rider-offline span {
  color: #f8d76e;
}

@keyframes flash {
  0% {
    border-color: var(--focus);
    transform: scale(1.01);
  }
  100% {
    border-color: var(--line);
    transform: scale(1);
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .app-shell {
    width: min(1040px, 100%);
    padding: 12px;
  }

  .topbar {
    margin-bottom: 10px;
  }

  h1 {
    font-size: 28px;
  }

  .alert-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .alert-button {
    min-height: 82px;
  }

  .latest-panel,
  .log-panel,
  .announcement-panel,
  .voice-panel,
  .info-panel,
  .riders-panel {
    margin-top: 10px;
  }
}

@media (max-width: 390px) {
  .announcement-row {
    grid-template-columns: 1fr 104px;
  }

  .ride-status-grid,
  .info-panel {
    grid-template-columns: 1fr;
  }

  .alert-button {
    min-height: 64px;
  }
}

@media (max-width: 720px) {
  .entry-grid,
  .leader-panel {
    grid-template-columns: 1fr;
  }

  .leader-actions {
    grid-template-columns: 1fr;
  }
}
