:root {
  color-scheme: dark;
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #0b0f14;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #7d8590;
  --accent: #2f81f7;
  --accent-2: #3fb950;
  --warn: #f0883e;
  --danger: #f85149;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

/* ---- loading overlay ---- */
#loading {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg); gap: 18px;
}
#loading.hidden { display: none; }
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 4px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { color: var(--muted); font-family: var(--mono); font-size: 14px; }

/* ---- layout ---- */
header {
  display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap;
  padding: 16px 22px; border-bottom: 1px solid var(--border); background: var(--panel);
}
header h1 { font-size: 17px; margin: 0; letter-spacing: .02em; }
header .level-badge {
  font-family: var(--mono); font-size: 13px; color: var(--accent);
  background: rgba(47,129,247,.12); border: 1px solid rgba(47,129,247,.3);
  padding: 2px 10px; border-radius: 999px;
}
header .title { color: var(--muted); font-size: 14px; }
header .progress { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--muted); }

main {
  display: grid; grid-template-columns: 360px 1fr; gap: 18px;
  padding: 18px 22px; align-items: start;
}
@media (max-width: 880px) { main { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px;
}
.panel h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--muted); margin: 0 0 12px;
}

/* ---- left column ---- */
.story {
  font-size: 16px; line-height: 1.55; color: var(--text); margin: 0 0 18px;
}
.qr-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.qr-wrap canvas {
  image-rendering: pixelated; background: #fff; border-radius: 6px;
  max-width: 100%; height: auto;
}
.qr-label { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.qr-pair { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; }
#right #fixed-wrap { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }

.code-entry { margin-top: 16px; }
.code-entry label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.code-row { display: flex; gap: 8px; align-items: stretch; }
.code-row input {
  flex: 1 1 auto; min-width: 0; font-family: var(--mono); font-size: 18px; letter-spacing: .12em;
  padding: 10px 12px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
}
.code-row button { flex: 0 0 auto; white-space: nowrap; }
.code-row input:focus { outline: none; border-color: var(--accent); }
.feedback { margin-top: 10px; font-family: var(--mono); font-size: 13px; min-height: 18px; }
.feedback.ok { color: var(--accent-2); }
.feedback.bad { color: var(--danger); }
.shake { animation: shake .4s; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%,60%{transform:translateX(-6px)} 40%,80%{transform:translateX(6px)} }

/* ---- buttons ---- */
button {
  font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 16px;
  background: var(--panel-2); color: var(--text); transition: background .12s, border-color .12s;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #4493f8; }
button.success { background: var(--accent-2); border-color: var(--accent-2); color: #04260f; }

/* ---- editor ---- */
.pg-body { position: relative; }
.rt-overlay {
  position: absolute; inset: 0; z-index: 5; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(13, 17, 23, .88); backdrop-filter: blur(2px);
  color: var(--muted); font-family: var(--mono); font-size: 13px; text-align: center; padding: 16px;
}
.rt-overlay.hidden { display: none; }

/* ---- language tabs (sit directly on top of the editor) ---- */
.tabs { display: flex; gap: 4px; margin-bottom: 0; padding-left: 14px; flex-wrap: wrap; position: relative; z-index: 6; }
.tab {
  font-family: var(--mono); font-size: 12.5px; font-weight: 600;
  padding: 6px 14px; border-radius: 8px 8px 0 0; margin-bottom: -1px;
  background: var(--bg); color: var(--muted); border: 1px solid var(--border); /* inactive tabs keep a bottom line */
}
.tab:hover { color: var(--text); }
/* active tab opens into the editor: its bottom border matches the editor bg */
.tab.active { color: var(--text); background: var(--panel-2); border-bottom-color: var(--panel-2); }

.editor-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.editor-head .spacer { flex: 1; }
.editor-wrap {
  display: flex; align-items: stretch;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.editor-wrap:focus-within { border-color: var(--accent); }
.gutter {
  font-family: var(--mono); font-size: 13px; line-height: 1.55;
  padding: 12px 8px 12px 12px; margin: 0; text-align: right; white-space: pre;
  color: var(--muted); background: var(--panel); user-select: none; overflow: hidden;
  min-width: 2.4em;
}
#code {
  flex: 1; min-width: 0; min-height: 320px; resize: vertical; tab-size: 4;
  font-family: var(--mono); font-size: 13px; line-height: 1.55;
  padding: 12px; background: transparent; color: var(--text);
  border: 0; border-radius: 0; white-space: pre; outline: none;
}
.console {
  margin-top: 12px; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap;
  background: #05080c; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; max-height: 200px; overflow: auto; color: #c9d1d9;
}
.console .err { color: var(--danger); }
.console:empty::before { content: "Output appears here after you run."; color: var(--muted); }

details.help { margin-top: 12px; }
details.help summary { cursor: pointer; color: var(--accent); font-size: 13px; }
details.help .help-body { font-size: 13px; color: var(--muted); margin-top: 8px; }
details.help code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-family: var(--mono); }

.hidden { display: none !important; }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0; }

/* ---- "Access Granted" popup on a correct code ---- */
.granted {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: rgba(3, 10, 6, .72); backdrop-filter: blur(2px);
  animation: granted-fade .25s ease;
}
.granted-box {
  font-family: var(--mono); font-weight: 800; font-size: clamp(26px, 7vw, 54px);
  letter-spacing: .08em; text-transform: uppercase; color: var(--accent-2);
  padding: 24px 44px; border: 3px solid var(--accent-2); border-radius: 16px;
  background: rgba(63, 185, 80, .1);
  box-shadow: 0 0 50px rgba(63, 185, 80, .45), inset 0 0 32px rgba(63, 185, 80, .15);
  text-shadow: 0 0 18px rgba(63, 185, 80, .6);
  animation: granted-pop .4s cubic-bezier(.2, 1.5, .4, 1);
}
@keyframes granted-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes granted-pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---- message screen (single centered column) ---- */
body.is-message main { grid-template-columns: 1fr; max-width: 640px; margin: 0 auto; }
body.is-message .story {
  font-size: 20px; text-align: center; line-height: 1.65;
  border-left: 0; background: none; padding: 8px 0;
}
body.is-message .qr-wrap { margin-top: 8px; }
body.is-message .qr-label { display: none; } /* not a "broken QR" on the end screens */
