:root {
  --bg-1: #030712;
  --bg-2: #111827;
  --panel: rgba(17, 24, 39, 0.88);
  --panel-border: rgba(148, 163, 184, 0.14);
  --tile: rgba(30, 41, 59, 0.72);
  --tile-border: #334155;
  --tile-filled: #64748b;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #8b5cf6;
  --green: #22c55e;
  --yellow: #facc15;
  --gray: #475569;
  --pink: #fb7185;
  --orange: #fb923c;
  --red: #ef4444;
  --gold: #fbbf24;
  --key-default: #334155;
  --key-absent: #0f172a;
  --key-absent-text: #cbd5e1;
  --shadow: 0 24px 90px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 20%, rgba(56, 189, 248, 0.18), transparent 24%),
    radial-gradient(circle at 85% 0%, rgba(139, 92, 246, 0.18), transparent 30%),
    linear-gradient(180deg, var(--bg-1), var(--bg-2));
}

body { padding: 20px; }

.shell {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 18px;
  align-items: start;
  position: relative;
  z-index: 1;
}

.app, .sidebar {
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.app { padding: 24px; position: relative; overflow: hidden; }
.sidebar { padding: 20px; position: sticky; top: 20px; }

.app.legendary-active::before,
.app.loss-active::before {
  content: "";
  position: absolute;
  inset: -40%;
  pointer-events: none;
  opacity: 0;
}

.app.legendary-active::before {
  background: conic-gradient(from 180deg, rgba(251,191,36,0), rgba(251,191,36,0.18), rgba(255,255,255,0.06), rgba(251,191,36,0));
  animation: halo-spin 2.2s linear infinite;
  opacity: 1;
}

.app.loss-active::before {
  background: radial-gradient(circle at center, rgba(239,68,68,0.14), transparent 55%);
  opacity: 1;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.brand { display: flex; align-items: center; gap: 14px; }

.logo {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 1.2rem;
  font-weight: 900;
  color: white;
  box-shadow: 0 16px 40px rgba(56, 189, 248, 0.28);
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  line-height: 1;
  letter-spacing: 0.03em;
}

.subtitle {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.97rem;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  border: 1px solid rgba(56, 189, 248, 0.26);
  color: var(--accent);
  padding: 10px 13px;
  border-radius: 999px;
  font-size: 0.83rem;
  font-weight: 700;
  background: rgba(15, 23, 42, 0.55);
  white-space: nowrap;
  text-decoration: none;
}

.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 16px 18px;
  margin-bottom: 18px;
  border-radius: 22px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.78), rgba(30, 41, 59, 0.72));
}

.hero strong {
  display: block;
  font-size: 1.05rem;
  margin-bottom: 6px;
}

.hero span {
  color: var(--muted);
  font-size: 0.94rem;
}

