:root {
  --bg: #0a0b0d; /* near-black */
  --fg: #f2f5f8; /* near-white */
  --muted: #aeb6c2; /* light grey */
  --card: #101318; /* dark grey */
  --accent: #470aa1; /* theme purple */
  --accent-d: #3b0786; /* darker purple */
  /* Base header height only; filters and banners overlay and do not affect padding */
  --hdr-h: calc(env(safe-area-inset-top) + 72px);
}
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  padding-top: var(--hdr-h);
  min-height: 100%;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  overflow-x: hidden;
}

#app-root {
  opacity: 1;
  transition: opacity 0.3s ease;
}

body[data-loading="true"] #app-root {
  opacity: 0;
  pointer-events: none;
}

.app-loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d1014;
  z-index: 9999;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.4s ease, visibility 0s linear 0.4s;
}

.app-loading.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.app-loading__logo {
  width: min(280px, 60vw);
  max-width: 320px;
  animation: loading-pulse 1.2s ease-in-out forwards;
  will-change: transform;
}

@keyframes loading-pulse {
  0% {
    transform: scale(0.9);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(0.95);
  }
}
html {
  overflow-x: hidden;
}
[hidden] {
  display: none !important;
}
/* Layout helpers to mirror MMA Picks */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
}
.app-header {
  padding-top: env(safe-area-inset-top);
  background-color: rgba(0, 0, 0, 0.6) !important;
  border-bottom: 1px solid #1a1d23 !important;
}
header:not(.app-header) {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #10131a;
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid #1d2230;
}
header .left {
  display: flex;
  gap: 10px;
  align-items: center;
}
header h1 {
  margin: 0;
  font-size: 20px;
}
.subnav {
  display: flex;
  gap: 12px;
}
.subnav a {
  color: var(--muted);
  text-decoration: none;
}
.subnav a:hover {
  color: var(--fg);
}
.subnav .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #2a3140;
  border: 1px solid #3a4456;
}
.subnav .avatar span {
  display: block;
  text-align: center;
  line-height: 28px;
  font-weight: 700;
  color: #e9eef4;
}
main {
  padding: 16px;
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
  height: calc(100vh - var(--hdr-h) - env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: none;
  touch-action: pan-y;
}
.page-fill {
  min-height: calc(
    100vh - var(--hdr-h) - 32px - env(safe-area-inset-bottom, 0px)
  );
}

/* Page wrappers for sections */
.pagewrap {
  min-height: calc(100vh - var(--hdr-h) - env(safe-area-inset-bottom, 0px));
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}
/* Add bottom padding to events and race pages */
#pageEvents.pagewrap, #pageRace.pagewrap { padding-bottom: 50px; }
.card {
  background: #0e1014;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid #20242d;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset;
}
h2 {
  margin-top: 0;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.driver {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #0f1118;
  border-radius: 6px;
  padding: 12px;
}
.driver img {
  width: 100px;
  height: 100px;
  object-fit: cover;
  border-radius: 50%;
  border: 2px solid #222;
}
.muted {
  color: var(--muted);
}
.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #191c22;
  color: #d8dde6;
  font-size: 12px;
}
.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Ensure Race/Quali results tables span full width like Sessions */
#results-content {
  flex-direction: column;   /* override .row default */
  align-items: stretch;     /* make children fill width */
}
#results-content > div {
  width: 100%;              /* wrapper div spans full width */
}
#results-content table.tbl {
  width: 100%;              /* tables expand to container width */
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.filters {
  position: fixed;
  top: calc(var(--hdr-h) - 10px);
  left: 0;
  right: 0;
  z-index: 49;
  background: #0e1014;
  border-bottom: 1px solid #20242d;
  height: 44px;
  pointer-events: none;
  transform: translateZ(0);
}
.filters .page {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 44px;
}
.filters .toggle-past-btn{ pointer-events: auto; }
/* When filters are visible, push content so it doesn't hide underneath */
body.has-filters main {
  padding-top: calc(16px + 44px);
}

/* Prevent horizontal panning on race detail */
#pageRace,
#event-detail {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  touch-action: pan-y;
}

