:root {
  --bg-grad-a: #fef9ef;
  --bg-grad-b: #eafbf7;
  --card-panel: #ffffff;
  --text: #1c2a2e;
  --muted: #607470;
  --primary: #14b8a6;
  --primary-dark: #0d8f81;
  --primary-light: #5eead4;
  --accent: #f97316;
  --accent-dark: #c2570a;
  --accent-2: #6366f1;
  --accent-2-dark: #4338ca;
  --border: #dbeee9;
  --shadow: 0 8px 24px rgba(13, 100, 90, 0.14);
  --radius: 16px;
  --cell-w: clamp(26px, 6.4vw, 42px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(135deg, var(--bg-grad-a), var(--bg-grad-b));
  color: var(--text);
  display: flex;
  flex-direction: column;
}

a { color: inherit; }

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding: 18px 28px;
  background: rgba(255, 255, 255, 0.78);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  transition: transform 0.25s ease;
}

@media (orientation: portrait) {
  .site-header.header-hidden { transform: translateY(-100%); }
}

.brand a {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.brand-icon {
  font-size: 20px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  box-shadow: 0 4px 10px rgba(20, 184, 166, 0.35);
}

.brand-name {
  font-size: 20px;
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--primary-dark), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tabs {
  display: flex;
  gap: 6px;
  background: var(--card-panel);
  padding: 6px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.tab-btn {
  border: none;
  background: transparent;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.18s ease;
  white-space: nowrap;
  display: inline-block;
}

.tab-btn:hover { color: var(--primary-dark); }

.tab-btn.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  box-shadow: 0 4px 12px rgba(20, 184, 166, 0.35);
}

/* Main content */
.content {
  flex: 1;
  padding: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.hero {
  max-width: 980px;
  width: 100%;
  text-align: center;
}

.hero h1 {
  font-size: clamp(22px, 3.6vw, 32px);
  margin: 4px 0 8px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.hero-tagline {
  color: var(--muted);
  font-size: 14px;
  max-width: 680px;
  margin: 0 auto;
  line-height: 1.6;
}

.hero-tagline a { color: var(--primary-dark); font-weight: 700; text-decoration: none; }
.hero-tagline a:hover { text-decoration: underline; }

/* Game switcher grid (homepage cross-links) */
.game-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  max-width: 720px;
  width: 100%;
}

.game-card {
  background: var(--card-panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid transparent;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.game-card:hover { transform: translateY(-3px); border-color: var(--primary-light); }
.game-card .gc-icon { font-size: 26px; }
.game-card h3 { margin: 0; font-size: 16px; font-weight: 800; }
.game-card p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }

/* Game panel layout */
.game-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 1180px;
  width: 100%;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.game-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

.board-header { width: 100%; max-width: 1180px; }
.board-header h2 { margin: 0 0 4px 0; font-size: 22px; font-weight: 800; }

.game-intro {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  max-width: 760px;
}

.status {
  font-size: 13px;
  color: var(--muted);
  min-height: 18px;
  font-weight: 600;
}

.status.status-error { color: var(--accent-dark); }
.status.status-good { color: var(--primary-dark); }

/* Board area (holds the puzzle grid) — shrink-wraps to the grid's actual
   rendered size instead of flex-growing, so smaller grids (e.g. Easy word
   search) don't leave dead space inside an oversized frame. */
.board-area {
  flex: 0 1 auto;
  max-width: 100%;
  background:
    radial-gradient(ellipse at top, rgba(255,255,255,0.5), transparent 60%),
    linear-gradient(160deg, #ffffff, #f3fbf9 60%);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  overflow: auto;
  display: flex;
  justify-content: center;
}

/* Side panel (difficulty, language, controls, stats) */
.side-panel {
  flex: 0 0 240px;
  background: var(--card-panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-self: flex-start;
  height: fit-content;
}

.new-game-btn {
  border: none;
  padding: 13px 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #ffb26b);
  color: #402200;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(249, 115, 22, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.new-game-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 18px rgba(249, 115, 22, 0.4); }
.new-game-btn:active { transform: translateY(0); }

.secondary-btn {
  border: 1px solid var(--border);
  background: #f4fdfb;
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}

.secondary-btn:hover { background: #e8faf5; }
.secondary-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-row { display: flex; gap: 8px; }
.btn-row .secondary-btn { flex: 1; }

.control-group { display: flex; flex-direction: column; gap: 6px; }

.control-group label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.control-group select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

.stat-row span:last-child { color: var(--text); font-weight: 800; font-variant-numeric: tabular-nums; }

.hint { font-size: 12px; color: var(--muted); margin: 0; line-height: 1.5; }

/* ---------- Crossword grid ---------- */
.cw-grid {
  display: grid;
  gap: 2px;
  background: var(--border);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  width: max-content;
}

.cw-cell {
  position: relative;
  width: var(--cell-w);
  height: var(--cell-w);
  background: #fff;
}

.cw-cell.blocked { background: transparent; }

.cw-cell input {
  width: 100%;
  height: 100%;
  border: none;
  text-align: center;
  text-transform: uppercase;
  font-size: calc(var(--cell-w) * 0.5);
  font-weight: 700;
  background: transparent;
  color: var(--text);
  padding: 0;
  caret-color: transparent;
}

.cw-cell input:focus { outline: none; }

.cw-cell.active-cell { background: var(--primary-light); }
.cw-cell.active-word { background: #d3fdf5; }
.cw-cell.active-word.active-cell { background: var(--primary-light); }

.cw-cell.wrong input { color: var(--accent-dark); }
.cw-cell.wrong { animation: shake 0.3s ease; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-2px); }
  75% { transform: translateX(2px); }
}

.cw-number {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: calc(var(--cell-w) * 0.24);
  font-weight: 700;
  color: var(--muted);
  pointer-events: none;
}

.cw-clues {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  max-width: 1180px;
  width: 100%;
  background: var(--card-panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}

.cw-clue-list h3 {
  margin: 0 0 8px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary-dark);
}

.cw-clue-list ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }

.cw-clue-list li {
  font-size: 13px;
  line-height: 1.4;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
}

.cw-clue-list li:hover { background: #eafbf7; }
.cw-clue-list li.solved { color: var(--muted); text-decoration: line-through; }
.cw-clue-list li.active-clue { background: var(--primary-light); font-weight: 700; }
.cw-clue-list li b { font-weight: 800; margin-right: 4px; }

/* ---------- Word search grid ---------- */
.ws-grid-wrap { position: relative; touch-action: none; }

.ws-grid {
  display: grid;
  gap: 0;
  user-select: none;
  position: relative;
}

.ws-cell {
  width: var(--cell-w);
  height: var(--cell-w);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell-w) * 0.46);
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  border-radius: 50%;
  position: relative;
  z-index: 2;
}

.ws-cell.selecting { background: rgba(99, 102, 241, 0.25); }
.ws-cell.found { color: #fff; }

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

.ws-word-list {
  max-width: 1180px;
  width: 100%;
  background: var(--card-panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}

.ws-word-list h3 {
  margin: 0 0 10px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary-dark);
}

.ws-word-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px 16px;
}

.ws-word-list li {
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--text);
  padding: 4px 0;
  border-bottom: 1px dashed var(--border);
}

.ws-word-list li .ws-word { font-weight: 800; letter-spacing: 0.02em; }
.ws-word-list li .ws-clue { display: block; font-size: 11.5px; color: var(--muted); font-weight: 500; }
.ws-word-list li.found .ws-word { text-decoration: line-through; color: var(--muted); }

/* Win overlay */
.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 40, 36, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.win-overlay.show { display: flex; }

.win-card {
  background: var(--card-panel);
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.4);
}

.win-card h2 {
  margin: 0 0 6px;
  font-size: 26px;
  background: linear-gradient(90deg, var(--primary-dark), var(--accent-dark));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.win-card p { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.win-stats { display: flex; justify-content: center; gap: 18px; margin-bottom: 18px; font-size: 13px; color: var(--muted); }
.win-stats strong { display: block; font-size: 20px; color: var(--text); }

.confetti-piece {
  position: fixed;
  top: -20px;
  z-index: 2001;
  border-radius: 2px;
  pointer-events: none;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  to { transform: translateY(105vh) rotate(540deg); opacity: 0.4; }
}

/* Info / FAQ sections */
.info-section {
  max-width: 860px;
  width: 100%;
  background: var(--card-panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 28px;
}

.info-section h2 { margin: 0 0 12px; font-size: 19px; font-weight: 800; }
.info-section h3 { font-size: 15px; margin: 16px 0 6px; font-weight: 700; color: var(--primary-dark); }
.info-section p, .info-section li { font-size: 13.5px; line-height: 1.65; color: var(--text); }
.info-section ul, .info-section ol { padding-left: 20px; margin: 8px 0; }

.faq details { border-top: 1px solid var(--border); padding: 12px 0; }
.faq details:first-of-type { border-top: none; padding-top: 0; }

.faq summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; font-size: 18px; color: var(--primary); font-weight: 800; }
.faq details[open] summary::after { content: "\2212"; }
.faq details p { margin: 8px 0 0; color: var(--muted); }

/* Footer */
.site-footer { text-align: center; padding: 16px; font-size: 12px; color: var(--muted); }
.site-footer p { margin: 0 0 4px; }
.site-footer a { color: var(--primary-dark); font-weight: 600; text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 900px) {
  .game-layout { flex-direction: column; }
  .side-panel { flex-direction: row; flex-wrap: wrap; width: 100%; order: 1; }
  .board-area { order: 2; }
  .side-panel .new-game-btn { flex: 1 1 100%; }
  .side-panel .control-group { flex: 1 1 140px; }
  .cw-clues { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .site-header { flex-direction: column; align-items: flex-start; }
  .game-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .board-area { padding: 12px; }
}

.tab-btn.home-link {
  margin-left: 8px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
  opacity: 0.75;
}
.tab-btn.home-link:hover { opacity: 1; }
