/* Connections v1.0.0 */
:root {
  --bg: #0f1419;
  --bg-soft: #161b22;
  --surface: #1c2330;
  --surface-hover: #252d3d;
  --border: rgba(255,255,255,0.08);
  --text: #f0f3f8;
  --muted: #8b95a8;
  --accent: #6366f1;
  --accent-glow: rgba(99,102,241,0.35);
  --mint: #34d399;
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 14px;
  --tile-bg: #fef9ef;
  --tile-text: #1a1a1a;
  --header-h: 56px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-soft: #eef1f8;
  --surface: #ffffff;
  --surface-hover: #f0f3fa;
  --border: rgba(0,0,0,0.08);
  --text: #12151c;
  --muted: #5c6578;
  --tile-bg: #ffffff;
  --tile-text: #12151c;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}
body.menu-open { overflow: hidden; }

.is-embedded .game-shell,
.is-embedded .app-header .header-inner {
  max-width: none !important;
  width: 100% !important;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}
.is-embedded .game-panel {
  border-radius: 0;
  border-left: none;
  border-right: none;
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 9999;
  padding: 0.5rem 1rem; background: var(--accent); color: #fff;
}
.skip-link:focus { left: 0.5rem; top: 0.5rem; }

/* Header */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(52,211,153,0.08)), var(--bg-soft);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}
.header-inner {
  max-width: 720px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.65rem 1rem; gap: 0.75rem;
}
.header-left, .header-actions { display: flex; align-items: center; gap: 0.35rem; }
.brand { display: flex; align-items: center; gap: 0.55rem; min-width: 0; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
  background: linear-gradient(135deg, #6366f1, #34d399);
  display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 7px;
}
.brand-mark span { border-radius: 3px; background: rgba(255,255,255,0.9); }
.brand-name { margin: 0; font-size: 1rem; font-weight: 800; letter-spacing: -0.02em; white-space: nowrap; }
.brand-name em { font-style: normal; color: var(--mint); }
.puzzle-meta { font-size: 0.72rem; color: var(--muted); display: block; }
.mode-badge {
  font-size: 0.62rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 0.2rem 0.45rem; border-radius: 6px; background: var(--accent); color: #fff;
}

.icon-btn {
  width: 40px; height: 40px; border: none; border-radius: 10px; cursor: pointer;
  background: var(--surface); color: var(--text); display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.icon-btn:hover { background: var(--surface-hover); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.icon-btn--accent { background: var(--accent); color: #fff; }

.timer-pill {
  font-size: 0.78rem; font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 0.35rem 0.65rem; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
}

/* Game shell */
.game-shell {
  max-width: 720px; margin: 0 auto;
  padding: 1rem 1rem 2rem;
}
.game-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 1.25rem 1rem 1.5rem;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.game-topline {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; flex-wrap: wrap; gap: 0.5rem;
}
.game-topline h2 { margin: 0; font-size: 0.95rem; font-weight: 700; }

#solved-bar { display: flex; flex-direction: column; gap: 0.45rem; margin-bottom: 0.85rem; }
.solved-group {
  padding: 0.65rem 0.85rem; border-radius: 10px;
  background: var(--group-color);
  color: #1a1a1a; text-align: center;
  animation: slideIn 0.35s ease;
}
.solved-group .sg-cat { display: block; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.solved-group .sg-words { font-size: 0.85rem; font-weight: 600; }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

#word-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.45rem;
  margin-bottom: 1rem;
}
.word-tile {
  min-height: 52px; padding: 0.45rem 0.35rem;
  border: 2px solid transparent; border-radius: 10px;
  background: var(--tile-bg); color: var(--tile-text);
  font-size: clamp(0.62rem, 2.8vw, 0.82rem); font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.02em;
  cursor: pointer; transition: transform 0.12s, box-shadow 0.15s, background 0.15s;
  line-height: 1.15; word-break: break-word;
}
.word-tile:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,0.2); }
.word-tile.is-selected {
  background: #5c6bc0; color: #fff; border-color: #7986cb;
  box-shadow: 0 0 0 3px var(--accent-glow);
  transform: scale(1.02);
}

.mistakes-row {
  display: flex; align-items: center; justify-content: center; gap: 0.65rem;
  margin-bottom: 1rem; font-size: 0.82rem; color: var(--muted);
}
#mistakes-count { display: flex; gap: 0.35rem; }
.mistake-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--text); opacity: 0.85;
}
.mistake-dot.is-lost { background: var(--border); opacity: 0.35; }

