:root {
  --bg: #050b07;
  --panel: rgba(10, 22, 15, 0.86);
  --line: rgba(80, 255, 130, 0.28);
  --green: #4dff88;
  --red: #ff4d5e;
  --text: #e3f7e8;
  --muted: #8fb09a;
  --vx: #ff5d73;
  --vy: #ffc94d;
  --vz: #4cc9f0;
  --vw: #b98cff;
  --mono: "JetBrains Mono", "DejaVu Sans Mono", "Consolas", monospace;
  --sans: "Inter", "Segoe UI", "DejaVu Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); overflow: hidden; }
#gl { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
.hidden { display: none !important; }

button {
  font: 600 16px var(--sans);
  color: var(--text);
  background: linear-gradient(180deg, rgba(60, 200, 110, 0.22), rgba(30, 120, 60, 0.18));
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 22px;
  cursor: pointer;
  transition: transform 0.12s, background 0.2s, box-shadow 0.2s, border-color 0.2s;
  backdrop-filter: blur(6px);
}
button:hover { transform: translateY(-1px); border-color: var(--green); box-shadow: 0 0 18px rgba(77, 255, 136, 0.25); }
button:active { transform: translateY(1px); }
button.ghost { background: transparent; }
button.danger:hover { border-color: var(--red); box-shadow: 0 0 18px rgba(255, 77, 94, 0.25); }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

kbd {
  display: inline-block; min-width: 1.7em; padding: 1px 6px; margin: 0 2px;
  font: 600 12px var(--mono); text-align: center; color: var(--text);
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.2);
  border-bottom-width: 3px; border-radius: 6px;
}

