:root {
  --bg: #0e1726;
  --panel: rgba(255, 255, 255, 0.08);
  --panel-strong: rgba(255, 255, 255, 0.13);
  --text: #f7fbff;
  --muted: #aebbd0;
  --line: rgba(255, 255, 255, 0.16);
  --accent: #7dd3fc;
  --good: #86efac;
  --bad: #fca5a5;
  --warn: #fde68a;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(125, 211, 252, 0.22), transparent 34rem),
    radial-gradient(circle at bottom right, rgba(167, 139, 250, 0.18), transparent 34rem),
    var(--bg);
}

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

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

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.13em;
  font-size: 0.74rem;
  font-weight: 800;
}

h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 0.95;
  letter-spacing: -0.06em;
}
h2 { letter-spacing: -0.025em; }
.lead {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.server-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 10px 13px;
  border-radius: 999px;
  color: var(--muted);
  box-shadow: var(--shadow);
}
.server-pill.online { color: var(--good); }
.server-pill.offline { color: var(--warn); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  align-items: start;
}

.panel {
  background: linear-gradient(180deg, var(--panel-strong), var(--panel));
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.game-panel {
  min-height: 680px;
  padding: clamp(18px, 3vw, 32px);
  position: relative;
  overflow: hidden;
}
.game-panel::before {
  content: "";
  position: absolute;
  inset: -120px auto auto -120px;
  width: 280px;
  height: 280px;
  background: rgba(125, 211, 252, 0.12);
  border-radius: 999px;
  filter: blur(8px);
  pointer-events: none;
}

.side-panel {
  padding: 22px;
  display: grid;
  gap: 22px;
}
.side-panel section:not(:last-child) {
  border-bottom: 1px solid var(--line);
  padding-bottom: 20px;
}
.side-panel p, .muted { color: var(--muted); line-height: 1.55; }

.hidden { display: none !important; }

.start-screen, .end-screen {
  min-height: 610px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  max-width: 760px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}
.start-screen h2, .end-screen h2 {
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1;
  margin-bottom: 14px;
}
.start-screen p, .end-screen p {
  color: var(--muted);
  font-size: 1.07rem;
  line-height: 1.58;
}

.badge {
  display: inline-flex;
  border: 1px solid rgba(125, 211, 252, 0.35);
  background: rgba(125, 211, 252, 0.12);
  color: #d6f5ff;
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 800;
  margin-bottom: 18px;
}

.rules-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}
.rules-grid div {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.08);
  border-radius: 18px;
  padding: 16px;
}
.rules-grid strong {
  display: block;
  font-size: 2rem;
  line-height: 1;
}
.rules-grid span {
  display: block;
  color: var(--muted);
  margin-top: 8px;
}

.controls-help { margin-bottom: 22px; }

.primary-btn, .secondary-btn, .tiny-btn {
  border: 0;
  border-radius: 999px;
  font-weight: 900;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.primary-btn {
  background: linear-gradient(135deg, #7dd3fc, #c4b5fd);
  color: #06111f;
  padding: 14px 22px;
  box-shadow: 0 14px 35px rgba(125, 211, 252, 0.25);
}
.secondary-btn {
  background: rgba(255,255,255,0.1);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 14px 22px;
}
.tiny-btn {
  padding: 8px 11px;
  background: rgba(255,255,255,0.12);
  color: var(--text);
  border: 1px solid var(--line);
}
.primary-btn:hover, .secondary-btn:hover, .tiny-btn:hover { transform: translateY(-1px); }

.game-screen {
  position: relative;
  z-index: 1;
  min-height: 610px;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 18px;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.hud div, .result-grid div {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.08);
  border-radius: 18px;
  padding: 15px;
}
.hud span, .result-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 7px;
}
.hud strong, .result-grid strong {
  display: block;
  font-size: 1.7rem;
}

.inbox-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 0;
}
.mail-card {
  width: min(720px, 100%);
  min-height: 280px;
  border-radius: 28px;
  padding: clamp(20px, 4vw, 34px);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(226, 240, 255, 0.92));
  color: #0d1828;
  box-shadow: 0 26px 75px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255,255,255,0.65);
  transform-origin: center;
  animation: cardIn 0.18s ease-out;
}
.mail-card.correct { animation: correctPulse 0.22s ease-out; }
.mail-card.wrong { animation: wrongShake 0.25s ease-in-out; }
.mail-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #52637a;
  font-size: 0.9rem;
  font-weight: 800;
  margin-bottom: 18px;
}
.mail-card h2 {
  font-size: clamp(1.6rem, 3vw, 2.45rem);
  line-height: 1.05;
  margin-bottom: 16px;
}
.mail-card p {
  color: #314258;
  font-size: 1.15rem;
  line-height: 1.55;
  margin-bottom: 16px;
}
.mail-hint {
  color: #52637a;
  background: rgba(14, 23, 38, 0.07);
  padding: 10px 12px;
  border-radius: 14px;
  font-weight: 700;
}

