/* ═══════════════════════════════════════════════════════
   Migros Wrapped — styles.css
   Mobile-first dark theme with purple-ish accent colours.
   Requirement 8.5, 8.6, 9.5, 10.3
   ═══════════════════════════════════════════════════════ */

/* ── Design tokens ────────────────────────────────────── */
:root {
  --color-bg:           #0f0f1a;
  --color-surface:      #1a1a2e;
  --color-accent:       #7b2ff7;
  --color-accent-light: #a855f7;
  --color-brand-orange: #ff6600;
  --color-text:         #f0f0f0;
  --color-text-muted:   #9999bb;
  --color-error:        #ff4466;

  --font-stack: system-ui, -apple-system, sans-serif;
  --slide-transition: 300ms ease;
}

/* ── Reset / base ─────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  min-width: 320px;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-stack);
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Upload screen ────────────────────────────────────── */
#upload-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  justify-content: safe center;
  gap: 2rem;
  height: 100dvh;
  overflow-y: auto;
  padding: 2rem 1rem;
  text-align: center;
}

#upload-screen > * {
  flex-shrink: 0;
}

/* Wordmark */
.wordmark {
  font-size: clamp(2.5rem, 10vw, 5rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1;
}

/* Upside-down "M" renders as the "W" of "Wrapped" */
.wordmark-w {
  display: inline-block;
  transform: rotate(180deg);
  color: var(--color-brand-orange);
}

.wordmark-rapped {
  color: #ffffff;
}

/* How-to tutorial */
.howto {
  width: 100%;
  max-width: 420px;
  padding: 1rem 1.25rem;
  border-radius: 1rem;
  background: var(--color-surface);
  text-align: left;
}

.howto__title {
  margin-bottom: 0.5rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
}

.howto__steps {
  padding-left: 1.25rem;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--color-text-muted);
}

.howto__steps a {
  color: #ffffff;
  text-decoration: underline;
}

/* Drop zone */
.drop-zone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 420px;
  padding: 2.5rem 1.5rem;
  border: 2px dashed var(--color-accent);
  border-radius: 1rem;
  background: var(--color-surface);
  cursor: pointer;
  transition: border-color 200ms, background 200ms;
}

.drop-zone:hover,
.drop-zone:focus-within,
.drop-zone--active {
  border-color: var(--color-accent-light);
  background: #21213a;
}

.drop-zone__hint {
  font-size: 1rem;
  color: var(--color-text-muted);
}

.drop-zone__label {
  color: var(--color-accent-light);
  text-decoration: underline;
  cursor: pointer;
}

/* Hide the native file input but keep it accessible */
.drop-zone__input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* Inline error */
.upload-error {
  color: var(--color-error);
  font-size: 0.9rem;
  max-width: 420px;
}

/* Privacy notice */
.privacy-notice {
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--color-text-muted);
  max-width: 340px;
}

/* ── Loading indicator ────────────────────────────────── */
.loading-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  min-height: 100dvh;
}

.loading-indicator__spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--color-surface);
  border-top-color: var(--color-accent-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-indicator__text {
  color: var(--color-text-muted);
  font-size: 1rem;
}

/* ── Story deck ───────────────────────────────────────── */
.story-deck {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
}

/* Progress bar */
.progress-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.15);
  z-index: 10;
}

.progress-bar__fill {
  height: 100%;
  background: var(--color-accent-light);
  transition: width var(--slide-transition);
}

/* Tap zones */
.tap-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  z-index: 5;
  cursor: pointer;
}

.tap-zone--prev { left: 0; }
.tap-zone--next { right: 0; }

/* Slides container */
.slides-container {
  width: 100%;
  height: 100%;
}

/* Individual slide (renderer.js will add these) */
.slide {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 3rem 1.5rem 2rem;
  background: var(--color-bg);
  text-align: center;
  overflow-x: hidden;
  overflow-y: auto;
}

