/* ============================================================
   DRIVE DEALS — styles
   Phase 3: visual identity — "Drive Surface" dark tech theme.
   Very dark navy canvas with a faint pixel grid (a nod to the
   retro logo), cyan glow accents, and monospace "data readouts"
   for every file name / number. Cairo stays for Arabic UI text;
   JetBrains Mono carries the data. Design tokens live here so
   later phases can reuse them.
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  color-scheme: dark;

  --bg: #0a1220;        /* very dark navy canvas            */
  --surface: #101d34;  /* card / panel surface               */
  --ink: #e9f2fc;      /* main text (near-white, blue tint)  */
  --muted: #9cb2d4;    /* secondary text                     */
  --primary: #2f7ce8;  /* medium blue — structural accents   */
  --accent: #35dcff;   /* cyan — glow, focus, selection, CTA */
  --line: #1f3560;     /* hairlines / borders                */
  --error: #ff7a68;   /* error text (status only)           */

  --font-body: "Cairo", system-ui, "Segoe UI", Tahoma, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --radius: 8px;
  --container-width: 1100px;
}

/* ---------- Base ---------- */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  background-color: var(--bg);
  /* Ambient "drive surface": soft cyan horizon glow + a faint
     pixel grid (34px cells) that nods to the retro logo. */
  background-image:
    radial-gradient(900px 420px at 50% -160px, rgba(53, 220, 255, 0.09), transparent 70%),
    linear-gradient(to left, rgba(125, 170, 255, 0.045) 1px, transparent 1px),
    linear-gradient(to top, rgba(125, 170, 255, 0.045) 1px, transparent 1px);
  background-size: auto, 34px 34px, 34px 34px;
}

::selection {
  background: var(--accent);
  color: #061426;
}

/* Slim dark scrollbars (WebKit + Firefox). */
* {
  scrollbar-width: thin;
  scrollbar-color: #27436f transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: #27436f;
  border-radius: 8px;
  border: 2px solid var(--bg);
}

::-webkit-scrollbar-thumb:hover {
  background: #35609c;
}

/* ---------- Layout container (RTL-safe centering) ---------- */
.container {
  width: 100%;
  max-width: var(--container-width);
  padding-inline: 20px;
  margin-inline: auto;
}

/* ---------- Header ---------- */
.site-header {
  background: transparent; /* the body's grid + glow continues behind it */
  border-bottom: 1px solid rgba(53, 220, 255, 0.22);
}

.header-inner {
  padding-block: 30px 24px;
}

.brand {
  position: relative;
  display: inline-block;
  margin: 0;
  padding: 12px 26px;
  font-family: var(--font-mono); /* the wordmark reads like a data label */
  font-size: clamp(1.9rem, 5vw, 2.8rem);
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: 0.04em;
  color: var(--ink);
  text-shadow: 0 0 24px rgba(53, 220, 255, 0.35);
}

/* Signature detail (kept from the old identity, recolored):
   viewfinder corner brackets around the wordmark, now glowing cyan. */
.brand::before,
.brand::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border: 3px solid var(--accent);
  filter: drop-shadow(0 0 5px rgba(53, 220, 255, 0.8));
}

.brand::before {
  top: -8px;
  right: -8px; /* inline-start corner in RTL */
  border-left: none;
  border-bottom: none;
}

.brand::after {
  bottom: -8px;
  left: -8px; /* inline-end corner in RTL */
  border-right: none;
  border-top: none;
}

.tagline {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 400;
}

/* Logo + name sit on one row (Phase 2). */
.header-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-logo {
  height: clamp(48px, 7vw, 64px);
  width: auto;
  max-width: 132px;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 10px rgba(53, 220, 255, 0.18));
}

.app {
  /* extra bottom space so the fixed summary bar never covers content */
  padding-block: 32px 130px;
}

/* ---------- Load status (Phase 3) ---------- */
/* Hidden until an error message is set by script.js. */
.status {
  display: none;
}

.status-error {
  display: block;
  margin: 0 0 16px;
  color: var(--error);
  font-weight: 600;
}

/* ---------- Hero: main page content (rebrand plan Phase 5) ---------- */
.hero {
  margin-bottom: 28px;
}

.hero-title {
  margin: 0 0 10px;
  font-size: clamp(1.7rem, 4vw, 2.3rem);
  font-weight: 800;
  line-height: 1.4;
  color: var(--ink);
}

.hero-text {
  margin: 0 0 16px;
  max-width: 640px;
  color: var(--muted);
  font-size: 1.05rem;
}

/* The CTA is an anchor styled as a button — no underline. */
a.btn {
  text-decoration: none;
}

.hero-cta {
  min-width: 200px;
}

/* ---------- "Choose Your Games" section (rebrand plan Phase 5) ---------- */
#game-library {
  scroll-margin-top: 8px;
}

