/* ═══════════════════════════════════════════════════════════════
   crossword.css — Kreuzworträtsel-spezifische Styles
   Ergänzt style.css · Keine Duplikate der Design-Tokens
   klickspiele.de · v1.0.0
═══════════════════════════════════════════════════════════════ */

/* ══════════════════════════════════════
   1. INTRO SECTION (above the fold)
══════════════════════════════════════ */
.cw-intro {
  background: linear-gradient(135deg, var(--c-primary-container) 0%, var(--c-surf-low) 100%);
  border-bottom: 2px solid var(--c-outline-var);
  padding: 20px 16px 16px;
}

.cw-intro__inner {
  max-width: var(--content-max);
  margin: 0 auto;
}

.cw-intro__h1 {
  font-size: clamp(18px, 4vw, 26px);
  font-weight: 700;
  line-height: 1.3;
  color: var(--c-on-primary-container);
  margin-bottom: 8px;
}

.cw-intro__lead {
  font-size: 15px;
  line-height: 24px;
  color: var(--c-on-surf-var);
  max-width: 640px;
}

body.dark-mode .cw-intro {
  background: linear-gradient(135deg, #2A1400 0%, var(--c-surf-low) 100%);
}

/* ══════════════════════════════════════
   2. GRID CONTAINER & LAYOUT
══════════════════════════════════════ */

/* Dynamic cell sizing based on grid dimensions */
:root {
  --cw-cell-size: calc(var(--grid-sz, min(96vw, 500px)) / var(--cw-cols, 11));
}

#cw-grid {
  display: grid;
  grid-template-rows: repeat(var(--cw-rows, 11), var(--cw-cell-size));
  width: var(--grid-sz, min(96vw, 500px));
  border: 2px solid var(--c-outline);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--elev-2);
  background: var(--c-outline-var);
  gap: 1px;
  margin: 0 auto;
  /* Prevent layout shift */
  aspect-ratio: var(--cw-cols, 11) / var(--cw-rows, 11);
}

.cw-row {
  display: grid;
  grid-template-columns: repeat(var(--cw-cols, 11), 1fr);
  gap: 1px;
}

