:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-elevated: #243044;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --border: #2d3a4f;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --correct: #22c55e;
  --correct-bg: rgba(34, 197, 94, 0.18);
  --partial: #eab308;
  --partial-bg: rgba(234, 179, 8, 0.18);
  --wrong: #64748b;
  --wrong-bg: rgba(100, 116, 139, 0.15);
  --higher: #38bdf8;
  --higher-bg: rgba(56, 189, 248, 0.15);
  --lower: #a78bfa;
  --lower-bg: rgba(167, 139, 250, 0.15);
  --error: #f87171;
  --radius: 8px;
  --font: Arial, Helvetica, sans-serif;
  /* card/search sizing */
  --card-width: 510px; /* preferred max width for guess/results card */
  --search-offset: 56px; /* search bar is slightly wider than the card */
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

.game-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--navbar-height, 64px));
}

.game-shell > .app,
.game-shell > .loading,
.game-shell > .error {
  flex: 1;
  width: 100%;
}

.hidden {
  display: none !important;
}


/* Loading & error */

.loading,
.error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  gap: 1rem;
  color: var(--text-muted);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.error p {
  color: var(--error);
}

/* App layout */

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.guess-counter {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  align-self: flex-end;
}

/* Search stack: counter above (right), search bar slightly wider than cards */

.search-section {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  width: min(100%, calc(var(--card-width) + var(--search-offset)));
  margin: 0 auto 0.5rem;
}

.search-wrapper {
  position: relative;
  width: 100%;
  min-width: 0;
}

.search-input {
  width: 100%;
  padding: 0.75rem 3rem 0.75rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s;
}

.search-input:focus {
  border-color: var(--accent);
}

.search-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.search-submit-btn {
  position: absolute;
  top: 50%;
  right: 4px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  transform: translateY(-50%);
  transition: color 0.15s, background 0.15s, opacity 0.15s;
}

.search-submit-btn:hover:not(:disabled),
.search-submit-btn:focus-visible:not(:disabled) {
  color: #fff;
  background: rgba(59, 130, 246, 0.18);
  outline: none;
}

.search-submit-btn:focus-visible:not(:disabled) {
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.45);
}

.search-submit-btn:active:not(:disabled) {
  background: rgba(59, 130, 246, 0.28);
}

.search-submit-btn:disabled {
  color: var(--text-muted);
  opacity: 0.45;
  cursor: not-allowed;
}

.search-submit-icon {
  display: block;
  width: 20px;
  height: 20px;
}

.search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 100;
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  max-height: 280px;
  overflow-y: auto;
}

.search-dropdown li {
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-size: 0.95rem;
}

.search-dropdown li:hover,
.search-dropdown li.active {
  background: var(--surface);
}

.play-again-btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.play-again-btn:hover {
  background: var(--accent-hover);
}


.search-error {
  margin: 0;
  font-size: 0.875rem;
  color: var(--error);
  text-align: left;
  align-self: flex-start;
}

.mode-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.mode-label {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  white-space: nowrap;
}

.daily-done-note {
  margin: 0.85rem auto 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 22rem;
}

.next-car-countdown {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}

