/* ==========================================================================
   KARMOUCH DESIGN SYSTEM — ASTRO WORDMAZE RUNNER
   Source of Truth: karmouch-design-system.md
   Play screen for WordMaze (/wordmaze/play.html). The public page is src/pages/wordmaze/.
   ========================================================================== */

:root {
  /* -- Colour Tokens (Section 2) ------------------------------------------ */
  --color-primary: #C4A8E0;       /* Lavender — promo bands, highlight underline, accents */
  --color-secondary: #5B3E86;     /* Aubergine — labels, focus rings, hover states, primary brand */
  --color-accent: #E0A03C;        /* Marigold — commerce only: buy buttons, price flags, errors */
  --color-support: #2F6B54;       /* Forest — category labels only, used sparingly */
  --color-bg: #FFFFFF;            /* Page and card background */
  --color-surface: #F7F3FB;       /* Tinted panels, tag pills, question wells */
  --color-text: #1A1A1A;          /* All body and heading text, primary button fill */
  --color-text-muted: #5E5A63;    /* Descriptions, metadata, secondary text */
  --color-line: #E6E2EA;          /* Neutral hairlines and card borders */
  --color-line-violet: #D9C6EC;   /* Violet hairlines — offset panels, tag borders, dotted rules */
  --color-rail: #F0ECF4;          /* The faint six-column grid rails behind the hero */

  /* Arcade / Canvas specific colors */
  --arcade-bg: #070714;
  --arcade-wall: #182436;
  --arcade-gold: #f59e0b;
  --arcade-cyan: #00f5d4;
  --arcade-blue: #38bdf8;
  --arcade-purple: #a855f7;

  /* -- Typography (Section 3) ---------------------------------------------- */
  --font-heading: "Fraunces", Georgia, "Times New Roman", serif;
  --font-body: "Archivo", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "DM Mono", ui-monospace, Menlo, monospace;

  /* Modular scale, ratio 1.2 */
  --fs-100: 0.688rem;   /* 11px — mono labels */
  --fs-200: 0.813rem;   /* 13px — buttons, meta */
  --fs-300: 0.938rem;   /* 15px — card body */
  --fs-350: 1.063rem;   /* 17px — page body */
  --fs-400: 1.25rem;    /* 20px — lede, card titles */
  --fs-500: 1.5rem;     /* 24px */
  --fs-600: 1.875rem;   /* 30px */
  --fs-700: clamp(2rem, 3.4vw, 2.5rem);
  --fs-800: clamp(2.25rem, 5vw, 3.5rem); /* h1 */

  /* -- Spacing ------------------------------------------------------------- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --space-6: 44px;
  --space-7: 52px;
  --space-8: 64px;

  --container-max: 1240px;

  /* -- Radius Grammar (Section 5: Steps DOWN as surfaces nest) ------------ */
  --radius-shell: 24px;    /* promo bands, popups, outermost containers */
  --radius-surface: 18px;  /* cards, tiles, panels */
  --radius-inset: 10px;    /* images inside cards, previews */
  --radius-control: 14px;  /* inputs, selects */
  --radius-tight: 6px;     /* tag pills, small badges */
  --radius-pill: 9999px;   /* buttons, chips, avatars */

  /* -- Motion (Section 6) -------------------------------------------------- */
  --ease-spring: cubic-bezier(0.25, 1, 0.5, 1);
  --duration-control: 230ms;
  --duration-card: 300ms;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Header on top, game fills the rest (the header is hidden inside the class stream) */
body {
  display: flex;
  flex-direction: column;
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  color: var(--color-text);
  line-height: 1.1;
}

h1 {
  font-weight: 900;
  letter-spacing: -0.02em;
}

h2, h3 {
  font-weight: 700;
  letter-spacing: -0.012em;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
  background: none;
}

input, textarea, select {
  font-family: var(--font-body);
  user-select: text !important;
  -webkit-user-select: text !important;
}

/* Karmouch Lucide Icon standard */
.k-ico {
  vertical-align: -0.125em;
  flex: none;
  stroke-width: 1.75;
}

/* Eyebrow / Mono label */
.k-eyebrow {
  font-family: var(--font-mono);
  font-size: var(--fs-100);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--color-support);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

/* Focus Ring */
:focus-visible {
  outline: 2px solid var(--color-secondary);
  outline-offset: 3px;
}

/* ==========================================================================
   APP HEADER — Light Editorial White Paper with Karmouch Brand Mark
   ========================================================================== */
.app-header {
  position: relative;
  z-index: 100;
  flex: none;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-line);
}