.status {
  min-height: 26px;
  margin-bottom: 14px;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.01em;
}
.status.error { color: #fca5a5; }
.status.success { color: #86efac; }

.hint-box {
  margin: 0 auto 16px;
  width: min(100%, 420px);
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(250, 204, 21, 0.12);
  border: 1px solid rgba(250, 204, 21, 0.28);
  color: #fde68a;
  font-weight: 800;
  line-height: 1.4;
  box-shadow: 0 10px 30px rgba(250, 204, 21, 0.08);
}

.hint-box.hidden {
  display: none;
}

.board-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 22px;
  position: relative;
  z-index: 1;
}

.board {
  width: min(100%, 420px);
  display: grid;
  gap: 10px;
  transform-origin: center;
}

.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.tile {
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  border: 2px solid var(--tile-border);
  background: var(--tile);
  display: grid;
  place-items: center;
  font-size: clamp(1.25rem, 4vw, 2rem);
  font-weight: 900;
  text-transform: uppercase;
  user-select: none;
  transition: transform 0.15s ease, background 0.16s ease, border-color 0.16s ease, box-shadow 0.2s ease, filter 0.2s ease, opacity 0.2s ease;
  transform-style: preserve-3d;
}

.tile.filled {
  border-color: var(--tile-filled);
  transform: translateY(-1px);
}

.tile.pop { animation: pop 0.13s ease; }
.tile.flip { animation: flip 0.55s ease; }
.tile.correct { background: var(--green); border-color: var(--green); color: white; }
.tile.present { background: var(--yellow); border-color: var(--yellow); color: #111827; }
.tile.absent { background: var(--gray); border-color: var(--gray); color: white; }
.tile.win { animation: win-pop 0.5s ease, win-glow 1s ease; }
.tile.legendary { box-shadow: 0 0 30px rgba(251,191,36,0.55), 0 0 70px rgba(251,191,36,0.16); }
.tile.loss-hit { box-shadow: 0 0 24px rgba(239,68,68,0.4); }

.keyboard {
  display: grid;
  gap: 10px;
  width: 100%;
  position: relative;
  z-index: 1;
}

.key-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  width: 100%;
}

.key {
  flex: 1 1 0;
  min-width: 0;
  border: 0;
  border-radius: 13px;
  background: var(--key-default);
  color: white;
  font-weight: 800;
  height: 54px;
  padding: 0 10px;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.16s ease, background 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease;
}

.key:hover { transform: translateY(-1px); filter: brightness(1.06); }
.key:active { transform: translateY(0); }
.key.wide { flex: 1.6 1 0; font-size: 0.9rem; }
.key.correct { background: var(--green); }
.key.present { background: var(--yellow); color: #111827; }
.key.absent {
  background: var(--key-absent);
  color: var(--key-absent-text);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
}
.key:disabled {
  cursor: default;
  opacity: 0.55;
  filter: none;
  transform: none;
}

.actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 18px;
  position: relative;
  z-index: 1;
}

.action-btn {
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(15, 23, 42, 0.85);
  color: var(--text);
  padding: 12px 15px;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 0.08s ease, border-color 0.16s ease, background 0.16s ease;
}

.action-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(56, 189, 248, 0.35);
}

.action-btn.secondary {
  width: 100%;
  background: rgba(30, 41, 59, 0.65);
}

.sidebar h2 {
  margin: 0 0 14px 0;
  font-size: 1rem;
  letter-spacing: 0.02em;
}

.meta-grid {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.meta-card, .stat-card {
  padding: 14px;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.1);
}

.meta-card strong { display: block; margin-bottom: 6px; font-size: 1rem; }
.meta-card span, .meta-card div, .sidebar p, .sidebar li {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.stat-card { display: flex; flex-direction: column; gap: 6px; }
.stat-card span {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat-card strong { font-size: 1.25rem; }
.stat-card-wide { grid-column: 1 / -1; }
.sidebar-actions { margin-bottom: 18px; }

.legend {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.dot { width: 15px; height: 15px; border-radius: 5px; flex: 0 0 15px; }
.dot.correct { background: var(--green); }
.dot.present { background: var(--yellow); }
.dot.absent { background: var(--gray); }

.share-box {
  margin-top: 12px;
  margin-bottom: 18px;
  padding: 14px;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.1);
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  min-height: 90px;
  font-size: 0.92rem;
}

.end-screen {
  margin-top: 18px;
  padding: 18px;
  border-radius: 24px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.88));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.03), 0 18px 60px rgba(0,0,0,0.22);
  position: relative;
  overflow: hidden;
}
.end-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(120deg, transparent, rgba(255,255,255,0.06), transparent);
  opacity: 0;
}
.end-screen.hidden { display: none; }
.end-screen.win {
  border-color: rgba(34, 197, 94, 0.38);
  background: linear-gradient(135deg, rgba(6, 78, 59, 0.64), rgba(15, 23, 42, 0.94));
}
.end-screen.win.legendary {
  border-color: rgba(251,191,36,0.5);
  background: linear-gradient(135deg, rgba(120, 53, 15, 0.72), rgba(6, 78, 59, 0.58), rgba(15, 23, 42, 0.95));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04), 0 22px 90px rgba(251,191,36,0.18);
}
.end-screen.loss {
  border-color: rgba(251, 113, 133, 0.34);
  background: linear-gradient(135deg, rgba(76, 5, 25, 0.64), rgba(15, 23, 42, 0.94));
}
.end-screen.locked {
  border-color: rgba(56, 189, 248, 0.26);
}
.end-screen-badge {
  display: inline-block;
  margin-bottom: 10px;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: rgba(56, 189, 248, 0.14);
  color: var(--accent);
}
.end-screen.win .end-screen-badge {
  background: rgba(34,197,94,0.16);
  color: #bbf7d0;
}
.end-screen.win.legendary .end-screen-badge {
  background: rgba(251,191,36,0.2);
  color: #fde68a;
  box-shadow: 0 0 24px rgba(251,191,36,0.18);
}
.end-screen.loss .end-screen-badge {
  background: rgba(251,113,133,0.16);
  color: #fecdd3;
}
.end-screen h2 {
  margin: 0 0 8px 0;
  font-size: 1.25rem;
  position: relative;
  z-index: 1;
}
.end-screen p {
  margin: 0;
  color: var(--muted);
  position: relative;
  z-index: 1;
}
.end-screen-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
  position: relative;
  z-index: 1;
}
.end-chip {
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.45);
  border: 1px solid rgba(148, 163, 184, 0.14);
  font-weight: 700;
  color: var(--text);
}