.play-unlimited-link {
  display: inline-block;
  margin-top: 0.6rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.play-unlimited-link:hover {
  color: var(--accent-hover);
}

/* Board */

.board-section {
  margin-top: 1.5rem;
}

.empty-hint {
  margin: 0 0 0.75rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
}

.status-note {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.92rem;
  text-align: center;
}

.guess-cards {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.guess-card {
  display: grid;
  /* Keep the guess/results card centered and constrained by --card-width */
  width: min(100%, var(--card-width));
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 1.25);
  background: var(--surface);
  box-shadow: 0 18px 35px rgba(0, 0, 0, 0.12);
  opacity: 1;
  transform: translateY(0);
  margin: 0 auto;
}

.guess-card--new {
  animation: fadeSlideIn 0.36s ease both;
}

.guess-card--win {
  border-color: rgba(34, 197, 94, 0.55);
  box-shadow:
    0 0 0 1px rgba(250, 204, 21, 0.35),
    0 0 28px rgba(34, 197, 94, 0.35),
    0 0 48px rgba(250, 204, 21, 0.18),
    0 18px 35px rgba(0, 0, 0, 0.12);
}

.guess-card--win .guess-tile {
  transform-origin: center bottom;
  animation: winTileFlip 0.38s ease both;
}

.guess-card--win .guess-card-grid {
  perspective: 700px;
}

.guess-card--win .guess-tile:nth-child(1) { animation-delay: 0.02s; }
.guess-card--win .guess-tile:nth-child(2) { animation-delay: 0.06s; }
.guess-card--win .guess-tile:nth-child(3) { animation-delay: 0.1s; }
.guess-card--win .guess-tile:nth-child(4) { animation-delay: 0.14s; }
.guess-card--win .guess-tile:nth-child(5) { animation-delay: 0.18s; }
.guess-card--win .guess-tile:nth-child(6) { animation-delay: 0.22s; }
.guess-card--win .guess-tile:nth-child(7) { animation-delay: 0.26s; }

@keyframes winTileFlip {
  0% {
    transform: rotateX(78deg) scale(0.92);
    opacity: 0.35;
  }
  55% {
    transform: rotateX(-8deg) scale(1.04);
    opacity: 1;
  }
  100% {
    transform: rotateX(0) scale(1);
    opacity: 1;
  }
}

.guess-card-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.guess-card-avatar {
  width: 56px;
  height: 56px;
  min-width: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  padding: 6px;
  overflow: hidden;
  color: var(--accent);
  background: rgba(238, 242, 255, 0.956);
  border: 1px solid rgba(0, 51, 133, 0.22);
}

.guess-card-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.guess-card-avatar-fallback {
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
}

.guess-card-photo {
  margin-top: 1rem;
  min-height: 120px;
  border-radius: 0.75rem;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.18);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1rem;
}

.guess-card-photo:empty,
.guess-card-photo:not(:has(.guess-card-photo-img)) {
  min-height: 120px;
}

.guess-card-photo-img {
  width: 100%;
  max-height: 140px;
  object-fit: contain;
  display: block;
}

.guess-card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.guess-card-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  gap: 0.65rem;
  align-items: stretch;
  width: 100%;
}

.guess-tile {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 0.4rem;
  padding: 0.75rem 0.85rem;
  border-radius: 1rem;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  flex: 0 0 auto;
  width: max-content;
  min-width: 4.75rem;
  max-width: 100%;
  min-height: 0;
  height: auto;
  box-sizing: border-box;
}

.guess-tile--wide {
  min-width: 6.5rem;
}

.guess-tile--compact {
  padding: 0.65rem 0.75rem;
}

.guess-tile--engine {
  min-width: 7rem;
}

.tile-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.tile-value {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.5rem;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  width: 100%;
}

.tile-text {
  min-width: 0;
  flex: 1 1 auto;
}

.tile-flag {
  flex-shrink: 0;
  margin-left: auto;
  font-size: 1.2rem;
  line-height: 1;
}

.guess-tile--compact .tile-value {
  gap: 0.35rem;
}

.tile-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.16);
  color: var(--correct);
  font-size: 0.9rem;
}

.guess-tile--higher .tile-badge,
.guess-tile--lower .tile-badge {
  background: rgba(56, 189, 248, 0.18);
  color: var(--higher);
}

.guess-tile--correct {
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.22);
}

.guess-tile--higher {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.22);
}

.guess-tile--lower {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.22);
}

.guess-tile--wrong {
  background: rgba(234, 179, 8, 0.12);
  border-color: rgba(234, 179, 8, 0.22);
}