/* PWA banner fixed to bottom of the viewport */
#pwaBanner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px));
  z-index: 60;
}
.toggle-past-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  color: #e5e7eb;
}
.toggle-past-btn .box {
  width: 20px;
  height: 20px;
  border: 1px solid #2a3140;
  background: #0b0d13;
  border-radius: 4px;
  display: inline-grid;
  place-items: center;
  color: transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
#toggle-past + .toggle-past-btn .box::after {
  content: "✓";
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
}
#toggle-past:checked + .toggle-past-btn .box {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.toggle-past-btn:hover .box {
  border-color: #3a4356;
}
.toggle-past-btn .text {
  font-weight: 600;
}
.wx {
  width: 40px;
  text-align: center;
  white-space: nowrap;
}
.w120 {
  width: 120px;
  display: inline-block;
}
.w80 {
  width: 80px;
}
.w100 {
  width: 100px;
}
.w60 {
  width: 60px;
}
.nowrap {
  white-space: nowrap;
}
.pickform label {
  color: #cbd2dc;
}

/* Main menu list */
.event-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
@media (min-width: 900px) {
  .event-list {
    grid-template-columns: 1fr 1fr;
  }
}
.event {
  position: relative;
  display: grid;
  grid-template-columns: 200px 1fr;
  align-items: center;
  gap: 12px;
  background: #0f1116;
  border-radius: 10px;
  padding: 10px;
  border: 1px solid #262a33;
}
.event .title {
  font-weight: 600;
}
.event .times {
  display: block;
  margin-top: 6px;
}
@media (max-width: 560px) {
  .event {
    grid-template-columns: 120px 1fr;
  }
}
.event.past {
  opacity: 0.45;
  filter: saturate(0.7);
}
.event.past .title {
  text-decoration: none;
}
.event.next {
  border: 2px solid var(--accent);
}

/* Track map */
.track {
  position: relative;
  width: 100%;
  height: 92px;
  border-radius: 6px;
  background: #0a0c10;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.track img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0.95;
  position: relative;
  z-index: 1;
}
.track .badge {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 2;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent-d);
}
@media (max-width: 560px) {
  .track {
    height: 72px;
  }
}
/* Badge indicating user has saved picks */
.picked-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
}
/* Points badge for past events */
.points-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: #1c212d;
  color: #e9eef4;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  border: 1px solid #2a3140;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
}

/* Details summary */
details.card {
  padding: 0;
}
details.card > .summary {
  display: block;
  padding: 12px 16px;
  cursor: pointer;
}
details.card[open] > .summary {
  border-bottom: 1px solid #252a36;
}
details.card > .event-list {
  padding: 12px 16px;
}

/* Past Races controls moved to checkbox toggle */