/* ══════════════════════════════════════
   3. CELLS
══════════════════════════════════════ */
.cw-cell {
  background: var(--c-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  overflow: hidden;
  transition: background var(--dur-fast) var(--ease);
  min-width: 0;
  min-height: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.cw-cell--black {
  background: var(--c-on-bg, #111111);
  cursor: default;
}

.cw-cell:focus-visible {
  outline: 2.5px solid var(--c-primary);
  outline-offset: -2px;
  z-index: 2;
}

/* ── Cell highlight states ─────────────────────── */
.cw-cell--active   { background: var(--c-cell-sel,   #FFE0B2) !important; }
.cw-cell--word     { background: var(--c-cell-rel,   #FFF8F0); }
.cw-cell--correct  { background: #E8F5E9; }
.cw-cell--revealed { background: #E3F2FD; }
.cw-cell--error    { background: var(--c-error-container, #FFDAD6); }

/* ── Dark mode cell states ─────────────────────── */
body.dark-mode .cw-cell              { background: var(--c-surface); }
body.dark-mode .cw-cell--black       { background: #000000; }
body.dark-mode .cw-cell--active      { background: #4A2800 !important; }
body.dark-mode .cw-cell--word        { background: #1F1507; }
body.dark-mode .cw-cell--correct     { background: #1B3A1E; }
body.dark-mode .cw-cell--revealed    { background: #0D2A3A; }
body.dark-mode .cw-cell--error       { background: #3B0A08; }

/* ── Hover shimmer (not on touch) ──────────────── */
@media (hover: hover) {
  .cw-cell:not(.cw-cell--black):not(.cw-cell--active):hover {
    background: var(--c-surf-high);
  }
}

/* ── Cell number (top-left clue number) ─────────── */
.cw-cell__num {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: clamp(7px, 1.4vw, 11px);
  font-weight: 700;
  line-height: 1;
  color: var(--c-on-surf-var);
  pointer-events: none;
  z-index: 1;
}

/* ── Cell letter ────────────────────────────────── */
.cw-cell__letter {
  font-family: var(--font-ui);
  font-size: clamp(11px, 3.2vw, 24px);
  font-weight: 800;
  line-height: 1;
  color: var(--c-primary);
  pointer-events: none;
  z-index: 1;
  text-transform: uppercase;
}

.cw-cell--revealed .cw-cell__letter { color: #1565C0; }
.cw-cell--correct  .cw-cell__letter { color: #2E7D32; }
.cw-cell--error    .cw-cell__letter { color: var(--c-error); }

body.dark-mode .cw-cell--revealed .cw-cell__letter { color: #64B5F6; }
body.dark-mode .cw-cell--correct  .cw-cell__letter { color: #81C784; }

/* ══════════════════════════════════════
   4. ACTIVE CLUE BAR
══════════════════════════════════════ */
#cw-clue-bar {
  max-width: var(--grid-sz, min(96vw, 500px));
  margin: 8px auto 4px;
  background: var(--c-surf-mid);
  border-radius: var(--r-md);
  padding: 10px 14px;
  font-size: 15px;
  font-weight: 500;
  line-height: 22px;
  color: var(--c-on-surf-var);
  min-height: 44px;
  border: 1.5px solid var(--c-outline-var);
  transition: background var(--dur-fast);
}

/* ══════════════════════════════════════
   5. PROGRESS BAR
══════════════════════════════════════ */
#cw-progress-wrap {
  max-width: var(--grid-sz, min(96vw, 500px));
  margin: 4px auto 0;
  padding: 0 2px;
}

#cw-progress-track {
  height: 5px;
  border-radius: var(--r-full);
  background: var(--c-surf-high);
  overflow: hidden;
}

#cw-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--c-primary);
  border-radius: var(--r-full);
  transition: width var(--dur-slow) var(--ease);
}

/* ══════════════════════════════════════
   6. CLUE LISTS
══════════════════════════════════════ */
.cw-clues-section {
  max-width: var(--content-max, 760px);
  margin: 20px auto 0;
  padding: 0 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 540px) {
  .cw-clues-section { grid-template-columns: 1fr; }
}

.cw-clues-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--c-on-surf-var);
  margin-bottom: 6px;
  padding-left: 2px;
}

#cw-list-h,
#cw-list-v {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 300px;
  overflow-y: auto;
  border: 1.5px solid var(--c-outline-var);
  border-radius: var(--r-md);
  background: var(--c-surf-low);
  scroll-behavior: smooth;
  /* Custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--c-outline-var) transparent;
}

#cw-list-h::-webkit-scrollbar,
#cw-list-v::-webkit-scrollbar { width: 4px; }
#cw-list-h::-webkit-scrollbar-thumb,
#cw-list-v::-webkit-scrollbar-thumb {
  background: var(--c-outline-var);
  border-radius: 4px;
}

.cw-clue {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px 12px;
  border-bottom: 1px solid var(--c-outline-var);
  cursor: pointer;
  font-size: 14px;
  line-height: 20px;
  transition: background var(--dur-fast) var(--ease);
  position: relative;
  overflow: hidden;
}

.cw-clue:last-child { border-bottom: none; }

@media (hover: hover) {
  .cw-clue:hover { background: var(--c-surf-mid); }
}

.cw-clue:focus-visible {
  outline: var(--focus-ring);
  outline-offset: -3px;
  border-radius: var(--r-sm);
}

.cw-clue--active {
  background: var(--c-primary-container) !important;
  color: var(--c-on-primary-container);
}

.cw-clue--done {
  opacity: 0.42;
  text-decoration: line-through;
  pointer-events: none;
}

.cw-clue__n {
  font-weight: 800;
  color: var(--c-primary);
  min-width: 22px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.cw-clue--active .cw-clue__n {
  color: var(--c-on-primary-container);
}

.cw-clue__t {
  color: var(--c-on-surf-var);
  flex: 1;
}

.cw-clue__len {
  color: var(--c-outline);
  font-style: normal;
  font-size: 13px;
  margin-left: 3px;
}

/* ══════════════════════════════════════
   7. ANIMATIONS
══════════════════════════════════════ */
@keyframes cw-pop {
  0%   { transform: scale(0.45); }
  60%  { transform: scale(1.28); }
  100% { transform: scale(1); }
}

@keyframes cw-shake {
  0%,100% { transform: translateX(0); }
  18%     { transform: translateX(-5px); }
  36%     { transform: translateX(5px); }
  54%     { transform: translateX(-4px); }
  72%     { transform: translateX(4px); }
  90%     { transform: translateX(-2px); }
}

@keyframes cw-flash-score {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0)   scale(1); }
  70%  { opacity: 1; transform: translateX(-50%) translateY(-28px) scale(1.1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-40px) scale(0.9); }
}

.cw-anim-pop {
  animation: cw-pop var(--dur-normal) var(--ease) both;
}

.cw-anim-shake {
  animation: cw-shake 340ms var(--ease) both;
}

.cw-anim-flash {
  animation: cw-flash-score 900ms var(--ease) both;
}

/* ══════════════════════════════════════
   8. SCORE FLASH & CONFETTI
══════════════════════════════════════ */
#cw-score-flash {
  position: fixed;
  bottom: 200px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 26px;
  font-weight: 900;
  color: var(--c-primary);
  pointer-events: none;
  opacity: 0;
  z-index: 400;
  text-shadow: 0 2px 8px rgba(0,0,0,.2);
}

#cw-confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 500;
  display: none;
}

/* ══════════════════════════════════════
   9. HIDDEN INPUT (keyboard capture)
══════════════════════════════════════ */
#cw-hidden-input {
  position: fixed;
  top: -9999px;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  border: none;
  background: transparent;
}

/* ══════════════════════════════════════
   10. TOAST NOTIFICATIONS
══════════════════════════════════════ */
.cw-toast {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--c-on-bg);
  color: var(--c-bg);
  padding: 10px 24px;
  border-radius: var(--r-full);
  font-size: 15px;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  z-index: 600;
  white-space: nowrap;
  box-shadow: var(--elev-2);
  transition:
    opacity   var(--dur-normal) var(--ease),
    transform var(--dur-normal) var(--ease);
}

.cw-toast--show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.cw-toast--success { background: #2E7D32; color: #fff; }
.cw-toast--error   { background: var(--c-error); color: #fff; }
.cw-toast--info    { background: var(--c-secondary); color: #fff; }

/* ══════════════════════════════════════
   11. STATS DIALOG BODY
══════════════════════════════════════ */
.cw-stat-row {
  display: grid;
  grid-template-columns: 28px 1fr 60px 80px;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--c-outline-var);
  font-size: 14px;
}

.cw-stat-row:last-child { border-bottom: none; }
.cw-stat-rank  { font-weight: 800; color: var(--c-primary); }
.cw-stat-score { font-weight: 700; }
.cw-stat-time  { font-family: var(--font-mono); font-size: 13px; }
.cw-stat-date  { color: var(--c-outline); font-size: 12px; text-align: right; }

/* ══════════════════════════════════════
   12. SCREEN-READER ONLY UTILITY
══════════════════════════════════════ */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ══════════════════════════════════════
   13. DESKTOP ≥ 900px OVERRIDES
══════════════════════════════════════ */
@media (min-width: 900px) {
  :root { --grid-sz: 500px; }

  .cw-clues-section {
    max-width: calc(var(--grid-sz) + 340px);
    grid-template-columns: 1fr 1fr;
  }

  #cw-list-h,
  #cw-list-v { max-height: 400px; }

  #cw-clue-bar { font-size: 16px; }
}

/* ══════════════════════════════════════
   14. LARGE DESKTOP ≥ 1200px
══════════════════════════════════════ */
@media (min-width: 1200px) {
  :root { --grid-sz: 540px; }
}

/* ══════════════════════════════════════
   15. PRINT
══════════════════════════════════════ */
@media print {
  .cw-intro,
  .cw-clues-section,
  .cw-clue-bar,
  #cw-progress-wrap,
  .toolbar-row,
  .diff-row,
  #cw-score-flash,
  #cw-confetti,
  .seo-section { display: none !important; }

  #cw-grid {
    box-shadow: none;
    border: 2px solid #000;
    border-radius: 0;
    width: 100%;
    margin: 0;
  }

  :root { --grid-sz: 100%; }

  .cw-cell { background: #fff !important; }
  .cw-cell--black { background: #000 !important; }
  .cw-cell__letter { color: #000 !important; }
  .cw-cell__num    { color: #333 !important; }
}