.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 10; }
.screen.dim { background: rgba(2, 8, 4, 0.55); backdrop-filter: blur(3px); }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 28px 32px;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.6), inset 0 0 40px rgba(77, 255, 136, 0.05);
  max-height: calc(100vh - 48px); overflow: auto;
}
.panel.wide { width: min(980px, 100%); }
.panel.narrow { width: min(420px, 100%); text-align: center; }
.panel h2 { margin: 0 0 18px; font-size: 28px; letter-spacing: 0.5px; }
.row { display: flex; gap: 12px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.muted { color: var(--muted); }

/* --- главное меню --- */
#screen-menu { justify-content: flex-start; padding-left: 7vw; }
.menu-card { width: min(440px, 92vw); padding: 28px; border-radius: 24px; background: linear-gradient(160deg, rgba(10, 30, 16, 0.82), rgba(5, 12, 8, 0.7)); border: 1px solid var(--line); backdrop-filter: blur(8px); }
.avatar { width: 96px; height: 96px; border-radius: 50%; border: 2px solid var(--green); box-shadow: 0 0 30px rgba(77, 255, 136, 0.45); display: block; }
.avatar.small { width: 64px; height: 64px; flex: none; }
h1 { font-size: 46px; line-height: 1; margin: 18px 0 10px; letter-spacing: -1px; }
h1 span { color: var(--green); text-shadow: 0 0 18px rgba(77, 255, 136, 0.6); margin: 0 6px; }
h1 em { font-style: normal; font-size: 22px; vertical-align: super; color: var(--muted); font-family: var(--mono); }
.tagline { color: var(--muted); margin: 0 0 22px; line-height: 1.45; }
.menu-buttons { display: flex; flex-direction: column; gap: 10px; }
.menu-buttons button { width: 100%; text-align: left; }
.panel.narrow .menu-buttons button { text-align: center; }
.foot { margin: 18px 0 0; font-size: 13px; color: var(--muted); }

/* --- уровни --- */
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.level-card { text-align: left; padding: 14px 16px; min-height: 108px; display: flex; flex-direction: column; gap: 6px; }
.level-card .num { font: 700 13px var(--mono); color: var(--green); }
.level-card .name { font-size: 17px; }
.level-card .meta { font: 13px var(--mono); color: var(--muted); margin-top: auto; }
.level-card .stars { font-size: 16px; }
.level-card.locked { filter: grayscale(1); }

.stars { color: #ffd34d; letter-spacing: 3px; text-shadow: 0 0 12px rgba(255, 211, 77, 0.5); }
.stars .off { color: rgba(255, 255, 255, 0.15); text-shadow: none; }
.win .stars { font-size: 42px; margin: -4px 0 6px; }
#win-text { font-size: 18px; margin: 6px 0; }
.record-flag { color: var(--green); font-weight: 700; margin: 10px 0 6px; }
#win-name { width: 100%; font: 16px var(--sans); padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.35); color: var(--text); margin-bottom: 14px; outline: none; }
#win-name:focus { border-color: var(--green); }
.win .menu-buttons { margin-top: 14px; }

/* --- рекорды --- */
table.records { width: 100%; border-collapse: collapse; font-size: 15px; }
table.records th, table.records td { padding: 8px 10px; border-bottom: 1px solid rgba(255, 255, 255, 0.07); text-align: left; }
table.records th { color: var(--muted); font-weight: 600; }
table.records td.mono { font-family: var(--mono); }
.records-mode { margin: 18px 0 6px; color: var(--green); }

/* --- справка --- */
.help-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.help-item { background: rgba(255, 255, 255, 0.04); border-radius: 12px; padding: 14px; line-height: 1.45; color: var(--muted); }
.help-item b { display: block; color: var(--text); margin-bottom: 4px; }
.keys { display: flex; flex-wrap: wrap; gap: 10px 26px; margin: 18px 0; color: var(--muted); }
.t { color: var(--green); font-weight: 700; }
.vx { color: var(--vx); font-weight: 700; } .vy { color: var(--vy); font-weight: 700; }
.vz { color: var(--vz); font-weight: 700; } .vw { color: var(--vw); font-weight: 700; }

.truth-tables { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.truth-tables table { border-collapse: collapse; width: 100%; font: 14px var(--mono); text-align: center; background: rgba(0, 0, 0, 0.25); border-radius: 10px; overflow: hidden; }
.truth-tables caption { font: 600 12px var(--sans); color: var(--muted); padding-bottom: 4px; }
.truth-tables th { background: rgba(77, 255, 136, 0.18); padding: 5px 4px; }
.truth-tables td { padding: 4px; border-top: 1px solid rgba(255, 255, 255, 0.06); }
.truth-tables td.one { color: var(--green); }
.truth-tables td.zero { color: var(--red); }

/* --- HUD --- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; font-family: var(--mono); }
#hud button { pointer-events: auto; }
.hud-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; backdrop-filter: blur(6px); }
#hud-vars { position: absolute; top: 16px; left: 16px; min-width: 250px; font-size: 16px; line-height: 1.65; }
#hud-vars .vars { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; border: 1px solid currentColor; background: rgba(0, 0, 0, 0.3); transition: box-shadow 0.25s, background 0.25s; }
.chip b { color: var(--text); }
.chip.on { box-shadow: 0 0 14px currentColor; background: rgba(255, 255, 255, 0.08); }
.chip.flash { animation: flash 0.5s; }
@keyframes flash { 0% { transform: scale(1.25); } 100% { transform: scale(1); } }
.func { display: flex; gap: 10px; align-items: baseline; white-space: nowrap; }
.func .fn { font-weight: 700; width: 2.2em; }
.func .expr { flex: 1; }
.func .val { font-size: 13px; padding: 0 8px; border-radius: 6px; }
.func.open .fn, .func.open .val { color: var(--green); }
.func.closed .fn, .func.closed .val { color: var(--red); }
.func.open .val { background: rgba(77, 255, 136, 0.12); }
.func.closed .val { background: rgba(255, 77, 94, 0.12); }
.func.near { text-shadow: 0 0 10px currentColor; }
#hud-title { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); font: 600 16px var(--sans); color: var(--muted); background: rgba(0, 0, 0, 0.35); padding: 6px 16px; border-radius: 999px; }
#hud-menu { position: absolute; top: 16px; right: 16px; }
#hud-funcs { position: absolute; bottom: 16px; left: 16px; }
#hud-tables { position: absolute; bottom: 74px; left: 16px; width: min(760px, calc(100vw - 32px)); padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
#hud-count { position: absolute; bottom: 20px; right: 20px; font-size: 20px; color: var(--green); text-shadow: 0 0 12px rgba(77, 255, 136, 0.5); }
#hud-prompt { position: absolute; bottom: 90px; left: 50%; transform: translateX(-50%); font: 600 17px var(--sans); background: var(--panel); border: 1px solid var(--line); padding: 10px 18px; border-radius: 12px; }
#hud-toast { position: absolute; top: 70px; left: 50%; transform: translateX(-50%); font: 600 15px var(--sans); background: rgba(10, 22, 15, 0.92); border: 1px solid var(--line); padding: 10px 18px; border-radius: 12px; max-width: 80vw; text-align: center; }

.tutor { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; width: min(720px, 100%); position: absolute; bottom: 7vh; }
.tutor p { flex: 1; min-width: 260px; margin: 0; font-size: 17px; line-height: 1.55; }
.tutor .row { width: 100%; justify-content: flex-end; margin-top: 0; }

#loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; font: 18px var(--mono); color: var(--green); background: var(--bg); z-index: 100; }

@media (max-width: 760px) {
  .help-grid { grid-template-columns: 1fr; }
  .truth-tables { grid-template-columns: repeat(3, 1fr); }
  #screen-menu { justify-content: center; padding-left: 24px; }
  #hud-vars { font-size: 13px; min-width: 0; }
}