.header-branding {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
}

.header-mark {
  color: var(--color-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-brand-text {
  display: flex;
  flex-direction: column;
}

.header-brand-title {
  font-family: var(--font-heading);
  font-weight: 900;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  color: var(--color-text);
  line-height: 1.1;
}

.header-brand-sub {
  font-family: var(--font-mono);
  font-size: 0.688rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--color-secondary);
  font-weight: 500;
}

/* Header Nav Tabs */
.nav-tabs {
  display: flex;
  background: var(--color-surface);
  padding: 4px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-line);
  gap: 4px;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: var(--fs-200);
  font-weight: 600;
  color: var(--color-text-muted);
  transition: background-color var(--duration-control) var(--ease-spring), border-color var(--duration-control) var(--ease-spring), color var(--duration-control) var(--ease-spring);
}

.nav-tab:hover {
  color: var(--color-text);
  background: rgba(196, 168, 224, 0.15);
}

.nav-tab.active {
  background: var(--color-secondary);
  color: #FFFFFF;
  box-shadow: 0 2px 8px rgba(91, 62, 134, 0.25);
}

/* Header Right Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-tool-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: var(--fs-200);
  font-weight: 600;
  color: var(--color-secondary);
  background: var(--color-surface);
  border: 1px solid var(--color-line-violet);
  border-radius: var(--radius-pill);
  transition: background-color var(--duration-control) var(--ease-spring), border-color var(--duration-control) var(--ease-spring), color var(--duration-control) var(--ease-spring);
}

.btn-tool-link:hover {
  background: var(--color-primary);
  color: var(--color-text);
  transform: translateY(-1px);
}

.btn-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  color: var(--color-text-muted);
  font-size: 1rem;
  transition: background-color var(--duration-control) var(--ease-spring), border-color var(--duration-control) var(--ease-spring), color var(--duration-control) var(--ease-spring);
}

.btn-tool:hover {
  background: var(--color-bg);
  color: var(--color-text);
  border-color: var(--color-line-violet);
  transform: translateY(-1px);
}

.btn-tool.muted {
  opacity: 0.5;
}

/* ==========================================================================
   APP MAIN & VIEW PANELS
   ========================================================================== */
.app-main {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}

.view-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  z-index: 1;
}

.view-panel.active {
  display: flex !important;
  visibility: visible !important;
  pointer-events: auto !important;
  z-index: 10;
}

/* ==========================================================================
   BUTTONS (pause / game over / victory pop-ups)
   ========================================================================== */
.btn-aubergine-karmouch,
.btn-secondary-karmouch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 22px;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: var(--fs-200);
  font-weight: 600;
  transition: transform var(--duration-control) var(--ease-spring), background-color var(--duration-control) var(--ease-spring), border-color var(--duration-control) var(--ease-spring);
}

.btn-aubergine-karmouch {
  background: var(--color-text);
  color: var(--color-bg);
  border: 1px solid var(--color-text);
  box-shadow: 0 0 0 4px rgba(196, 168, 224, 0.45), 0 8px 18px -10px rgba(91, 62, 134, 0.9);
}

.btn-secondary-karmouch {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-line);
}

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

.btn-aubergine-karmouch:active,
.btn-secondary-karmouch:active {
  transform: translateY(1px) scale(0.985);
}

.btn-aubergine-karmouch:focus-visible,
.btn-secondary-karmouch:focus-visible,
.hud-pill--button:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
}

/* ==========================================================================
   GAME SCREEN
   Score bar on top, maze in the middle, question underneath. On touch
   screens a see-through arrow pad sits over the maze's bottom-right corner.
   The maze keeps its own night-sky look; everything around it uses the tokens.
   ========================================================================== */
#game-view {
  width: 100%;
  height: 100%;
  padding: 12px 16px 16px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "hud"
    "canvas"
    "question";
  gap: 12px;
  background:
    linear-gradient(rgba(10, 10, 26, 0.45), rgba(10, 10, 26, 0.45)),
    var(--arcade-bg) url("../assets/cosmic_nebula_bg.jpg") center / cover no-repeat;
  overflow: hidden;
  touch-action: none;
}