.library-title {
  margin: 0 0 6px;
  font-size: 1.3rem;
  color: #c5e7ff; /* same tone as the panel headings */
}

.library-text {
  margin: 0 0 14px;
  max-width: 640px;
  color: var(--muted);
}

/* ---------- Gallery grid (Phase 4) ---------- */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 16px;
}

@media (max-width: 520px) {
  /* Phase 2: smaller logo on phones so the name stays readable. */
  .brand-logo {
    height: 44px;
    max-width: 104px;
  }

  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
  }

  /* Phase 18 — small phones:
     the summary bar wraps to two rows there, so give it more room and
     let both buttons share a full-width row (easy to tap). */
  .app {
    padding-top: 16px;
    padding-bottom: 150px;
  }

  /* Rebrand plan Phase 5 — compact hero on phones so the first card row
     stays clear of the fixed summary bar (cards must remain tappable). */
  .header-inner {
    padding-block: 14px 10px;
  }

  .tagline {
    margin-top: 12px;
    font-size: 0.9rem;
  }

  .hero {
    margin-bottom: 18px;
  }

  .hero-title {
    margin-bottom: 8px;
    font-size: 1.35rem;
    line-height: 1.35;
  }

  .hero-text {
    margin-bottom: 12px;
    font-size: 0.95rem;
  }

  .library-title {
    margin-bottom: 4px;
    font-size: 1.15rem;
  }

  .library-text {
    margin-bottom: 10px;
    font-size: 0.9rem;
  }

  .summary-actions {
    width: 100%;
  }

  .summary-actions .btn {
    flex: 1;
  }

  /* Forms must not overflow narrow screens. */
  .view-panel {
    padding: 16px;
  }
}

/* ---------- Image card ---------- */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: inherit;
  text-align: start;
  cursor: pointer;
  overflow: hidden; /* clips the image zoom + keeps corners clean */
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background-color 0.18s ease;
}

/* Fixed ratio + cover keeps every card the same size and prevents
   very large images from breaking the layout. */
.card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--bg);
  transition: transform 0.25s ease;
}

/* Hover = the card lifts and its image zooms in slightly. */
.card:hover {
  transform: translateY(-2px);
  border-color: rgba(53, 220, 255, 0.4);
  box-shadow: 0 10px 26px rgba(2, 6, 16, 0.55);
}

.card:hover img {
  transform: scale(1.05);
}

/* Rebrand plan Phase 6: the card body is a column — name, then the size
   readout (the important data), then the selection status. */
.card-info {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 10px 12px;
}

.card-name {
  font-family: var(--font-mono); /* file names read like data */
  font-size: 0.9rem; /* Phase 17: readable on phones */
  font-weight: 600;
  overflow-wrap: anywhere; /* long file names wrap instead of breaking */
}

/* Size row: muted label + prominent value (rebrand plan Phase 6). */
.card-size {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

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

.card-value {
  font-family: var(--font-mono); /* the size reads like data */
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}

/* Visible selection status: "Select Game" -> "Selected"
   (rebrand plan Phase 6). */
.card-status {
  align-self: flex-start;
  margin-top: 2px;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.card.selected .card-status {
  border-color: rgba(53, 220, 255, 0.5);
  background: rgba(53, 220, 255, 0.12);
  color: var(--accent);
}

/* ---------- Selected state (Phase 5) ---------- */
/* Phase 17: selection must be obvious at a glance — cyan border,
   tinted surface and an outer glow ring ("transfer-ready"). */
.card.selected {
  border-color: var(--accent);
  background: #0f2b4d;
  box-shadow: 0 0 0 3px rgba(53, 220, 255, 0.28), 0 0 22px rgba(53, 220, 255, 0.16);
}

.card.selected:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 0 3px rgba(53, 220, 255, 0.4), 0 0 28px rgba(53, 220, 255, 0.28);
}

.check-badge {
  position: absolute;
  top: 8px;
  right: 8px; /* inline-start corner in RTL */
  display: none;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #061426;
  font-size: 1.15rem;
  line-height: 1;
  box-shadow: 0 0 14px rgba(53, 220, 255, 0.5);
}

.card.selected .check-badge {
  display: flex;
}

/* Keyboard focus stays visible */
.card:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Missing image placeholder (Phase 21) ---------- */
/* Same box as .card img so the grid never shifts when a file is missing. */
.image-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #0c1830;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

/* Small corner mark — top-left, so it never covers the check badge (top-right). */
.unavailable-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 10px;
  border-radius: 999px;
  background: #2e4c7c;
  color: #dbe9ff;
  font-size: 0.75rem;
  font-weight: 700;
}

/* ---------- Shared buttons (Phase 6+) ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px; /* Phase 17: comfortable touch target on phones */
  padding: 10px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #12203c;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background-color 0.15s ease, filter 0.15s ease;
}