.game-actions {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.5rem;
}
.btn {
  padding: 0.75rem 0.5rem; border-radius: 999px; font-weight: 800; font-size: 0.88rem;
  border: 2px solid var(--border); background: var(--surface-hover); color: var(--text);
  cursor: pointer; transition: transform 0.1s, opacity 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-primary:hover:not(:disabled) { opacity: 0.92; }
.btn-ghost { background: transparent; }

/* Menu */
.menu-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200;
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.menu-backdrop.is-open { opacity: 1; pointer-events: auto; }
.menu-panel {
  position: fixed; top: 0; left: 0; width: min(320px, 88vw); height: 100%;
  background: var(--bg-soft); border-right: 1px solid var(--border);
  z-index: 201; transform: translateX(-100%); transition: transform 0.28s ease;
  overflow-y: auto; padding: 1rem;
}
.menu-panel.is-open { transform: none; }
.menu-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; font-weight: 800; }
.menu-body h3 { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 1rem 0 0.5rem; }
.menu-list { list-style: none; padding: 0; margin: 0; }
.menu-list button {
  width: 100%; text-align: left; padding: 0.65rem 0.75rem; margin-bottom: 0.25rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  color: var(--text); font-weight: 600; cursor: pointer;
}
.menu-list button:hover { background: var(--surface-hover); }

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65); z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal-backdrop[hidden] { display: none !important; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem; max-width: 400px; width: 100%;
  text-align: center;
}
.modal h2 { margin: 0 0 0.75rem; }
.modal .btn { margin-top: 0.75rem; min-width: 140px; }

.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%) translateY(120%);
  background: var(--text); color: var(--bg); padding: 0.65rem 1.25rem;
  border-radius: 999px; font-weight: 700; font-size: 0.88rem; z-index: 400;
  transition: transform 0.28s ease; pointer-events: none;
}
.toast.is-visible { transform: translateX(-50%) translateY(0); }
.toast-warn { background: var(--warn); color: #1a1a1a; }
.toast-err { background: var(--danger); color: #fff; }
.toast-ok { background: var(--mint); color: #0a1a12; }

/* SEO / site content */
.site-content {
  max-width: 820px; margin: 0 auto; padding: 2rem 1.25rem 3rem;
}
.content-hero {
  text-align: center; margin-bottom: 2rem;
}
.content-hero h1 {
  font-size: clamp(1.75rem, 4vw, 2.35rem); margin: 0 0 0.5rem;
  background: linear-gradient(135deg, var(--text), var(--mint));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.rating-row { color: var(--warn); font-size: 0.9rem; margin-bottom: 1rem; }
.rating-row span { color: var(--muted); margin-left: 0.35rem; }

.seo-block {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem 1.5rem; margin-bottom: 1.5rem;
}
.seo-block h2 { font-size: 1.15rem; margin: 1.25rem 0 0.65rem; }
.seo-block h2:first-child { margin-top: 0; }
.seo-block p { color: var(--muted); margin: 0 0 0.85rem; }
.seo-block ul { color: var(--muted); padding-left: 1.25rem; }
.seo-block li { margin-bottom: 0.4rem; }

.tag-cloud { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.75rem; }
.tag {
  display: inline-block; padding: 0.35rem 0.75rem; border-radius: 999px;
  border: 1px solid var(--border); font-size: 0.78rem; font-weight: 600;
  color: var(--mint); text-decoration: none; transition: background 0.15s;
}
.tag:hover { background: var(--surface-hover); }

.discover-box {
  background: linear-gradient(135deg, rgba(99,102,241,0.12), rgba(52,211,153,0.08));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.25rem; margin: 1.25rem 0;
}
.discover-box h3 { margin: 0 0 0.65rem; font-size: 0.95rem; }
.discover-links { list-style: none; padding: 0; margin: 0; }
.discover-links a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.55rem 0; color: var(--text); text-decoration: none; font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.discover-links a:hover { color: var(--mint); }
.discover-links li:last-child a { border-bottom: none; }

#related-games-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem; margin-top: 1rem;
}
.game-card {
  display: flex; flex-direction: column; gap: 0.25rem;
  padding: 1rem; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); text-decoration: none; color: var(--text);
  transition: transform 0.15s, border-color 0.15s;
}
.game-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.game-card strong { font-size: 0.88rem; }
.game-card span { font-size: 0.75rem; color: var(--muted); }
.gc-rating { font-size: 0.68rem; color: var(--warn); font-weight: 800; }

.feedback-form label { display: block; font-size: 0.82rem; font-weight: 600; margin: 0.75rem 0 0.35rem; }
.feedback-form input, .feedback-form textarea {
  width: 100%; padding: 0.65rem 0.85rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-soft); color: var(--text);
  font: inherit;
}
.form-status { font-size: 0.85rem; margin-top: 0.75rem; min-height: 1.2em; }
.form-status.ok { color: var(--mint); }

.site-footer {
  text-align: center; padding: 2rem 1rem; border-top: 1px solid var(--border);
  color: var(--muted); font-size: 0.78rem;
}
.site-footer a { color: var(--mint); }

@media (max-width: 520px) {
  #word-grid { gap: 0.35rem; }
  .word-tile { min-height: 46px; font-size: 0.62rem; }
  .game-actions { grid-template-columns: 1fr; }
}

@media (max-width: 380px) {
  #word-grid { grid-template-columns: repeat(2, 1fr); }
}