.guess-tile--wrong .tile-badge {
  background: rgba(234, 179, 8, 0.22);
  color: #debe1c;
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive adjustments: reduce the extra width on smaller viewports to avoid overflow */
@media (max-width: 900px) {
  :root {
    --search-offset: 32px;
  }
}

@media (max-width: 640px) {
  :root {
    --search-offset: 12px;
  }
}

/* for mobile view */

@media (max-width: 640px) {
  .guess-card-grid {
    gap: 0.5rem;
    justify-content: center;
  }

  .guess-tile {
    min-width: 4.25rem;
  }
}

@media (max-width: 768px) {
  .app {
    padding: 1rem 0.9rem 1rem;
  }

  .header {
    margin-bottom: 1rem;
  }

  .search-section {
    gap: 0.35rem;
    margin-bottom: 0.1rem;
  }

  .guess-counter {
    font-size: 0.95rem;
  }

  .search-submit-btn {
    width: 44px;
    height: 44px;
  }

  .search-submit-icon {
    width: 22px;
    height: 22px;
  }

  .board-section {
    margin-top: 0.5rem;
  }

  .guess-cards {
    gap: 0.75rem;
  }

  .empty-hint {
    margin-bottom: 0.5rem;
  }
}

.cell-car-name {
  position: sticky;
  left: 0;
  z-index: 1;
  text-align: left !important;
  font-weight: 600;
  background: var(--surface);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.guess-table thead .cell-car-name,
.guess-table th:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface-elevated);
  text-align: left;
}

.cell-feedback {
  font-weight: 600;
}

.cell-correct {
  background: var(--correct-bg);
  color: var(--correct);
}

.cell-wrong {
  background: var(--wrong-bg);
  color: var(--wrong);
}

.cell-partial {
  background: var(--partial-bg);
  color: var(--partial);
}

.cell-higher {
  background: var(--higher-bg);
  color: var(--higher);
}

.cell-lower {
  background: var(--lower-bg);
  color: var(--lower);
}

/* Game over — sits below the fixed navbar so nav stays usable */

.game-over {
  position: fixed;
  top: var(--navbar-height, 64px);
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1.5rem;
  padding-top: 3rem;
  text-align: center;
  background: rgba(15, 20, 25, 0.422);
  backdrop-filter: blur(10px);
  z-index: 25;
}

.game-over::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(15, 20, 25, 0.72);
}

.game-over-won::before {
  background:
    radial-gradient(ellipse at 50% 18%, rgba(34, 197, 94, 0.28), transparent 55%),
    radial-gradient(ellipse at 50% 80%, rgba(34, 197, 94, 0.1), transparent 50%),
    rgba(15, 20, 25, 0.7);
}

.game-over-wrapped {
  position: relative;
  width: min(520px, 100%);
  max-height: calc(100vh - var(--navbar-height, 64px) - 3rem);
  overflow-y: auto;
  padding: 2.5rem 2rem 1.75rem;
  border-radius: calc(var(--radius) * 1.25);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
  z-index: 1;
}

.game-over-won .game-over-wrapped {
  border-color: rgba(34, 197, 94, 0.45);
  box-shadow:
    0 0 0 1px rgba(250, 204, 21, 0.22),
    0 0 40px rgba(34, 197, 94, 0.22),
    0 24px 64px rgba(0, 0, 0, 0.35);
}

.game-over-enter .game-over-wrapped {
  animation: gameOverScaleIn 0.28s ease both;
}

@keyframes gameOverScaleIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.game-over-close {
  position: absolute;
  top: 1rem;
  left: 1rem;
  width: 2.4rem;
  height: 2.4rem;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}

.game-over-close:hover {
  background: rgba(255, 255, 255, 0.14);
  transform: scale(1.05);
}

.game-over-wrapped > .game-over-title,
.game-over-wrapped > .game-over-tone,
.game-over-wrapped > .game-over-message,
.game-over-wrapped > .game-over-streak,
.game-over-wrapped > .secret-reveal,
.game-over-wrapped > .game-over-photo,
.game-over-wrapped > .game-over-actions {
  position: relative;
}

.game-over-won {
  border-color: var(--correct);
}

.game-over-lost {
  border-color: var(--error);
}

