/* ==========================================================================
   PRISMORA — original visual identity
   Deep indigo base, soft cyan / violet glow, warm amber accents.
   Mobile-first, safe-area aware, no external assets or web fonts.
   ========================================================================== */

:root {
  --ink-900: #070A18;
  --ink-800: #0B0E22;
  --ink-700: #141936;
  --ink-600: #1D2450;
  --ink-500: #2A3270;

  --indigo: #5B6BFF;
  --indigo-light: #8C97FF;
  --cyan: #2FD4E0;
  --cyan-soft: #8AF1F8;
  --violet: #9B5BFF;
  --amber: #FFB347;
  --rose: #FF6FA5;
  --mint: #4ADE80;

  --text: #F2F5FF;
  --text-dim: #A7AEDA;
  --text-faint: #6E77A8;

  --panel: rgba(20, 25, 54, 0.86);
  --panel-solid: #141936;
  --stroke: rgba(140, 151, 255, 0.22);
  --stroke-strong: rgba(140, 151, 255, 0.45);

  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;

  --shadow-deep: 0 24px 60px rgba(0, 0, 0, 0.55);
  --shadow-soft: 0 10px 26px rgba(6, 8, 24, 0.5);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink-900);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

body {
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
}

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 80% at 50% -10%, #1B2154 0%, transparent 60%),
    radial-gradient(90% 60% at 100% 110%, #2A1B52 0%, transparent 55%),
    linear-gradient(180deg, var(--ink-800) 0%, var(--ink-900) 100%);
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 10px) calc(var(--safe-bottom) + 8px) calc(var(--safe-left) + 10px);
}

.screen.is-active { display: flex; }

/* ---------------------------------------------------------------- buttons */

.btn {
  border: 1px solid var(--stroke);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.04);
  padding: 15px 22px;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.2px;
  min-height: 52px;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
  box-shadow: var(--shadow-soft);
}

.btn:active { transform: translateY(1px) scale(0.99); }
.btn:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }

.btn--primary {
  border: none;
  background: linear-gradient(135deg, var(--indigo) 0%, var(--violet) 100%);
  color: #fff;
  box-shadow: 0 12px 30px rgba(91, 107, 255, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.btn--ghost { background: rgba(140, 151, 255, 0.09); }
.btn--quiet {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
  box-shadow: none;
  min-height: 46px;
  padding: 12px 18px;
}

/* ------------------------------------------------------------------ menu */

.screen--menu { align-items: center; justify-content: center; overflow: hidden; }

.menu__bg { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(52px);
  opacity: 0.5;
  animation: drift 14s ease-in-out infinite alternate;
}
.orb--1 { width: 260px; height: 260px; background: #3B49C9; top: -60px; left: -70px; }
.orb--2 { width: 220px; height: 220px; background: #7A3BD9; bottom: 6%; right: -70px; animation-delay: -4s; }
.orb--3 { width: 180px; height: 180px; background: #1E8F9E; bottom: 30%; left: -50px; animation-delay: -8s; }

@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(14px, -22px, 0) scale(1.08); }
}

.menu__content {
  position: relative;
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  text-align: center;
  padding: 10px;
}

.brand { display: flex; flex-direction: column; align-items: center; gap: 6px; }

.brand__mark {
  display: grid;
  grid-template-columns: repeat(2, 26px);
  grid-template-rows: repeat(2, 26px);
  gap: 6px;
  margin-bottom: 14px;
}
.brand__tile {
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), 0 6px 14px rgba(0, 0, 0, 0.35);
  animation: tilePulse 3.2s ease-in-out infinite;
}
.brand__tile.t1 { background: linear-gradient(160deg, var(--indigo-light), var(--indigo)); }
.brand__tile.t2 { background: linear-gradient(160deg, var(--cyan-soft), var(--cyan)); animation-delay: -0.4s; }
.brand__tile.t3 { background: linear-gradient(160deg, #C9A0FF, var(--violet)); animation-delay: -0.8s; }
.brand__tile.t4 { background: linear-gradient(160deg, #FFD79A, var(--amber)); animation-delay: -1.2s; }

@keyframes tilePulse {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-4px) scale(1.04); }
}

.brand__title {
  margin: 0;
  font-size: clamp(34px, 12vw, 46px);
  font-weight: 800;
  letter-spacing: 0.14em;
  background: linear-gradient(120deg, #FFFFFF 0%, var(--cyan-soft) 45%, var(--indigo-light) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand__tagline {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.best-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 14px 30px;
  border-radius: var(--radius-md);
  border: 1px solid var(--stroke);
  background: rgba(140, 151, 255, 0.08);
}
.best-card__label { font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-faint); }
.best-card__value { font-size: 30px; font-weight: 750; font-variant-numeric: tabular-nums; }

.menu__actions { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.menu__foot { margin: 0; font-size: 12px; color: var(--text-faint); }

/* ------------------------------------------------------------------- hud */

.screen--game { padding-top: calc(var(--safe-top) + 6px); }

.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 4px 2px 10px;
}

.hud__side { display: flex; flex-direction: column; gap: 2px; }
.hud__side--end { align-items: flex-end; }
.hud__label { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-faint); }
.hud__value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text-dim); }

.hud__score {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 26px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(140, 151, 255, 0.07);
  min-width: 148px;
}
.hud__score-value {
  font-size: 30px;
  font-weight: 800;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(120deg, #FFFFFF, var(--cyan-soft));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hud__score.is-bump { animation: bump 0.28s ease; }
@keyframes bump {
  0% { transform: scale(1); }
  45% { transform: scale(1.09); }
  100% { transform: scale(1); }
}

.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: 1px solid var(--stroke);
  background: rgba(140, 151, 255, 0.09);
  display: grid;
  place-items: center;
}
.icon-btn__bars,
.icon-btn__bars::before,
.icon-btn__bars::after {
  display: block;
  width: 17px;
  height: 2px;
  border-radius: 2px;
  background: var(--text);
}
.icon-btn__bars { position: relative; }
.icon-btn__bars::before { content: ''; position: absolute; top: -6px; }
.icon-btn__bars::after { content: ''; position: absolute; top: 6px; }

/* ----------------------------------------------------------------- stage */

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  margin-bottom: 0;
  transition: margin-bottom 0.2s ease;
}

/* While the tutorial coach is open, reserve room at the bottom of the game
   screen so the tray AND the trashcan stay visible and reachable. */
.app.is-tutorial .screen--game {
  padding-bottom: calc(var(--safe-bottom) + 8px + var(--coach-h, 210px));
}

#board {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.stage__toast {
  position: absolute;
  left: 50%;
  top: 8px;
  transform: translateX(-50%) translateY(-8px);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(11, 14, 34, 0.9);
  border: 1px solid var(--stroke-strong);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  white-space: nowrap;
  max-width: 92%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stage__toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* -------------------------------------------------------------- controls */

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 0 4px;
}

.trash {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-radius: 999px;
  border: 1px solid var(--stroke-strong);
  background: linear-gradient(160deg, rgba(47, 212, 224, 0.16), rgba(91, 107, 255, 0.14));
  box-shadow: var(--shadow-soft);
  min-height: 52px;
  transition: transform 0.15s ease, opacity 0.2s ease, border-color 0.2s ease;
}
.trash:active { transform: scale(0.97); }
.trash:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }

.trash__icon { width: 26px; height: 26px; display: block; }
.trash__icon svg { width: 100%; height: 100%; }
.trash__icon path { fill: none; stroke: var(--cyan-soft); stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.trash__state { font-size: 12px; font-weight: 750; letter-spacing: 0.16em; color: var(--cyan-soft); }

.trash.is-used {
  opacity: 0.45;
  border-color: rgba(140, 151, 255, 0.2);
  background: rgba(255, 255, 255, 0.03);
}
.trash.is-used .trash__icon path { stroke: var(--text-faint); }
.trash.is-used .trash__state { color: var(--text-faint); }
.trash.is-target { border-color: var(--amber); box-shadow: 0 0 0 4px rgba(255, 179, 71, 0.18); }
.trash.is-armed { border-color: var(--amber); background: rgba(255, 179, 71, 0.18); }

.controls__hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
  min-height: 16px;
}