/* Keep content at natural size so tall slides scroll instead of squashing. */
.slide > * {
  flex-shrink: 0;
}

.slide--active {
  display: flex;
}

/* Opening slide */
.slide--opening {
  gap: 1.25rem;
  background:
    radial-gradient(circle at 50% 30%, rgba(123, 47, 247, 0.35), transparent 60%),
    var(--color-bg);
}

.slide--opening .wordmark {
  font-size: clamp(2.5rem, 16vw, 6rem);
  max-width: 100%;
}

.slide-opening__year {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-accent-light);
}

.slide-opening__file {
  max-width: 100%;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  overflow-wrap: anywhere;
}

/* Stat slides (total spending, shopping trips) */
.slide--stats {
  gap: 1.75rem;
  background:
    radial-gradient(circle at 50% 80%, rgba(123, 47, 247, 0.25), transparent 60%),
    var(--color-bg);
}

.slide__title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.stat {
  max-width: 100%;
}

.stat__label {
  font-size: 0.95rem;
  color: var(--color-text-muted);
}

.stat__value {
  font-size: clamp(2rem, 12vw, 3.5rem);
  font-weight: 900;
  line-height: 1.1;
  color: var(--color-accent-light);
  overflow-wrap: anywhere;
}

.stat__value--total,
.stat__value--trips {
  font-size: clamp(2.25rem, 14vw, 4.5rem);
  color: var(--color-text);
}

/* Chart slides (favourite day / time) */
.slide--chart {
  gap: 1.25rem;
  background:
    radial-gradient(circle at 50% 80%, rgba(123, 47, 247, 0.25), transparent 60%),
    var(--color-bg);
}

.chart-canvas {
  display: block;
  /* Width is capped by container, 480px, and available height (4:3 ratio). */
  width: min(100%, 480px, calc(45dvh * 4 / 3));
  aspect-ratio: 320 / 240;
  height: auto;
}

.chart-axis-note {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.chart-summary {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-brand-orange);
  overflow-wrap: anywhere;
}

/* Top products slide */
.slide--products {
  gap: 1.25rem;
  background:
    radial-gradient(circle at 50% 80%, rgba(123, 47, 247, 0.25), transparent 60%),
    var(--color-bg);
}