.game-over-title {
  margin: 0 0 0.35rem;
  font-size: 20px;
  font-weight: 700;
}

.game-over-won .game-over-title {
  color: var(--correct);
}

.game-over-lost .game-over-title {
  color: var(--error);
}

.game-over-tone {
  margin: 0 0 0.55rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: #facc15;
}

.game-over-message {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.game-over-won .game-over-message {
  color: var(--text);
}

.game-over-lost .game-over-message {
  color: var(--error);
}

.game-over-streak {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #86efac;
}

.secret-reveal {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.secret-reveal-make {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.15rem;
}

.secret-reveal-logo-wrap {
  position: relative;
  display: grid;
  place-items: center;
}

.secret-reveal-logo-wrap--win .secret-reveal-logo {
  animation: logoPop 0.45s ease both;
}

@keyframes logoPop {
  0% {
    transform: scale(0.7);
    opacity: 0.4;
  }
  60% {
    transform: scale(1.12);
    opacity: 1;
  }
  100% {
    transform: scale(1);
  }
}

.secret-reveal-logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
  display: block;
  padding: 6px;
  border-radius: 50%;
  background: #ffffff;
  border: 1px solid rgba(59, 130, 246, 0.22);
}

.secret-reveal-logo[hidden] {
  display: none;
}

.secret-reveal strong {
  color: var(--text);
  font-size: 1.25rem;
}

.secret-reveal-specs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.35rem 0.4rem;
}

.secret-spec {
  opacity: 0;
  animation: specFadeIn 0.35s ease forwards;
  animation-delay: calc(0.12s + var(--spec-i, 0) * 0.12s);
}

.secret-spec-dot {
  opacity: 0.55;
}

@keyframes specFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.win-particles {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 0;
}

.win-particle {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: hsl(calc(95 + var(--i) * 12), 85%, 60%);
  box-shadow: 0 0 8px rgba(250, 204, 21, 0.55);
  animation: particleBurst 0.7s ease-out forwards;
  transform: rotate(var(--angle)) translateY(0) scale(0.4);
}

@keyframes particleBurst {
  0% {
    opacity: 1;
    transform: rotate(var(--angle)) translateY(0) scale(0.35);
  }
  100% {
    opacity: 0;
    transform: rotate(var(--angle)) translateY(-72px) scale(1);
  }
}

.game-over-photo {
  margin: 0 auto 1.25rem;
  width: 100%;
  min-height: 120px;
  border-radius: 0.75rem;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.18);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1rem;
}

.game-over-photo-img {
  width: 100%;
  max-height: 160px;
  object-fit: contain;
  display: block;
}

.game-over-photo-img[hidden] {
  display: none;
}

.game-over-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.65rem;
  margin-bottom: 0.35rem;
}

.share-result-btn {
  min-width: 120px;
  padding: 0.75rem 1.35rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: transparent;
  border: 1.5px solid rgba(34, 197, 94, 0.55);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.share-result-btn:hover {
  background: rgba(34, 197, 94, 0.14);
  border-color: rgba(34, 197, 94, 0.8);
}

.share-result-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.share-status {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.play-again-btn {
  min-width: 140px;
}

@media (prefers-reduced-motion: reduce) {
  .guess-card--win .guess-tile,
  .game-over-enter .game-over-wrapped,
  .secret-reveal-logo-wrap--win .secret-reveal-logo,
  .secret-spec,
  .win-particle {
    animation: none !important;
  }

  .secret-spec {
    opacity: 1;
  }
}

@media (max-width: 640px) {
  .game-over {
    padding: 1rem;
    align-items: flex-start;
    padding-top: 1.25rem;
  }

  .game-over-wrapped {
    padding: 2.25rem 1.25rem 1.5rem;
  }

  .game-over-photo {
    min-height: 100px;
  }

  .game-over-photo-img {
    max-height: 130px;
  }
}

/* Desktop */
@media (min-width: 769px) {
  .app {
    position: relative;
  }

  .header {
    margin-bottom: 2rem;
  }
}
