/**
 * File:     main.css
 * Project:  MindPieces
 * Author:   Thomas Dobler - SYNTHETIXMIND
 * Version:  1.0.1
 * Created:  2026-10-24
 * Updated:  2026-10-24
 */

/* ----- Design tokens (DESIGN.md section 3, 4 and 9.3) ----------------------- */

:root {
  /* Brand palette (SM Color Theme) */
  --brand-navy: #1C2C37;
  --brand-navy-raised: #26394A;
  --brand-orange: #FA5800;
  --brand-soft-white: #F2F4F6;
  --brand-beige: #EADDD3;
  --brand-mahogany: #6B2D19;

  /* Semantic tokens, light theme */
  --surface: #F2F4F6;
  --surface-raised: #EADDD3;
  --ink: #1C2C37;
  --ink-muted: #58646C;
  --accent: #FA5800;
  --accent-strong: #C04300;
  --accent-hover: #E04F00;
  --on-accent: #FFFFFF;
  --border: #D0D4D8;
  --focus-ring: #1C2C37;

  --font-display: 'Sora', 'Segoe UI', system-ui, sans-serif;
  --font-sans: 'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Mono', monospace;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 999px;

  --hud-height: 64px;
  --tray-px: 0px;
  --fade: 0.24s;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: #1C2C37;
    --surface-raised: #26394A;
    --ink: #F2F4F6;
    --ink-muted: #B5BDC4;
    --border: #3A4C5A;
    --focus-ring: #F2F4F6;
  }
}

/* Screens that sit directly on the 3D scene always use the dark ground. */
.screen--home,
#screen-loading,
.best__header {
  --surface: #1C2C37;
  --surface-raised: #26394A;
  --ink: #F2F4F6;
  --ink-muted: #B5BDC4;
  --border: #3A4C5A;
  --focus-ring: #F2F4F6;
}

/* ----- Base ------------------------------------------------------------------- */

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

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--brand-navy);
  color: var(--brand-soft-white);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.15;
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.noscript {
  padding: var(--space-5);
}

/* ----- App frame and canvas --------------------------------------------------- */

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--brand-navy);
}

.app-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* The canvas takes input only on the game boards; only there is page scrolling blocked. */
.app[data-state='puzzle'] .app-canvas,
.app[data-state='memory'] .app-canvas {
  pointer-events: auto;
  touch-action: none;
}

.layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: max(var(--space-4), env(safe-area-inset-top)) max(var(--space-4), env(safe-area-inset-right))
    max(var(--space-4), env(safe-area-inset-bottom)) max(var(--space-4), env(safe-area-inset-left));
  pointer-events: auto;
  animation: fade-in var(--fade) ease-out;
}

.screen--centre {
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
}

.screen--scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.screen--scroll.screen--centre {
  justify-content: flex-start;
}

.screen--scroll.screen--centre > .panel {
  margin-block: auto;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

/* ----- Loading ---------------------------------------------------------------- */

.loading__logo {
  width: 96px;
  height: 96px;
}

.progress {
  width: min(240px, 70vw);
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--brand-navy-raised);
  overflow: hidden;
}

.progress__bar {
  width: 0;
  height: 100%;
  background: var(--brand-soft-white);
  transition: width 0.2s linear;
}

.loading__text {
  margin: 0;
  color: var(--ink-muted);
  font-size: 15px;
}

/* ----- Home ------------------------------------------------------------------- */

.screen--home {
  color: var(--ink);
}

/* Navy vignette behind the copy keeps the title readable over the floating cards. */
.screen--home::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(ellipse 70% 55% at 50% 52%, rgb(28 44 55 / 0.88) 0%, rgb(28 44 55 / 0.55) 55%, rgb(28 44 55 / 0) 100%);
  background: radial-gradient(
    ellipse 70% 55% at 50% 52%,
    color-mix(in srgb, var(--brand-navy) 88%, transparent) 0%,
    color-mix(in srgb, var(--brand-navy) 55%, transparent) 55%,
    transparent 100%
  );
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand__mark {
  width: 40px;
  height: 40px;
  /* Clear space of a quarter of the mark's diameter (concept 9.3). */
  margin: 10px;
}

.brand__name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.01em;
}

.home__content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  text-align: center;
  padding-bottom: var(--space-7);
}

