/* GridRush — production layout: fixed chrome, reserved playfield, no overlap */

.gridrush-page .game-stage.gridrush-stage {
  display: flex;
  flex-direction: column;
  background: #12161e;
  min-height: 0;
  --gridrush-chrome-h: 44px;
  --gridrush-footer-h: 48px;
}

.gridrush-page .game-stage[data-theme="dark"] {
  background: #12161e;
}

.gridrush-page .game-stage[data-theme="dark"] .game-overlay {
  background: rgba(8, 12, 18, 0.94);
  color: #e6edf4;
}

.gridrush-page .game-stage[data-theme="dark"] .overlay-copy {
  color: #e6edf4;
}

/* ---- Chrome (single-row HUD) ---- */
.gridrush-chrome {
  position: relative;
  z-index: 5;
  flex: 0 0 auto;
  min-height: var(--gridrush-chrome-h);
  padding: 6px 8px;
  background: linear-gradient(180deg, #121820 0%, #0a0e14 100%);
  border-bottom: 1px solid rgba(225, 6, 0, 0.22);
}

.gridrush-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 32px;
}

.gridrush-hud-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.gridrush-score-line {
  display: flex;
  align-items: baseline;
  gap: 3px;
  margin: 0;
  line-height: 1;
}

.gridrush-score {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  color: #fff;
  text-shadow: 0 0 18px rgba(56, 189, 248, 0.35);
}

.gridrush-score-unit {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(230, 237, 244, 0.45);
}

.gridrush-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
  background: rgba(56, 189, 248, 0.16);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.gridrush-badge.is-hidden {
  display: none;
}

.gridrush-badge--flow {
  background: rgba(251, 191, 36, 0.2);
  color: #fde68a;
  border-color: rgba(251, 191, 36, 0.45);
}

.gridrush-hud-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.gridrush-best-line {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin: 0;
  line-height: 1;
}

.gridrush-best-label {
  font-family: var(--font-display);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(230, 237, 244, 0.42);
}

.gridrush-best-line strong {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: rgba(230, 237, 244, 0.88);
}

.gridrush-drivers-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 9px;
  min-height: 32px;
  border-radius: 999px;
  background: rgba(225, 6, 0, 0.14);
  color: #ffb4ab;
  font-family: var(--font-display);
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  border: 1px solid rgba(225, 6, 0, 0.28);
}

.gridrush-drivers-btn:hover,
.gridrush-drivers-btn:focus-visible {
  background: rgba(225, 6, 0, 0.32);
  outline: 2px solid rgba(225, 6, 0, 0.4);
  outline-offset: 2px;
}

.gridrush-drivers-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  pointer-events: none;
}

/* ---- Canvas playfield ---- */
.gridrush-canvas-wrap {
  position: relative;
  flex: 1 1 0;
  min-height: 120px;
  overflow: hidden;
}

.gridrush-stage canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.gridrush-play-hint {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  z-index: 3;
  margin: 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(8, 12, 18, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.72);
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 600;
  pointer-events: none;
  max-width: calc(100% - 24px);
  text-align: center;
  transition: opacity 0.25s ease;
}

.gridrush-play-hint.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.gridrush-play-hint--flow {
  color: #fde68a;
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(8, 12, 18, 0.82);
}

/* ---- Drivers panel ---- */
.gridrush-drivers-panel {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0;
  background: rgba(8, 12, 18, 0.82);
  backdrop-filter: blur(8px);
  touch-action: auto;
  -webkit-overflow-scrolling: touch;
}

.gridrush-drivers-panel.is-open {
  display: flex;
}

.gridrush-drivers-sheet {
  width: 100%;
  max-height: min(92%, 520px);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border-radius: 18px 18px 0 0;
  background: #fff;
  padding:
    16px 14px
    calc(14px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.28);
  touch-action: auto;
}

.gridrush-drivers-sheet h2 {
  font-family: var(--font-display);
  font-size: 1rem;
  margin-bottom: 4px;
  color: var(--ink);
}

.gridrush-drivers-sheet > p {
  font-size: 0.82rem;
  color: var(--ink-muted);
  margin-bottom: 12px;
  line-height: 1.45;
}

.gridrush-upload-msg {
  min-height: 1.2em;
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  color: #e10600;
}

.gridrush-upload-msg:empty {
  display: none;
}

.gridrush-face-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.gridrush-face-slot {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  min-width: 0;
}

.gridrush-file-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
  font-size: 16px;
}

.gridrush-face-upload {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 14px 12px;
  border-radius: 16px;
  border: 2px dashed rgba(21, 38, 54, 0.16);
  background: #f7f9fc;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.gridrush-face-upload:active {
  background: rgba(225, 6, 0, 0.06);
  border-color: rgba(225, 6, 0, 0.35);
}

.gridrush-face-upload-text {
  position: relative;
  z-index: 1;
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
}

.gridrush-face-name {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-align: center;
}

.gridrush-face-preview {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: 2px solid rgba(21, 38, 54, 0.1);
  background: #eef2f7;
  overflow: hidden;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.gridrush-face-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gridrush-face-preview > span {
  font-size: 2rem;
  line-height: 1;
}

.gridrush-drivers-actions {
  display: flex;
  gap: 8px;
  position: sticky;
  bottom: 0;
  padding-top: 4px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), #fff 24%);
}

.gridrush-drivers-actions button {
  flex: 1;
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  touch-action: manipulation;
}

.gridrush-drivers-done {
  background: linear-gradient(135deg, #e10600, #ff4d4d);
  color: #fff;
}

.gridrush-drivers-clear {
  background: #eef2f7;
  color: var(--ink);
}

@media (min-width: 520px) {
  .gridrush-drivers-panel {
    padding: 12px;
    justify-content: center;
  }

  .gridrush-drivers-sheet {
    max-height: min(82%, 440px);
    border-radius: 18px;
    padding-bottom: 14px;
  }

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

  .gridrush-face-upload {
    padding: 12px 8px;
  }

  .gridrush-face-preview {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    max-width: 88px;
  }
}

body.gridrush-drivers-open {
  touch-action: auto;
}

body.gridrush-drivers-open .game-stage {
  touch-action: auto;
}

body.gridrush-drivers-open .gridrush-canvas-wrap,
body.gridrush-drivers-open .gridrush-chrome {
  pointer-events: none;
}

body.gridrush-drivers-open .gridrush-drivers-panel {
  pointer-events: auto;
}

body.gridrush-drivers-open .game-controls {
  visibility: hidden;
  pointer-events: none;
}

/* ---- Mobile controls below stage ---- */
body.gridrush-page.has-mobile-controls {
  --gridrush-footer-h: 56px;
}

body.gridrush-page.has-mobile-controls .gridrush-play-hint {
  bottom: 10px;
}

/* ---- Desktop centered stage ---- */
@media (pointer: fine) and (hover: hover) and (min-height: 480px) {
  .gridrush-page .game-stage.gridrush-stage {
    --gridrush-chrome-h: 46px;
  }
}

@media (max-width: 380px) {
  .gridrush-score {
    font-size: 1.2rem;
  }

  .gridrush-best-line {
    display: none;
  }

  .gridrush-drivers-btn span {
    display: none;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .gridrush-page .game-stage.gridrush-stage {
    --gridrush-chrome-h: 40px;
    --gridrush-footer-h: 28px;
  }

  .gridrush-chrome {
    padding: 4px 8px;
  }

  .gridrush-badge {
    display: none;
  }

  .gridrush-play-hint {
    display: block;
    bottom: 4px;
    font-size: 0.58rem;
    max-width: calc(100% - 16px);
  }
}