.footer {
  margin-top: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  position: relative;
  z-index: 1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.18);
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  font-weight: 700;
  z-index: 40;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.confetti-canvas,
.fx-stage,
.fx-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.confetti-canvas { z-index: 20; }
.fx-stage { z-index: 21; overflow: hidden; }

.fx-particle,
.fx-shard,
.fx-ring-burst,
.fx-badge-pop {
  position: absolute;
  pointer-events: none;
  will-change: transform, opacity;
}

.fx-particle {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.95), var(--particle-color, rgba(251,191,36,0.9)) 65%);
  box-shadow: 0 0 14px var(--particle-glow, rgba(251,191,36,0.5));
}

.fx-shard {
  width: 18px;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255,255,255,0.15), var(--particle-color, rgba(239,68,68,0.92)), rgba(255,255,255,0.15));
  box-shadow: 0 0 16px var(--particle-glow, rgba(239,68,68,0.45));
}

.fx-ring-burst {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 2px solid var(--particle-color, rgba(251,191,36,0.9));
  box-shadow: 0 0 18px var(--particle-glow, rgba(251,191,36,0.45));
}

.fx-badge-pop {
  min-width: 140px;
  padding: 14px 18px;
  border-radius: 999px;
  text-align: center;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff8db;
  background: linear-gradient(135deg, rgba(251,191,36,0.95), rgba(249,115,22,0.95));
  box-shadow: 0 12px 38px rgba(251,191,36,0.34), inset 0 0 0 1px rgba(255,255,255,0.18);
  backdrop-filter: blur(6px);
}

.fx-flash {
  opacity: 0;
  z-index: 18;
  background:
    radial-gradient(circle at center, rgba(255,255,255,0.16), transparent 40%),
    radial-gradient(circle at center, rgba(239,68,68,0.24), transparent 70%);
}

.board.dramatic-loss .tile {
  box-shadow: 0 0 0 rgba(239,68,68,0);
}

.board.dramatic-win .tile.correct {
  box-shadow: 0 0 24px rgba(34,197,94,0.2);
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

@keyframes win-pop {
  0%   { transform: scale(1); }
  25%  { transform: scale(1.12); }
  50%  { transform: scale(0.95); }
  75%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@keyframes win-glow {
  0%   { box-shadow: 0 0 0 rgba(34, 197, 94, 0); }
  50%  { box-shadow: 0 0 22px rgba(34, 197, 94, 0.65); }
  100% { box-shadow: 0 0 0 rgba(34, 197, 94, 0); }
}

@keyframes loss-flash {
  0% { opacity: 0; }
  18% { opacity: 0.9; }
  100% { opacity: 0; }
}

@keyframes halo-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; }
}

@media (max-width: 640px) {
  body { padding: 12px; }

  .hint-box {
    width: min(100%, 420px);
    font-size: 0.92rem;
  }

  .app, .sidebar {
    border-radius: 22px;
    padding: 16px;
  }

  .topbar, .hero {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topbar { gap: 12px; }
  .top-actions { justify-content: flex-start; }

  .keyboard { gap: 8px; }
  .key-row { gap: 4px; }

  .key {
    height: 46px;
    padding: 0 6px;
    font-size: 0.82rem;
    border-radius: 11px;
  }

  .key.wide {
    flex: 1.8 1 0;
    font-size: 0.72rem;
  }
}

@media (max-width: 420px) {
  .key-row { gap: 3px; }

  .key {
    height: 44px;
    font-size: 0.76rem;
    padding: 0 4px;
  }

  .key.wide {
    flex: 1.9 1 0;
    font-size: 0.66rem;
  }
}