.home__title {
  font-size: clamp(40px, 11vw, 72px);
  letter-spacing: -0.01em;
}

.home__lead {
  max-width: 28rem;
  margin: 0 0 var(--space-3);
  color: var(--ink-muted);
  font-size: 17px;
}

/* ----- Buttons ---------------------------------------------------------------- */

.actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-3);
  width: min(100%, 320px);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 48px;
  padding: var(--space-3) var(--space-5);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 17px;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.button:active {
  transform: translateY(1px);
}

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

/* One orange focal point per view; labels on orange are 19 px bold (concept 9.1). */
.button--primary {
  background: var(--accent);
  color: var(--on-accent);
  font-size: 19px;
  font-weight: 700;
}

.button--primary:hover {
  background: var(--accent-hover);
}

.button--outline {
  border-color: var(--ink);
  background: transparent;
  color: var(--ink);
}

.button--outline:hover {
  background: color-mix(in srgb, var(--ink) 10%, transparent);
}

.button--ghost {
  background: transparent;
  color: var(--ink-muted);
}

.button--ghost:hover {
  color: var(--ink);
}

.button--chip {
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  background: var(--accent-strong);
  color: var(--on-accent);
  font-size: 15px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.button--chip[aria-pressed='true'] {
  background: var(--brand-mahogany);
}

.button__cost {
  font-family: var(--font-mono);
  font-weight: 500;
}

.link-button {
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  border: 0;
  background: none;
  color: var(--ink);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

/* ----- Panels ----------------------------------------------------------------- */

.panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  width: min(100%, 30rem);
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  text-align: center;
}

.panel__title {
  font-size: clamp(26px, 6vw, 34px);
  color: var(--ink);
}

.panel__lead {
  margin: 0;
  color: var(--ink-muted);
}

/* ----- Level select ----------------------------------------------------------- */

.chips {
  display: grid;
  gap: var(--space-3);
  width: 100%;
}

.level-chip {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--space-1) var(--space-3);
  min-height: 72px;
  padding: var(--space-3) var(--space-5);
  border: 2px solid transparent;
  border-radius: var(--radius-full);
  background: var(--surface-raised);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.level-chip:hover:not(:disabled) {
  border-color: var(--ink);
}

.level-chip:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.level-chip__name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
}

.level-chip__count {
  color: var(--ink-muted);
  font-size: 15px;
}

.level-chip__base {
  grid-row: 1 / span 2;
  grid-column: 2;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 15px;
  color: var(--ink);
  white-space: nowrap;
}

.level-chip__note {
  grid-column: 1 / -1;
  color: var(--ink-muted);
  font-size: 14px;
}

/* ----- HUD -------------------------------------------------------------------- */

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hud__bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--hud-height);
  padding: var(--space-2) max(var(--space-3), env(safe-area-inset-right)) var(--space-2) max(var(--space-3), env(safe-area-inset-left));
  background: var(--surface);
  color: var(--ink);
  border-bottom: 1px solid var(--border);
  pointer-events: auto;
}

.hud__stat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.15;
}

.hud__label {
  color: var(--ink-muted);
  font-size: 12px;
}

.hud__value {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

#preview-button {
  margin-left: auto;
}

.hud__zoom {
  position: absolute;
  right: max(var(--space-3), env(safe-area-inset-right));
  bottom: calc(var(--tray-px) + var(--space-3));
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: auto;
}

.minimap {
  position: absolute;
  top: calc(var(--hud-height) + var(--space-3));
  right: max(var(--space-3), env(safe-area-inset-right));
  width: 120px;
  border: 1px solid var(--brand-soft-white);
  border-radius: 6px;
  pointer-events: auto;
  cursor: pointer;
}

.hud__notice {
  position: absolute;
  top: calc(var(--hud-height) + var(--space-4));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  background: rgb(28 44 55 / 0.85);
  background: color-mix(in srgb, var(--brand-navy) 85%, transparent);
  color: var(--brand-soft-white);
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
}

.hud__notice:empty {
  display: none;
}

@media (max-width: 420px) {
  .hud__bar {
    gap: var(--space-2);
  }

  .hud__value {
    font-size: 15px;
  }

  .button--chip {
    padding-inline: var(--space-3);
  }

  .panel {
    padding: var(--space-5) var(--space-4);
  }

  .breakdown {
    gap: var(--space-1) var(--space-3);
    padding: var(--space-3);
    font-size: 13px;
  }
}