.folders {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.folder {
  min-height: 128px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.09);
  color: var(--text);
  border-radius: 20px;
  padding: 15px;
  text-align: left;
}
.folder.selected {
  outline: 3px solid rgba(125, 211, 252, 0.65);
  background: rgba(125, 211, 252, 0.15);
}
.folder kbd {
  display: inline-flex;
  width: 28px;
  height: 28px;
  justify-content: center;
  align-items: center;
  background: rgba(0,0,0,0.24);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px;
  margin-bottom: 10px;
}
.folder strong, .folder span { display: block; }
.folder strong { font-size: 1.08rem; margin-bottom: 5px; }
.folder span { color: var(--muted); font-size: 0.9rem; line-height: 1.35; }
.folder-urgent { border-color: rgba(252, 165, 165, 0.45); }
.folder-important { border-color: rgba(253, 230, 138, 0.45); }
.folder-forward { border-color: rgba(196, 181, 253, 0.45); }
.folder-noise { border-color: rgba(174, 187, 208, 0.45); }

.feedback {
  min-height: 52px;
  display: flex;
  align-items: center;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.07);
  padding: 12px 16px;
  color: var(--muted);
  font-weight: 800;
}
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

.result-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 14px 0 20px;
}
.name-label {
  color: var(--muted);
  font-weight: 800;
  margin-bottom: 8px;
}
#playerName {
  width: min(460px, 100%);
  background: rgba(255,255,255,0.92);
  border: 0;
  color: #0d1828;
  border-radius: 16px;
  padding: 14px 15px;
  margin-bottom: 14px;
  outline: none;
}
#playerName:focus { box-shadow: 0 0 0 4px rgba(125, 211, 252, 0.35); }
.end-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.save-note { margin-top: 14px; }

.leaderboard-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}
.leaderboard-head h2 { margin: 0; }
.leaderboard {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.leaderboard li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.07);
  padding: 11px 12px;
  border-radius: 14px;
  color: var(--muted);
}
.leaderboard strong { color: var(--text); }
.leaderboard small { color: var(--muted); display: block; margin-top: 3px; }

.meta-box dl {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 8px 12px;
  margin: 0;
}
.meta-box dt { color: var(--muted); font-weight: 800; }
.meta-box dd { margin: 0; }
code {
  background: rgba(255,255,255,0.1);
  padding: 2px 6px;
  border-radius: 7px;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes correctPulse {
  0% { transform: scale(1); }
  45% { transform: scale(1.025); }
  100% { transform: scale(1); }
}
@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

@media (max-width: 950px) {
  .layout { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
  .server-pill { align-self: flex-start; }
}
@media (max-width: 720px) {
  .rules-grid, .hud, .folders, .result-grid { grid-template-columns: 1fr 1fr; }
  .game-panel { min-height: auto; }
  .start-screen, .end-screen, .game-screen { min-height: auto; }
}
@media (max-width: 470px) {
  .app-shell { width: min(100% - 18px, 1180px); padding: 10px 0; }
  .rules-grid, .hud, .folders, .result-grid { grid-template-columns: 1fr; }
  .mail-meta { flex-direction: column; }
}