.products-list {
  list-style: none;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.product {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.75rem;
  background: var(--color-surface);
  text-align: left;
}

.product__media {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  font-size: 1.5rem;
}

.product__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product__name {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product__freq {
  flex: 0 0 auto;
  font-weight: 800;
  color: var(--color-brand-orange);
}

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

/* Seasonal slides (reuse top products layout) */
.seasonal-item__detail {
  flex: 0 0 auto;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.seasonal-item--strong {
  border: 2px solid var(--color-brand-orange);
}

/* Favourite stores slide */
.slide--branches {
  justify-content: flex-start;
  gap: 1rem;
  overflow-y: auto;
  background:
    radial-gradient(circle at 50% 80%, rgba(123, 47, 247, 0.25), transparent 60%),
    var(--color-bg);
}

.home-store {
  width: 100%;
  max-width: 420px;
  padding: 1rem;
  border-radius: 1rem;
  background: var(--color-surface);
  border: 2px solid var(--color-brand-orange);
}

.home-store__label {
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.home-store__name {
  font-size: clamp(1.5rem, 8vw, 2.25rem);
  font-weight: 900;
  line-height: 1.15;
  color: var(--color-brand-orange);
  overflow-wrap: anywhere;
}

/* ── Language switcher ────────────────────────────────── */
.lang-switcher {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem;
}

.lang-switcher__option {
  min-height: 32px;
  padding: 0.25rem 0.625rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: transparent;
  color: var(--color-text-muted);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
}

.lang-switcher__option:focus-visible {
  outline: 2px solid var(--color-accent-light);
  outline-offset: 2px;
}

.lang-switcher__option[aria-checked="true"] {
  border-color: var(--color-accent-light);
  background: var(--color-accent);
  color: var(--color-text);
}

/* In the deck the switcher sits above the tap zones (z-index 5) so that
   pointer events on it never reach slide navigation. */
.lang-switcher--deck {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 11;
}

/* Scrollable lists sit above the tap zones (z-index 5) so touch scrolling
   works; taps directly on the list do not navigate (swipes still do). */
.products-list,
.branches-list,
.price-changes-list {
  position: relative;
  z-index: 6;
}

.branches-list {
  list-style: none;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.branch {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.15rem 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.75rem;
  background: var(--color-surface);
  text-align: left;
}

.branch__name {
  grid-column: 1 / -1;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.branch__trips,
.branch__umsatz {
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.branch__pct,
.branch__umsatz {
  text-align: right;
}

.branch__pct {
  font-weight: 800;
  color: var(--color-accent-light);
}

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

/* Price changes slide */
.slide--price-changes {
  justify-content: flex-start;
  gap: 1rem;
  overflow-y: auto;
  background:
    radial-gradient(circle at 50% 80%, rgba(123, 47, 247, 0.25), transparent 60%),
    var(--color-bg);
}

.price-changes-list {
  list-style: none;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.price-change {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.15rem 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.75rem;
  background: var(--color-surface);
  text-align: left;
}

.price-change__name {
  grid-column: 1 / -1;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.price-change__range {
  min-width: 0;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.price-change__swing {
  text-align: right;
  font-weight: 800;
  color: var(--color-accent-light);
}

/* Price rose = red, price fell = green; the +/- sign carries the meaning too. */
.price-change__swing--up { color: var(--color-error); }
.price-change__swing--down { color: #44dd88; }

.price-change__trend {
  grid-column: 1 / -1;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  overflow-wrap: anywhere;
}

.price-change__chart-wrap {
  grid-column: 1 / -1;
  margin-top: 0.25rem;
}

.price-change__chart {
  display: block;
  width: 100%;
  height: 48px;
}

.price-change__dates {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--color-text-muted);
}

.price-changes-empty {
  color: var(--color-text-muted);
}

/* End screen */
.slide--end {
  gap: 1.25rem;
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 102, 0, 0.25), transparent 60%),
    radial-gradient(circle at 50% 80%, rgba(123, 47, 247, 0.3), transparent 60%),
    var(--color-bg);
}

.end-message {
  max-width: 320px;
  color: var(--color-text-muted);
}

/* Must sit above the tap zones (z-index 5) so the buttons are clickable. */
.end-actions {
  position: relative;
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 320px;
}

.end-button {
  width: 100%;
  min-height: 3.25rem;
  padding: 0.75rem 1.25rem;
  border: 2px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
  cursor: pointer;
}

.end-button--primary {
  background: var(--color-brand-orange);
}

.end-button--secondary {
  background: var(--color-accent);
  border-color: var(--color-accent-light);
}

.end-button:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: 2px;
}

/* Centre content when it fits; align to top (scrollable) when it doesn't. */
.slide--products,
.slide--end {
  justify-content: safe center;
}

/* Short viewports (e.g. 320x568): tighter spacing so slides fit. */
@media (max-height: 600px) {
  #upload-screen {
    gap: 1.25rem;
    padding: 1rem;
  }

  .drop-zone {
    padding: 1.5rem 1rem;
  }

  .slide {
    padding: 2rem 1rem 1rem;
  }

  .slide--stats {
    gap: 1rem;
  }

  .slide--chart,
  .slide--products,
  .slide--end {
    gap: 0.75rem;
  }

  .product {
    padding: 0.35rem 0.6rem;
  }

  .stat__value--total,
  .stat__value--trips {
    font-size: clamp(2rem, 12vw, 3.5rem);
  }
}

/* Utility: visually hidden but accessible */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ── Hidden helper ────────────────────────────────────── */
[hidden] { display: none !important; }