/* ----- Result ----------------------------------------------------------------- */

.result__subtitle {
  margin: calc(var(--space-2) * -1) 0 0;
  color: var(--ink-muted);
}

.result__score {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(44px, 12vw, 64px);
  line-height: 1;
  color: var(--ink);
}

.result__unit {
  font-size: 18px;
  color: var(--ink-muted);
}

.breakdown {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-1) var(--space-5);
  width: 100%;
  margin: 0;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 15px;
  text-align: left;
}

.breakdown dt {
  color: var(--ink-muted);
}

.breakdown dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.breakdown .breakdown__total {
  padding-top: var(--space-2);
  border-top: 1px solid var(--border);
  color: var(--ink);
  font-weight: 500;
}

.result__rank {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
}

.result__rank:empty {
  display: none;
}

.name-form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-2);
  width: 100%;
  text-align: left;
}

.field__label {
  font-weight: 600;
}

.field__input {
  min-height: 48px;
  padding: var(--space-2) var(--space-3);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 18px;
}

.field__input:focus-visible {
  border-color: var(--ink);
}

.field__input[aria-invalid='true'] {
  border-color: var(--brand-mahogany);
}

.field__hint {
  margin: 0;
  color: var(--ink-muted);
  font-size: 14px;
}

.field__error {
  margin: 0;
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
}

.field__error:empty {
  display: none;
}

/* ----- Best lists ------------------------------------------------------------- */

.screen--best {
  padding-top: 0;
}

.best__header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: center;
  padding-top: max(var(--space-4), env(safe-area-inset-top));
}

.tabs {
  display: inline-flex;
  padding: var(--space-1);
  border-radius: var(--radius-full);
  background: var(--surface-raised);
}

.tabs__tab {
  min-width: 110px;
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--ink-muted);
  font-weight: 600;
  cursor: pointer;
}

.tabs__tab[aria-selected='true'] {
  background: var(--brand-soft-white);
  color: var(--brand-navy);
}

/* Free space in which the 3D podium is visible (MENU.podiumViewShare of the viewport). */
.best__stage {
  flex: 0 0 auto;
  height: calc(55vh - 76px);
  height: calc(55dvh - 76px);
  pointer-events: none;
}

.panel--list {
  align-self: center;
  align-items: stretch;
  margin-bottom: var(--space-5);
}

.best__list {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.best__row {
  display: grid;
  grid-template-columns: 32px 40px 1fr auto;
  align-items: center;
  gap: var(--space-3);
  min-height: 52px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  text-align: left;
}

.best__row--new {
  outline: 2px solid var(--ink);
  outline-offset: -2px;
}

.best__rank {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--brand-navy);
  color: var(--brand-soft-white);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 14px;
}

.best__thumb {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--brand-navy);
}

.best__thumb--label {
  display: grid;
  place-items: center;
  color: var(--brand-soft-white);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.1;
  text-align: center;
}

.best__who {
  min-width: 0;
}

.best__name {
  display: block;
  overflow: hidden;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.best__detail {
  display: block;
  overflow: hidden;
  color: var(--ink-muted);
  font-size: 13px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.best__points {
  font-family: var(--font-mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.best__note {
  margin: 0;
  color: var(--ink-muted);
  font-size: 13px;
}

.best__note:empty {
  display: none;
}

/* ----- Dialog and card zoom --------------------------------------------------- */

.dialog {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: rgb(28 44 55 / 0.6);
  background: color-mix(in srgb, var(--brand-navy) 60%, transparent);
  pointer-events: auto;
  animation: fade-in var(--fade) ease-out;
}

.card-zoom {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  animation: zoom-in 0.25s ease-out;
}

.card-zoom__image {
  width: min(70vmin, 360px);
  aspect-ratio: 1;
  object-fit: cover;
  border: 4px solid var(--brand-soft-white);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.35);
}

@keyframes zoom-in {
  from {
    opacity: 0;
    transform: scale(0.85);
  }
}

/* ----- Larger screens --------------------------------------------------------- */

@media (min-width: 768px) {
  .actions {
    flex-direction: row;
    justify-content: center;
    width: auto;
  }

  .panel {
    padding: var(--space-6);
  }

  .panel--dialog .actions,
  .panel--list .actions {
    width: 100%;
  }
}