#game-view.active {
  display: grid !important;
}

.game-canvas-wrapper {
  grid-area: canvas;
  position: relative;
  min-height: 0;
}

#game-canvas {
  position: absolute;
  inset: 0;
  display: block;
}

/* Score bar */
.game-hud-top {
  grid-area: hud;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  background: rgba(7, 7, 20, 0.8);
  border: 1px solid rgba(196, 168, 224, 0.3);
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: var(--fs-200);
  font-weight: 500;
  color: var(--color-bg);
}

.hud-pill--lives {
  color: var(--color-primary);
}

.hud-heart {
  fill: currentColor;
}

.hud-heart--lost {
  fill: none;
  opacity: 0.45;
}

.hud-pill--button {
  min-height: 44px;
  font-family: var(--font-body);
  font-weight: 600;
  cursor: pointer;
}

.hud-pill--button:hover {
  border-color: var(--color-primary);
}

/* Question, under the maze */
.hud-question-banner {
  grid-area: question;
  align-self: center;
  justify-self: center;
  width: 100%;
  max-width: 820px;
  padding: 12px 20px;
  background: rgba(7, 7, 20, 0.88);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-surface);
  text-align: center;
}

.hud-q-number {
  font-family: var(--font-mono);
  font-size: var(--fs-100);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-primary);
  margin-bottom: 4px;
}

.hud-q-prompt {
  font-family: var(--font-heading);
  font-size: var(--fs-400);
  font-weight: 700;
  line-height: 1.3;
  color: var(--color-bg);
}

/* Touch arrow pad: floats over the maze, see-through so the maze shows below */
.touch-dpad {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  display: none;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  grid-template-areas:
    ".    up    ."
    "left .     right"
    ".    down  .";
  gap: 4px;
}

.touch-dpad.visible {
  display: grid;
}

.dpad-up { grid-area: up; }
.dpad-left { grid-area: left; }
.dpad-right { grid-area: right; }
.dpad-down { grid-area: down; }

.dpad-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: var(--radius-inset);
  color: rgba(255, 255, 255, 0.85);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.dpad-btn.pressed {
  background: rgba(255, 255, 255, 0.3);
  color: var(--color-bg);
}

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

@media (max-width: 640px) {
  #game-view {
    padding: 8px 8px 12px;
    gap: 8px;
  }

  .hud-pill {
    padding: 0 10px;
  }

  .hud-question-banner {
    padding: 10px 12px;
  }

  .hud-q-number {
    display: none;
  }

  .hud-q-prompt {
    font-size: var(--fs-300);
  }

  .app-header .header-brand-text {
    display: none;
  }
}

/* ==========================================================================
   MODALS (Karmouch Shell Grammar & Offset Depth)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 26, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  padding: 20px;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal-card {
  position: relative;
  background: var(--color-bg);
  border: 1px solid var(--color-line-violet);
  border-radius: var(--radius-shell);
  padding: 32px;
  max-width: 520px;
  width: 100%;
  box-shadow: 0 10px 20px -14px rgba(26, 26, 26, 0.45);
  transform: translateY(16px);
  transition: transform 0.3s var(--ease-spring);
}

.modal-overlay.active .modal-card {
  transform: translateY(0);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.modal-title {
  font-family: var(--font-heading);
  font-size: var(--fs-500);
  font-weight: 700;
  letter-spacing: -0.012em;
  color: var(--color-text);
}

.modal-sub {
  font-size: var(--fs-200);
  color: var(--color-text-muted);
  margin-top: 4px;
}

.modal-actions-row {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: var(--space-4);
}

.modal-close-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  border: 1px solid var(--color-line);
}

.modal-close-btn:hover {
  color: var(--color-text);
  background: var(--color-surface);
}

/* Toast Notification */
.toast-msg {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  background: var(--color-text);
  color: #FFFFFF;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 2000;
  display: flex;
  align-items: center;
  gap: 8px;
  transform: translateY(80px);
  opacity: 0;
  transition: transform 0.3s var(--ease-spring), opacity 0.3s var(--ease-spring);
}

.toast-msg.show {
  transform: translateY(0);
  opacity: 1;
}

/* Reduced Motion (Always last, always global) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
