:root {
  --bg: #090d15;
  --bg-soft: #111827;
  --card: #101a2a;
  --line: #223049;
  --text: #e5edf8;
  --muted: #8ca1be;
  --accent: #5eead4;
  --accent-2: #60a5fa;
  --warn: #ef4444;
  --ok: #34d399;
  --slot: #172437;
  --slot-active: #284465;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 15%, #1a2640, transparent 45%),
              radial-gradient(circle at 80% 85%, #16273e, transparent 45%),
              var(--bg);
  overflow-x: hidden;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(rgba(136, 180, 255, 0.05) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(136, 180, 255, 0.05) 1px, transparent 1px);
  background-size: 32px 32px;
  pointer-events: none;
}

.bg-glow {
  position: fixed;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.18;
  pointer-events: none;
  animation: drift 12s ease-in-out infinite alternate;
}
.bg-glow-a { background: #2dd4bf; top: -120px; left: -70px; }
.bg-glow-b { background: #3b82f6; right: -80px; bottom: -160px; animation-duration: 14s; }

@keyframes drift {
  from { transform: translateY(0) translateX(0) scale(1); }
  to { transform: translateY(26px) translateX(-18px) scale(1.05); }
}

.app {
  width: min(1100px, 94vw);
  margin: 24px auto 40px;
  display: grid;
  gap: 16px;
  position: relative;
  z-index: 1;
}

.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01)), var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  backdrop-filter: blur(8px);
}

.topbar {
  padding: 18px 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
h1 { margin: 0 0 6px; font-size: clamp(1.5rem, 2.4vw, 2.2rem); }
h2 { margin: 0 0 8px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 0.9rem; }

.stats { display: flex; gap: 10px; }
.stat {
  background: rgba(11, 21, 34, 0.9);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  min-width: 92px;
}
.stat span { display: block; font-size: 0.78rem; color: var(--muted); }
.stat strong { font-size: 1.24rem; }

.controls {
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  border: 1px solid var(--line);
  color: var(--text);
  background: #122238;
  border-radius: 10px;
  padding: 10px 14px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}
.btn:hover { transform: translateY(-1px); background: #172c47; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.accent { background: linear-gradient(135deg, #0f766e, #2563eb); border-color: #35618f; }
.btn.ghost { background: transparent; }
.hidden { display: none !important; }

.boardWrap { padding: 16px; }
.board {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-family: "JetBrains Mono", monospace;
}

.slot {
  width: 34px;
  height: 46px;
  border-radius: 8px;
  border: 1px solid #2a3d5d;
  background: var(--slot);
  display: grid;
  place-items: center;
  position: relative;
  transition: all 120ms ease;
  color: var(--text);
}
.slot .cipher {
  position: absolute;
  top: 4px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.62rem;
  color: #7f96b9;
  letter-spacing: 0.03em;
}
.slot .guess {
  font-size: 1.12rem;
  font-weight: 600;
  margin-top: 9px;
  color: #f3f8ff;
}
.slot.active { border-color: #60a5fa; box-shadow: 0 0 0 1px #60a5fa inset; background: var(--slot-active); }
.slot.match { outline: 1px solid #2dd4bf; }
.slot.locked { background: #163827; border-color: #2f7d5b; }
.slot.correct { color: var(--ok); }
.slot.error { color: var(--warn); border-color: #7f1d1d; }
.slot.conflict { box-shadow: 0 0 0 2px rgba(239,68,68,0.5) inset; }
.slot-divider { width: 16px; height: 1px; }
.word-group {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  margin-right: 16px;
}

.analysis { padding: 14px 16px 16px; }
.analysisHead { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.histogram {
  margin-top: 10px;
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
  padding-right: 2px;
}
.hist-row {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  align-items: center;
  font-family: "JetBrains Mono", monospace;
}
.bars {
  height: 14px;
  display: grid;
  grid-template-columns: 1fr;
  border-radius: 7px;
  overflow: hidden;
  background: #0b1422;
  border: 1px solid #263653;
  position: relative;
}
.bar {
  position: absolute;
  height: 4px;
  left: 0;
  border-radius: 2px;
}
.bar.eng { top: 1px; background: #64748b; }
.bar.msg { top: 5px; background: #60a5fa; }
.bar.gss { top: 9px; background: #5eead4; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 14, 0.72);
  display: grid;
  place-items: center;
  z-index: 3;
}
.overlay-card {
  width: min(420px, 90vw);
  background: #0e1b2d;
  border: 1px solid #28405f;
  border-radius: 14px;
  padding: 20px;
  animation: pop 160ms ease;
}
.overlay-card.wide { width: min(620px, 92vw); }
@keyframes pop {
  from { transform: scale(0.96); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.toggles { display: grid; gap: 12px; margin: 14px 0 18px; }
.toggles label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #111f32;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

@media (max-width: 700px) {
  .slot { width: 30px; height: 42px; }
  .controls .btn { flex: 1 1 calc(50% - 8px); }
  .stats { width: 100%; }
  .topbar { flex-direction: column; }
}