/* Standings */
.standings {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
/* Keep standings tables full-width on desktop as well */
@media (min-width: 900px) {
  .standings {
    grid-template-columns: 1fr;
  }
}
.tbl {
  width: 100%;
  border-collapse: collapse;
}
.tbl th,
.tbl td {
  padding: 8px;
  border-bottom: 1px solid #252a36;
  text-align: left;
}
.tbl th {
  color: #cbd2dc;
  font-weight: 600;
}
.delta-up {
  color: #22c55e;
  font-weight: 600;
}
.delta-down {
  color: #ef4444;
  font-weight: 600;
}
.delta-flat {
  color: var(--muted);
}
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-right: 8px;
  vertical-align: middle;
  border: 1px solid rgba(0, 0, 0, 0.35);
}
.list {
  margin: 0;
  padding-left: 18px;
}
.list li {
  margin: 4px 0;
  color: #e9eef4;
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid #2b2f3a;
  background: #12151b;
  color: #f2f5f8;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}
.btn:hover {
  border-color: #3a3f4b;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* DaisyUI button overrides to use F1 red and dark neutrals */
.btn.btn-primary {
  background-color: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #fff !important;
}
.btn.btn-primary:hover {
  background-color: var(--accent-d) !important;
  border-color: var(--accent-d) !important;
}
.btn.btn-outline {
  border-color: #3a3f4b !important;
  color: #e5eaf1 !important;
}
.btn.btn-outline:hover {
  background-color: #161a21 !important;
}
.btn.btn-ghost {
  color: #e5eaf1 !important;
}
.btn.btn-danger-outline {
  border-color: var(--accent) !important;
  color: var(--accent) !important;
  background: transparent !important;
}
.btn.btn-danger-outline:hover {
  background-color: rgba(225, 6, 0, 0.12) !important;
}
/* Muted disabled look for Save button without red outline */
#save-pick[disabled] {
  background: #161a21 !important;
  color: #8a93a5 !important;
  border-color: #2a3140 !important;
  cursor: not-allowed !important;
}

/* Event detail layout (MMA Picks-like) */
.event-head {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
.event-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.picks-section {
  padding-top: 0;
  border-top: none;
}
.picks-toolbar {
  justify-content: flex-start;
  align-items: stretch;
  margin: 4px 0 12px;
  flex-direction: column;
  gap: 8px;
}
.picks-toolbar__buttons {
  justify-content: flex-start;
  align-items: stretch;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}
.picks-actions {
  display: flex;
  justify-content: flex-start;
  align-items: stretch;
  gap: 25px;
  width: 100%;
  flex-direction: column;
  margin-top: 16px;
}
.picks-toolbar__buttons .btn,
.picks-actions .btn {
  width: 100%;
  max-width: 100%;
}
.picks-card {
  background: #0f1118;
  border: 1px solid #21283a;
  border-radius: 10px;
  padding: 12px;
}
.picks-table {
  width: 100%;
}
.picks-table th,
.picks-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #232833;
  vertical-align: top;
}
.picks-table th {
  width: 180px;
  font-weight: 600;
  color: #cbd2dc;
}
.picks-table .select,
.picks-table select,
.picks-table .input,
.picks-table input,
.picks-table textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.picks-table td .mono {
  opacity: 0.8;
  margin-left: 6px;
}
.picks-table tr:last-child th,
.picks-table tr:last-child td {
  border-bottom: none;
}
@media (max-width: 540px) {
  .form {
    grid-template-columns: 1fr;
  }
}
@media (min-width: 720px) {
  .picks-toolbar {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }
  .picks-toolbar__buttons {
    flex-direction: row;
    justify-content: flex-end;
    gap: 25px;
    width: auto;
  }
  .picks-toolbar__buttons .btn {
    width: auto;
    min-width: 140px;
  }
  .picks-actions {
    flex-direction: row;
    align-items: center;
    gap: 25px;
    margin-top: 20px;
  }
  .picks-actions .btn {
    width: auto;
    min-width: 160px;
  }
}
.label {
  color: #cbd2dc;
}
.control {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.podium-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pod-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.medal {
  font-size: 18px;
  line-height: 1;
  align-self: center;
  margin-left: 6px;
  margin-right: 0;
}
.bold-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.bold-grid .select {
  min-width: 260px;
}
.input,
.select {
  background: #0b0d13;
  border: 1px solid #2a3140;
  border-radius: 8px;
  color: #e9eef4;
  padding: 8px 10px;
}
.input {
  min-width: 120px;
}
.select {
  min-width: 180px;
}
.podium .input {
  width: 90px;
}
/* Modal */
#modal[hidden] {
  display: none;
}
#modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 100;
}
#modal .backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.86);
}
#modal .modal-panel {
  position: relative;
  z-index: 101;
  background: #0f1118;
  border: 1px solid #2a3140;
  border-radius: 8px;
  padding: 16px;
  min-width: 320px;
  max-width: 90vw;
}
#modal input {
  background: #0b0d13;
  border: 1px solid #2a3140;
  border-radius: 6px;
  color: #e9eef4;
  padding: 6px 8px;
}

/* Profile modal */
#profile-modal[hidden] {
  display: none;
}
#profile-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 100;
}
#profile-modal .backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.86);
}
#profile-modal .modal-panel {
  position: relative;
  z-index: 101;
  background: #0f1118;
  border: 1px solid #2a3140;
  border-radius: 8px;
  padding: 16px;
  min-width: 320px;
  max-width: 92vw;
  width: min(540px, 92vw);
}
#profile-modal input {
  background: #0b0d13;
  border: 2px solid var(--accent);
  border-radius: 8px;
  color: #e9eef4;
  padding: 12px 14px;
  font-size: 16px;
  min-height: 44px;
  min-width: 260px;
  margin: 20px 0;
}

/* Profile page inputs (bigger, purple outline) */
#profile-page input {
  background: #0b0d13;
  border: 2px solid var(--accent);
  border-radius: 8px;
  color: #e9eef4;
  padding: 12px 14px;
  font-size: 16px;
  min-height: 44px;
  min-width: 260px;
  margin: 20px 0;
}

/* Profile heading styling */
#profile-page h3 {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 50px 0;
}

/* Improve focus visibility */
#profile-page input:focus,
#profile-modal input:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(71, 10, 161, 0.35);
  border-color: var(--accent);
}

