/* Worpzle — Plum theme (visual refresh)
   Tokens sourced from docs/UI Refresh 1/Plum Handoff/tokens.css */

:root {
  --bg: #2a1a2e; /* page */
  --ink: #f6e9f0; /* primary text */
  --tile: #3b2640; /* tiles, buttons, select, cards */
  --board: #1f1223; /* board frame, stat dividers */
  --muted: #b79bb4; /* secondary text */
  --accent: #f4c542; /* title dot, active selector dot, gold rating */
  --good: #7be0b0; /* solved message */
  --sel: #5e3f52; /* selected/hovered 2x2 block fill */
  --ok: #54774b; /* covered tile fill (part of a valid word) */
  --line: #6a4a6e; /* all borders */
  --gold: #7d6a2e; /* word locked in its final solved-grid position */
  --progress: #9e89a1; /* progress bar fill */
  --sel-border: color-mix(in srgb, var(--sel) 70%, black);
  --ok-border: color-mix(in srgb, var(--ok) 70%, black);
  --gold-border: color-mix(in srgb, var(--gold) 70%, black);

  --silver: #cbd5e1;
  --bronze: #d99a4e;

  /* Extra indicators layered on top of the Plum palette for word
     highlighting (not part of the original token set, chosen to sit
     comfortably alongside it). */
  --row-word: var(--good);
  --col-word: #d99bc4;

  --r-sm: 5px;
  --r-md: 6px;
  --r-lg: 10px;
  --border-w: 2px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "DM Sans", sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  justify-content: center;
  padding: 28px 16px;
}

button {
  font-family: inherit;
}

#app {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* --- Title block ----------------------------------------------------- */

.title-block {
  text-align: center;
}

.title-block h1 {
  margin: 0;
  font-weight: 700;
  font-size: clamp(38px, 12vw, 56px);
  line-height: 1;
  letter-spacing: -0.03em;
}

.title-block h1 .accent-dot {
  color: var(--accent);
}

.title-block .subtitle {
  font-size: 14px;
  color: var(--muted);
  margin: 4px 0 0;
}

/* --- Toolbar ----------------------------------------------------------- */

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar__spacer {
  flex: 1;
}

.select,
.btn {
  font-size: 15px;
  font-weight: 700;
  border: var(--border-w) solid var(--line);
  border-radius: var(--r-md);
  background: var(--tile);
  color: var(--ink);
  cursor: pointer;
}

.select {
  font-weight: 500;
  padding: 10px 12px;
  min-width: 0;
}