.btn:hover {
  border-color: rgba(53, 220, 255, 0.4);
}

/* Primary actions glow cyan — the single boldest element on the page. */
.btn-primary {
  border-color: transparent;
  background: var(--accent);
  color: #061426;
  box-shadow: 0 0 18px rgba(53, 220, 255, 0.25);
}

.btn-primary:hover {
  filter: brightness(1.07);
  box-shadow: 0 0 26px rgba(53, 220, 255, 0.4);
}

.btn-secondary {
  border-color: var(--line);
}

.btn-ghost {
  min-width: 48px;
  font-size: 1.1rem;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover {
  color: var(--ink);
  background: #12203c;
  border-color: var(--line);
}

.btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Disabled state while the order is being sent (Phase 15) */
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ---------- Search bar (Phase 7) ---------- */
/* Phase 17: sticky so the search stays reachable while scrolling a
   large gallery. Solid background keeps cards from showing through. */
.search-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  padding-block: 2px 8px;
  background: var(--bg);
}

#search-input {
  flex: 1;
  min-height: 48px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0c1730;
  color: var(--ink);
  font-family: inherit;
  font-size: 1rem;
}

#search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(53, 220, 255, 0.18);
}

.no-results {
  margin: 0 0 16px;
  padding: 24px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed rgba(125, 170, 255, 0.35);
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 600;
}

/* ---------- Load More button (Phase 8) ---------- */
.load-more {
  display: block;
  margin: 24px auto 0;
}

/* ---------- Summary bar (Phase 6) ---------- */
.summary-bar {
  position: fixed;
  bottom: 0;
  inset-inline: 0;
  z-index: 10;
  background: #0c1729;
  border-top: 1px solid rgba(53, 220, 255, 0.28);
  box-shadow: 0 -12px 32px rgba(2, 6, 16, 0.6);
}

.summary-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-block: 10px;
}

.summary-stats {
  margin: 0;
  font-weight: 600;
}

/* The running count + total read like a drive status strip. */
#selected-count,
#total-value {
  font-family: var(--font-mono);
  color: var(--accent);
}

.stats-sep {
  color: var(--muted);
  margin-inline: 8px;
}

.summary-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Warning shown when continuing with zero selections (Phase 9) */
.warning {
  width: 100%;
  margin: 0;
  color: var(--error);
  font-weight: 700;
}

/* ---------- View panels: form + review (Phases 10–11) ---------- */
.view-panel {
  max-width: 640px;
  margin-inline: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}

.view-panel h2 {
  margin-top: 0;
  color: #c5e7ff;
  font-size: 1.5rem;
}

.required-note {
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
}

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

.field input,
.field textarea {
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0c1730;
  color: var(--ink);
  font-family: inherit;
  font-size: 1rem;
}

.field textarea {
  resize: vertical;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(53, 220, 255, 0.18);
}

input[aria-invalid="true"] {
  border-color: var(--error);
}

.field-error {
  min-height: 1.2em;
  margin: 4px 0 0;
  color: var(--error);
  font-size: 0.85rem;
  font-weight: 600;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
}

/* ---------- Review screen (Phase 11) ---------- */
.review-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-block: 8px;
  border-bottom: 1px solid var(--line);
}

.row-label {
  flex-shrink: 0;
  color: var(--muted);
  font-weight: 700;
}

.review-images {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0c1730;
}

.review-images li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}

/* Phase 18: long file names / addresses wrap instead of breaking cards */
.review-images li > span:first-child {
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: 0.88rem;
}

.row-value-text {
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  color: var(--accent);
}

.review-images li:last-child {
  border-bottom: none;
}

.review-total {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
}

/* Final totals read like data, not prose. */
#review-total,
#success-total {
  font-family: var(--font-mono);
  color: var(--accent);
}

/* ---------- Sending status (Phase 15) ---------- */
.send-status {
  margin: 12px 0 0;
}

.send-status:empty {
  display: none; /* no space taken when there is nothing to say */
}

.send-status-error {
  color: var(--error);
  font-weight: 700;
}

/* ---------- Success screen (Phase 16) ---------- */
.success-panel {
  text-align: center;
}

.success-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--accent);
  color: #061426;
  font-size: 2rem;
  line-height: 1;
  box-shadow: 0 0 32px rgba(53, 220, 255, 0.35);
}

.success-text {
  color: var(--muted);
}

.success-total {
  margin-bottom: 8px;
}

.form-actions.center {
  justify-content: center;
}

/* ---------- Utility ---------- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Reduced motion ---------- */
/* The identity uses only small hover transitions; honor users who
   prefer no motion by dropping them entirely. */
@media (prefers-reduced-motion: reduce) {
  .card,
  .card img,
  .btn {
    transition: none;
  }

  .card:hover,
  .card.selected:hover {
    transform: none;
  }

  .card:hover img {
    transform: none;
  }
}