/* -------------------------------------------------------------- overlays */

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(6, 8, 20, 0.72);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  z-index: 20;
}
.overlay.is-active { display: flex; }

.panel {
  width: min(400px, 100%);
  border-radius: var(--radius-lg);
  border: 1px solid var(--stroke);
  background: var(--panel);
  box-shadow: var(--shadow-deep);
  padding: 26px 22px 22px;
  text-align: center;
  animation: panelIn 0.24s ease;
}
@keyframes panelIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.panel__kicker {
  margin: 0 0 4px;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--amber);
}
.panel__title { margin: 0 0 8px; font-size: 26px; font-weight: 780; }
.panel__text { margin: 0 0 18px; color: var(--text-dim); font-size: 14px; line-height: 1.5; }
.panel__note { margin: 14px 0 0; color: var(--text-faint); font-size: 12px; line-height: 1.5; }
.panel__actions { display: flex; flex-direction: column; gap: 10px; }
.panel__actions--stack { margin-top: 6px; }

.score-compare {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0 16px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--stroke);
  background: rgba(140, 151, 255, 0.07);
}
.score-compare__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 14px;
  color: var(--text-dim);
}
.score-compare__row strong { font-size: 24px; font-weight: 780; color: var(--text); font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- settings */

.settings-list { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 4px;
  border-bottom: 1px solid rgba(140, 151, 255, 0.12);
  font-size: 15px;
  text-align: left;
}
.settings-row:last-child { border-bottom: none; }

.switch {
  appearance: none;
  -webkit-appearance: none;
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--stroke);
  position: relative;
  transition: background 0.2s ease;
  flex: 0 0 auto;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
.switch:checked { background: linear-gradient(135deg, var(--indigo), var(--cyan)); border-color: transparent; }
.switch:checked::after { transform: translateX(22px); }
.switch:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

/* -------------------------------------------------------------- tutorial */

.coach {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  padding: 8px calc(var(--safe-right) + 12px) calc(var(--safe-bottom) + 8px) calc(var(--safe-left) + 12px);
  z-index: 25;
  pointer-events: none;
}
.coach.is-active { display: block; }

.coach__card {
  pointer-events: auto;
  width: min(460px, 100%);
  margin: 0 auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--stroke-strong);
  background: var(--panel);
  box-shadow: var(--shadow-deep);
  padding: 16px 18px 18px;
  animation: panelIn 0.22s ease;
}

.coach__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.coach__step { font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--cyan-soft); }
.coach__skip {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 13px;
  font-weight: 650;
  padding: 6px 8px;
  border-radius: 10px;
}
.coach__skip:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

.coach__title { margin: 0 0 6px; font-size: 19px; font-weight: 750; }
.coach__body { margin: 0; font-size: 14px; line-height: 1.5; color: var(--text-dim); }
.coach__hint { margin: 10px 0 0; font-size: 13px; font-weight: 650; color: var(--amber); }
.coach__actions { margin-top: 14px; display: flex; gap: 10px; }
.coach__actions .btn { flex: 1; }
.coach__actions[hidden] { display: none; }

/* ------------------------------------------------------- reduced motion */

body.reduced-motion .orb,
body.reduced-motion .brand__tile { animation: none; }
body.reduced-motion .panel,
body.reduced-motion .coach__card { animation: none; }

@media (prefers-reduced-motion: reduce) {
  .orb, .brand__tile { animation: none; }
}

/* ------------------------------------------------------------- landscape */

@media (orientation: landscape) and (max-height: 520px) {
  .hud { padding-bottom: 4px; }
  .hud__score-value { font-size: 24px; }
  .controls { flex-direction: row; justify-content: center; gap: 16px; }
  .controls__hint { min-height: 0; }
}

/* --------------------------------------------------------- narrow screens */

@media (max-width: 360px) {
  .hud__score { min-width: 122px; padding: 6px 16px; }
  .hud__score-value { font-size: 25px; }
  .btn { font-size: 15px; padding: 13px 18px; }
}