.btn {
  padding: 10px 18px;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn:focus-visible,
.select:focus-visible,
.handle:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.icon-btn {
  font-size: 15px;
  font-weight: 700;
  border: var(--border-w) solid var(--line);
  border-radius: var(--r-md);
  background: var(--tile);
  color: var(--ink);
  cursor: pointer;
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-btn:hover {
  border-color: var(--accent);
}

/* --- Stats card ---------------------------------------------------- */

.stats-card {
  background: var(--tile);
  border: var(--border-w) solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stats-card__row {
  display: flex;
}

.stat {
  flex: 1;
  text-align: center;
}

.stat--divider {
  border-left: var(--border-w) solid var(--board);
}

.stat__label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat__value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.stat__suffix {
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-bar {
  flex: 1;
  height: 8px;
  border: var(--border-w) solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg);
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  background: var(--progress);
  width: 0%;
  transition: width 0.3s ease;
}

.progress-label {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.progress-label__suffix {
  font-weight: 500;
  color: var(--muted);
}

.word-feed {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 1.6rem;
}

.word-feed__chip {
  font-size: 13px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  border: var(--border-w) solid var(--line);
  background: var(--bg);
  color: var(--muted);
}

.word-feed__chip--latest {
  color: var(--accent);
  border-color: var(--accent);
}

/* --- Status line -------------------------------------------------- */

.status-line {
  font-size: 15px;
  font-weight: 700;
  color: var(--good);
  text-align: center;
  margin: -10px 0 -6px;
  min-height: 1px;
}

.status-line:empty {
  margin: 0;
}

/* --- Board ----------------------------------------------------------- */

.board-wrap {
  position: relative;
  background: var(--board);
  border: var(--border-w) solid var(--line);
  border-radius: var(--r-lg);
  padding: 14px;
  /* Swipe-to-rotate reads raw touch drags, so the browser must not
     hijack them for page scrolling/panning. */
  touch-action: none;
}

.board {
  position: relative;
  display: grid;
  gap: 8px;
}

.tile {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  background: var(--tile);
  border: var(--border-w) solid var(--line);
  border-radius: var(--r-sm);
  font-size: clamp(24px, 9vw, 44px);
  font-weight: 700;
  color: var(--ink);
  transform: translateY(0);
  transition: transform 0.12s ease, background-color 0.12s ease, border-color 0.12s ease;
  user-select: none;
}

/* Priority high -> low: active (selected/hovered) block, final-position
   word, covered (part of any valid word), default. */

.tile--covered {
  background: var(--ok);
  border-color: var(--ok-border);
}

.tile--final-word {
  background: var(--gold);
  border-color: var(--gold-border);
}

.tile--row-word {
  box-shadow: inset 0 -4px 0 0 var(--row-word);
}

.tile--col-word {
  box-shadow: inset -4px 0 0 0 var(--col-word);
}

.tile--row-word.tile--col-word {
  box-shadow:
    inset 0 -4px 0 0 var(--row-word),
    inset -4px 0 0 0 var(--col-word);
}

/* Block highlight: a border frame surrounding the whole selected/hovered
   2x2 block, rather than filling each of its tiles. Positioned in JS
   (board.js) to exactly track the block's four tiles. */
.block-highlight {
  position: absolute;
  border: 3px solid var(--accent);
  border-radius: var(--r-md);
  pointer-events: none;
  opacity: 0;
  transition: left 0.12s ease, top 0.12s ease, width 0.12s ease, height 0.12s ease, opacity 0.12s ease;
}

.block-highlight--visible {
  opacity: 1;
}

.tile--credited-flash {
  animation: credited-flash 900ms ease-out;
}

.tile--hidden-for-animation {
  opacity: 0;
}

@keyframes credited-flash {
  0% {
    background: var(--accent);
    transform: scale(1.08);
  }
  100% {
    background: var(--ok);
    transform: scale(1);
  }
}

.handles-layer {
  position: absolute;
  inset: 14px;
  pointer-events: none;
}

.handle {
  position: absolute;
  width: 40px;
  height: 40px;
  transform: translate(-50%, -50%);
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.handle__dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: var(--border-w) solid var(--line);
  background: var(--bg);
  transition: width 0.12s ease, height 0.12s ease, background-color 0.12s ease;
}

.handle--active .handle__dot {
  width: 20px;
  height: 20px;
  background: var(--accent);
}

/* --- Rotation animation overlay ------------------------------------ */

.rotation-overlay {
  position: fixed;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  z-index: 50;
  pointer-events: none;
  transition: transform 220ms ease;
}

.rotation-overlay .tile {
  margin: 0;
}

/* --- Rotate controls ------------------------------------------------ */

.controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.controls .btn {
  padding: 12px 20px;
}

/* --- Help overlay ---------------------------------------------------- */

.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 10, 17, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.help-overlay[hidden] {
  display: none;
}

.help-card {
  background: var(--tile);
  border: var(--border-w) solid var(--line);
  border-radius: var(--r-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 400px;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}

.help-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.help-card h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.help-card h3 {
  margin: 1rem 0 0.4rem;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.help-card p {
  margin: 0.75rem 0 0;
  font-size: 14px;
  line-height: 1.5;
}

.help-card ul {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.help-card .icon-btn {
  width: 36px;
  height: 36px;
  font-size: 20px;
  line-height: 1;
}

.help-swatch {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: var(--r-sm);
  vertical-align: middle;
  margin-right: 0.2rem;
}

.help-swatch--covered {
  background: var(--ok);
  border: var(--border-w) solid var(--ok-border);
}

.help-swatch--final {
  background: var(--gold);
  border: var(--border-w) solid var(--gold-border);
}

.help-swatch--row {
  background: var(--tile);
  border: var(--border-w) solid var(--line);
  box-shadow: inset 0 -4px 0 0 var(--row-word);
}

.help-swatch--col {
  background: var(--tile);
  border: var(--border-w) solid var(--line);
  box-shadow: inset -4px 0 0 0 var(--col-word);
}

/* --- Completion overlay --------------------------------------------- */

.completion-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 10, 17, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.completion-overlay[hidden] {
  display: none;
}

.completion-card {
  background: var(--tile);
  border: var(--border-w) solid var(--line);
  border-radius: var(--r-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.completion-card h2 {
  margin: 0 0 0.25rem;
  font-size: 20px;
  font-weight: 700;
}

.completion-rating {
  font-size: 44px;
  font-weight: 700;
  margin: 0.25rem 0 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.completion-rating--gold {
  color: var(--accent);
}

.completion-rating--silver {
  color: var(--silver);
}

.completion-rating--bronze {
  color: var(--bronze);
}

.completion-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin: 1rem 0;
  text-align: left;
}

.completion-stats div {
  background: var(--board);
  border-radius: var(--r-md);
  padding: 0.5rem;
}

.completion-stats dt {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.completion-stats dd {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.completion-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- Reduced motion --------------------------------------------------- */

body.reduced-motion .tile,
body.reduced-motion .handle__dot,
body.reduced-motion .progress-bar__fill,
body.reduced-motion .btn {
  transition: none !important;
}

body.reduced-motion .tile--credited-flash {
  animation: none !important;
  background: var(--ok);
}

body.reduced-motion .rotation-overlay {
  transition: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .handle__dot,
  .progress-bar__fill,
  .btn,
  .rotation-overlay {
    transition: none !important;
  }

  .tile--credited-flash {
    animation: none !important;
  }
}