/* Rules modal uses same styling as profile */
#rules-modal[hidden] {
  display: none;
}
#rules-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 100;
}
#rules-modal .backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.86);
}
#rules-modal .modal-panel {
  position: relative;
  z-index: 101;
  background: #0f1118;
  border: 1px solid #2a3140;
  border-radius: 8px;
  padding: 16px;
  min-width: 320px;
  max-width: 92vw;
  width: min(540px, 92vw);
}

/* AI prediction modal mirrors rules modal styling */
#ai-modal[hidden] {
  display: none;
}
#ai-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 100;
}
#ai-modal .backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.86);
}
#ai-modal .modal-panel {
  position: relative;
  z-index: 101;
  background: #0f1118;
  border: 1px solid #2a3140;
  border-radius: 8px;
  padding: 18px;
  width: min(420px, 92vw);
  box-shadow: 0 18px 32px rgba(0, 0, 0, 0.45);
}

.ai-line {
  font-weight: 600;
  font-size: 18px;
}
.ai-podium {
  margin: 0;
  padding-left: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-podium li {
  font-weight: 600;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ai-podium li .muted {
  display: block;
  font-size: 13px;
  margin-top: 4px;
}
.ai-podium li .pill {
  margin-right: 6px;
}
.ai-podium-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Chips for quick driver pick */
.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chip {
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid #2b3243;
  background: #0e1219;
  color: #cfd6e3;
  cursor: pointer;
  font-size: 12px;
}
.chip:hover {
  border-color: #3a4356;
}

/* Ensure Standings card fills the viewport height so its background doesn't cut off */
#pageStandings {
  min-height: calc(100vh - var(--hdr-h) - env(safe-area-inset-bottom, 0px));
}
#pageStandings #standings.card {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}
#pageStandings .standings {
  flex: 1;
}

/* Toast */
#toast {
  position: fixed;
  top: calc(env(safe-area-inset-top));
  left: 0;
  right: 0;
  z-index: 9999;
  background: #111418;
  color: #e9eef4;
  border: 1px solid #252a36;
  border-radius: 0;
  padding: 12px 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transform: scaleY(0.98);
  transform-origin: top center;
  overflow: hidden;
}
#toast.show {
  animation: toastIn 0.18s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}
#toast.hiding {
  animation: toastOut 0.22s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}
@keyframes toastIn {
  from {
    transform: scaleY(0.92);
    opacity: 0;
  }
  to {
    transform: scaleY(1);
    opacity: 1;
  }
}
@keyframes toastOut {
  from {
    transform: scaleY(1);
    opacity: 1;
  }
  to {
    transform: scaleY(0.92);
    opacity: 0;
  }
}

/* Toast success variant */
#toast.toast-success {
  background: #14532d;
  border-color: #14532d;
  color: #ecfdf5;
}
#toast.toast-success .toast-progress {
  background: #22c55e;
}
/* Toast error variant */
#toast.toast-error {
  background: #3a0c0c;
  border-color: #7f1d1d;
  color: #fee2e2;
}
#toast.toast-error .toast-progress {
  background: #470aa1;
}

/* Toast contents */
#toast .toast-msg {
  font-weight: 600;
}
#toast .toast-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: #34d399;
}
.toast-progress.shrink {
  animation: toastProgress var(--toast-duration, 2000ms) linear forwards;
}
@keyframes toastProgress {
  from {
    width: 100%;
  }
  to {
    width: 0%;
  }
}

/* Compact UI tweaks for small phones */
@media (max-width: 420px) {
  body {
    font-size: 14px;
  }
  main {
    padding: 12px;
  }
  .card {
    padding: 12px;
  }
  .row {
    gap: 6px;
  }
  .btn {
    padding: 6px 10px;
    font-size: 13px;
  }
  .btn.btn-sm {
    padding: 4px 8px;
    font-size: 12px;
  }
  .input,
  .select {
    padding: 6px 8px;
    font-size: 14px;
    min-width: 0;
    width: 100%;
  }
  .tbl th,
  .tbl td {
    padding: 6px;
  }
  .picks-table th {
    width: 120px;
  }
  .picks-table th,
  .picks-table td {
    word-break: break-word;
  }
  .picks-card {
    padding: 10px;
  }
  .picks-table th,
  .picks-table td {
    padding: 8px 10px;
  }
  .picks-section {
    padding-top: 10px;
  }
  .event {
    gap: 8px;
    padding: 8px;
  }
  header.app-header .page {
    padding-left: 12px;
    padding-right: 12px;
  }
}
