:root {
  --bg: #090c08;
  --panel: #11170f;
  --panel-2: #182016;
  --ink: #f4f7ed;
  --muted: #99a690;
  --green: #99b719;
  --green-bright: #c7eb2f;
  --yellow: #ffd817;
  --purple: #6f2b85;
  --cyan: #31cad5;
  --red: #ff4b4b;
  --line: rgba(178, 211, 48, .22);
  font-family: "DejaVu Sans Mono", "Liberation Mono", ui-monospace, monospace;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 80% 10%, rgba(111, 43, 133, .18), transparent 35%),
    linear-gradient(135deg, #080b07 0%, #10150d 58%, #090c08 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(153, 183, 25, .035) 1px, transparent 1px), linear-gradient(90deg, rgba(153, 183, 25, .035) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, black, transparent 80%);
}

.scanlines {
  position: fixed;
  z-index: 10;
  inset: 0;
  pointer-events: none;
  opacity: .07;
  background: repeating-linear-gradient(to bottom, transparent 0 3px, #fff 4px);
}

.shell { height: 100dvh; min-height: 100vh; padding: clamp(14px, 2vw, 28px); display: flex; flex-direction: column; }

.topbar {
  height: 68px;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.school-logo {
  width: 76px;
  max-height: 56px;
  object-fit: contain;
  filter: brightness(1.35) contrast(1.08);
}

.eyebrow, .step {
  color: var(--green-bright);
  text-transform: uppercase;
  letter-spacing: .14em;
  font-size: .78rem;
}

h1, h2, p { margin-top: 0; }
h1 { margin: 6px 0 0; font-size: clamp(1.25rem, 2vw, 2rem); letter-spacing: -.04em; }
h2 { margin: 10px 0 0; font-size: clamp(2rem, 5vw, 4.5rem); letter-spacing: -.065em; line-height: 1; }

.system-state { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; text-transform: uppercase; }
.lamp { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.lamp-green { background: var(--green-bright); box-shadow: 0 0 7px var(--green-bright), 0 0 18px var(--green); animation: pulse 1.8s infinite; }

.screen { display: none; flex: 1; min-height: 0; padding-top: 20px; overflow: auto; }
.screen.active { display: block; animation: enter .28s ease-out; }
#screen-code.active { display: grid; grid-template-columns: minmax(220px, 280px) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 24px; align-items: start; overflow: visible; }
.local-mode #screen-code.active { grid-template-columns: minmax(0, 1fr); }
.local-mode .user-switcher, .local-mode #user-grid { display: none; }
.local-mode-note { color: var(--muted); font-size: .8rem; margin: 8px 0 0; }
.topbar:has(#terminal-logo[hidden]) { grid-template-columns: 1fr auto auto; }
.screen-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 34px; }

.button {
  min-height: 54px;
  padding: 0 24px;
  border: 1px solid transparent;
  border-radius: 3px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, background .12s;
}
.button:hover { transform: translateY(-2px); }
.button:focus-visible, input:focus-visible, .user-card:focus-visible, .quick-add:focus-visible { outline: 3px solid var(--yellow); outline-offset: 4px; }
.button-accent { color: #111; background: var(--yellow); box-shadow: 5px 5px 0 var(--purple); }
.button-submit { width: 100%; background: var(--green-bright); color: #0c1008; display: flex; justify-content: space-between; align-items: center; font-size: 1rem; }
.button-quiet { color: var(--ink); background: transparent; border-color: #46503e; }
.button-danger { color: white; background: #9e2929; }

.user-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; max-height: calc(100vh - 315px); overflow: auto; padding: 4px; }
.user-card {
  position: relative;
  min-height: 116px;
  padding: 22px;
  overflow: hidden;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  align-items: center;
  gap: 15px;
  color: var(--ink);
  text-align: left;
  font: inherit;
  background: linear-gradient(135deg, rgba(31, 42, 26, .95), rgba(17, 23, 15, .95));
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}
.user-card::after { content: ""; position: absolute; top: 0; right: 0; width: 7px; height: 100%; background: var(--purple); }
.user-card:hover { border-color: var(--green); background: #1b2517; }
.user-card.solved::after { background: var(--green-bright); box-shadow: 0 0 18px var(--green); }
.user-lock {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  font-size: 2rem;
  background: rgba(255, 75, 75, .16);
  border: 2px solid rgba(255, 75, 75, .75);
  border-radius: 8px;
  box-shadow: 0 0 18px rgba(255, 75, 75, .16);
}
.user-card.solved .user-lock { background: rgba(199, 235, 47, .17); border-color: var(--green-bright); box-shadow: 0 0 22px rgba(199, 235, 47, .32); }
.user-content { min-width: 0; }
.user-name { display: block; font-size: 1.35rem; font-weight: 900; margin-bottom: 20px; overflow-wrap: anywhere; }
.user-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; text-transform: uppercase; }
.solved-label { color: var(--green-bright); }
.empty-state { padding: 30px; border: 1px dashed #3f4938; color: var(--muted); text-align: center; }

.user-switcher { min-width: 0; padding: 18px; border: 1px solid var(--line); background: rgba(13, 18, 11, .72); }
.switcher-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.switcher-heading .step, .switcher-heading strong { display: block; }
.switcher-heading strong { margin-top: 5px; font-size: 1rem; }
.quick-add { min-height: 40px; padding: 0 13px; color: #10140d; background: var(--yellow); border: 0; border-radius: 3px; font: inherit; font-size: .78rem; font-weight: 900; cursor: pointer; }
.quick-add:hover { box-shadow: 3px 3px 0 var(--purple); }
.quick-add:disabled { color: #65705d; background: #283023; cursor: not-allowed; box-shadow: none; }
.quick-user-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; max-height: calc(100vh - 210px); overflow-y: auto; padding: 2px; }
.quick-user {
  min-width: 0;
  min-height: 48px;
  padding: 8px 10px;
  overflow: hidden;
  color: var(--muted);
  background: #11170f;
  border: 1px solid #303a2b;
  border-radius: 3px;
  font: inherit;
  font-size: .78rem;
  font-weight: 800;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  cursor: pointer;
}
.quick-user-lock {
  display: grid;
  place-items: center;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  font-size: 1.15rem;
  background: rgba(255, 75, 75, .16);
  border: 1px solid rgba(255, 75, 75, .72);
  border-radius: 5px;
}
.quick-user.solved .quick-user-lock { background: rgba(199, 235, 47, .16); border-color: var(--green-bright); box-shadow: 0 0 12px rgba(199, 235, 47, .28); }
.quick-user.active .quick-user-lock { background: rgba(16, 20, 13, .16); border-color: #10140d; }
.quick-user-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.quick-user:hover { color: var(--ink); border-color: var(--green); }
.quick-user.active { color: #10140d; background: var(--green-bright); border-color: var(--green-bright); }
.quick-user.solved:not(.active) { color: var(--green-bright); border-color: rgba(199, 235, 47, .5); }
.code-panel { width: min(1100px, 100%); margin: 0 auto; max-height: 100%; min-height: 0; overflow-y: auto; padding: 5px 8px 16px; scrollbar-gutter: stable; }
.identity-strip { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; margin-bottom: 16px; padding: 10px 14px; color: var(--muted); border-left: 4px solid var(--purple); background: rgba(111, 43, 133, .11); }
.identity-strip strong { color: var(--ink); font-size: 1.15rem; }
#code-title { font-size: clamp(1.8rem, 3vw, 2.7rem); }
#code-form { margin-top: 16px; }
.answer-progress { margin: 10px 0 0; color: var(--muted); font-size: .9rem; }
.answer-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 14px 18px; margin-bottom: 16px; }
.answer-field { min-width: 0; }
.answer-label { display: block; margin-bottom: 6px; color: var(--ink); font-weight: 800; font-size: .9rem; overflow-wrap: anywhere; }
.answer-field .code-input { height: 54px; margin-bottom: 0; padding: 0 14px; font-size: clamp(1.1rem, 2vw, 1.6rem); letter-spacing: .04em; text-transform: none; }
.answer-field .feedback { min-height: 0; margin-top: 5px; padding: 6px 9px; font-size: .78rem; }
#code-form .button-submit { min-height: 46px; position: sticky; bottom: 0; z-index: 1; }
#feedback { min-height: 0; margin-top: 10px; padding: 10px 14px; font-size: .85rem; }
.answer-field.solved .code-input { border-color: var(--green-bright); color: var(--green-bright); }
.answer-field.solved .answer-label { color: var(--green-bright); }
.button:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.code-input, .modal input {
  width: 100%;
  border: 1px solid #46503e;
  border-radius: 3px;
  color: var(--ink);
  background: #090c08;
  font: inherit;
}
.code-input { height: 96px; margin-bottom: 14px; padding: 0 26px; font-size: clamp(1.7rem, 4vw, 3.3rem); font-weight: 900; letter-spacing: .12em; text-transform: uppercase; caret-color: var(--yellow); }
.code-input::placeholder { color: #3c4636; }
.feedback { min-height: 70px; margin-top: 18px; padding: 18px 20px; border: 1px solid transparent; font-weight: 800; display: none; }
.feedback.show { display: flex; align-items: center; }
.feedback.error { color: #ffd0d0; border-color: rgba(255,75,75,.45); background: rgba(255,75,75,.11); }
.feedback.success { color: #e9ffc0; border-color: rgba(199,235,47,.55); background: rgba(153,183,25,.14); box-shadow: 0 0 28px rgba(153,183,25,.12); }
.alarm { animation: alarm .42s ease; }

.success-overlay {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  background: radial-gradient(circle, rgba(56, 78, 25, .97), rgba(7, 12, 6, .99) 66%);
  transition: opacity .24s ease, visibility 0s linear .24s;
}
.success-overlay.show { opacity: 1; visibility: visible; transition-delay: 0s; pointer-events: auto; }
.success-content { position: relative; z-index: 3; text-align: center; transform: scale(.72); opacity: 0; }
.success-overlay.show .success-content { animation: success-in .62s cubic-bezier(.2, 1.2, .3, 1) .1s forwards; }
.success-kicker { display: block; margin-bottom: 22px; color: var(--yellow); font-size: clamp(.75rem, 1.4vw, 1rem); font-weight: 800; letter-spacing: .2em; text-transform: uppercase; }
.success-content strong { display: block; color: white; font-size: clamp(4rem, 12vw, 10rem); line-height: .9; letter-spacing: -.075em; text-shadow: 0 0 16px rgba(199, 235, 47, .65), 0 0 60px rgba(153, 183, 25, .45); }
.success-check { display: grid; place-items: center; width: 76px; height: 76px; margin: 34px auto 18px; color: #10140d; background: var(--green-bright); border-radius: 50%; font-size: 3rem; font-weight: 900; box-shadow: 0 0 20px var(--green-bright), 0 0 70px rgba(199, 235, 47, .65); }
.success-content p { color: #dff5a2; font-size: clamp(1rem, 2vw, 1.35rem); font-weight: 800; }
.success-rings, .success-rings i { position: absolute; inset: 50%; }
.success-rings i { width: 18vmin; height: 18vmin; margin: -9vmin; border: 2px solid rgba(199, 235, 47, .45); border-radius: 50%; opacity: 0; }
.success-overlay.show .success-rings i { animation: ring-out 1.9s ease-out infinite; }
.success-overlay.show .success-rings i:nth-child(2) { animation-delay: .38s; }
.success-overlay.show .success-rings i:nth-child(3) { animation-delay: .76s; }
.confetti-piece { position: absolute; top: -10vh; width: 9px; height: 22px; opacity: .9; animation: confetti-fall 2.8s linear forwards; }

.modal { width: min(480px, calc(100% - 32px)); padding: 0; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 4px; box-shadow: 0 24px 90px #000; }
.modal::backdrop { background: rgba(3, 5, 3, .86); backdrop-filter: blur(7px); }
.modal form { padding: 34px; }
.modal h2 { font-size: 2.2rem; margin-bottom: 28px; }
.modal input { height: 62px; padding: 0 18px; font-size: 1.2rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }
[hidden] { display: none !important; }
.admin-trigger { min-height: 40px; padding: 0 14px; font-size: .8rem; }
.admin-modal { width: min(1120px, calc(100% - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto; }
.admin-panel { padding: 20px; display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 16px 24px; }
.admin-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.admin-heading, .admin-message, #exit-terminal { grid-column: 1 / -1; }
.admin-heading h2 { margin-bottom: 0; font-size: clamp(1.6rem, 4vw, 2.2rem); }
.admin-section { margin: 0; padding: 0 !important; }
.admin-section h3 { margin: 0 0 8px; font-size: 1rem; }
.admin-section p { color: var(--muted); line-height: 1.4; font-size: .85rem; margin-bottom: 12px; }
.admin-settings { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.admin-settings > label { font-size: .85rem; font-weight: 800; margin-top: 4px; }
.admin-settings select, .admin-settings input[type="text"] { width: 100%; min-height: 38px; height: 38px; padding: 6px 9px; border: 1px solid #46503e; border-radius: 3px; font: inherit; font-size: .8rem; color: var(--ink); background: var(--bg); }
.settings-hint { font-size: .75rem; line-height: 1.4; color: var(--muted); margin: 0; }
.theme-colors { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; }
.theme-colors label { font-size: .72rem; display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.theme-colors input[type="color"] { width: 30px; height: 28px; padding: 0; flex-shrink: 0; cursor: pointer; }
.reset-section { border-top: 1px solid var(--line); padding-top: 12px !important; margin-top: 8px; }
.reset-section summary { cursor: pointer; color: var(--muted); font-size: .85rem; font-weight: 800; }
.reset-section p { margin-top: 12px; }
.reset-section .button { min-height: 42px; width: 100%; padding: 8px 12px; font-size: .8rem; }
#config-form .modal-actions { margin-top: 12px; }
#config-form .button, .admin-heading .button { min-height: 42px; padding: 0 16px; font-size: .85rem; }
#config-editor { width: 100%; resize: vertical; min-height: 180px; height: clamp(180px, calc(100dvh - 320px), 480px); padding: 12px; border: 1px solid #46503e; border-radius: 3px; background: #090c08; color: var(--ink); font: inherit; font-size: .85rem; line-height: 1.4; tab-size: 2; }
#config-editor:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
.admin-message { margin: 0; line-height: 1.4; color: var(--green-bright); font-size: .85rem; overflow-wrap: anywhere; }
.admin-message:empty { display: none; }
.admin-message.error { color: #ff8d8d; }
.form-error { min-height: 20px; margin: 10px 0 0; color: #ff8d8d; font-size: .85rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

@keyframes pulse { 50% { opacity: .42; box-shadow: 0 0 3px var(--green); } }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } }
@keyframes alarm { 25%, 75% { transform: translateX(-8px); } 50% { transform: translateX(8px); } }
@keyframes success-in { to { opacity: 1; transform: scale(1); } }
@keyframes ring-out { 0% { opacity: .8; transform: scale(.5); } 100% { opacity: 0; transform: scale(7); } }
@keyframes confetti-fall { to { transform: translate3d(var(--drift), 115vh, 0) rotate(780deg); } }

@media (max-width: 900px) {
  body { overflow: auto; }
  .shell { padding: 14px; height: auto; }
  .topbar { height: auto; grid-template-columns: 58px 1fr auto; gap: 12px; }
  .topbar:has(#terminal-logo[hidden]) { grid-template-columns: 1fr auto; }
  .school-logo { width: 58px; max-height: 46px; }
  .system-state { display: none; }
  .eyebrow { display: none; }
  .screen { height: auto; min-height: 0; flex: none; padding-top: 16px; overflow: visible; }
  #screen-code.active { display: flex; flex-direction: column; gap: 14px; }
  .user-switcher { width: 100%; padding: 12px; }
  .switcher-heading { margin-bottom: 8px; padding-bottom: 8px; }
  .quick-user-list { display: flex; max-height: 64px; overflow-x: auto; }
  .quick-user { flex: 0 0 auto; }
  .code-panel { max-height: none; overflow-y: visible; }
  .screen-heading { align-items: center; }
  .screen-heading h2 { font-size: 2.5rem; }
  .identity-strip { grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; font-size: .8rem; }
  .identity-strip strong { font-size: 1rem; overflow-wrap: anywhere; }
  .identity-strip > span:first-child { display: none; }
  .identity-strip { grid-template-columns: minmax(0, 1fr) auto; }
  .admin-panel { padding: 16px; grid-template-columns: 1fr; gap: 14px; }
  .admin-settings { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 8px 12px; }
  .admin-settings .settings-hint, .admin-settings .reset-section, .theme-colors { grid-column: 1 / -1; }
  .admin-settings > label { max-width: 145px; font-size: .78rem; }
  #config-editor { height: clamp(180px, 30dvh, 300px); }
  .admin-heading { align-items: start; }
  .admin-section .modal-actions { flex-wrap: wrap; }
}

.custom-theme {
  background: radial-gradient(circle at 80% 10%, color-mix(in srgb, var(--purple) 18%, transparent), transparent 35%), linear-gradient(135deg, var(--bg), var(--panel));
}
.custom-theme .user-card { background: linear-gradient(135deg, var(--panel), var(--bg)); }
.custom-theme .user-card:hover, .custom-theme .quick-user, .custom-theme .user-switcher { background: var(--panel); }
.custom-theme .code-input, .custom-theme .modal input, .custom-theme #config-editor { background: var(--bg); }
.custom-theme .identity-strip { background: color-mix(in srgb, var(--purple) 11%, transparent); }
.custom-theme .feedback.error, .custom-theme .user-lock, .custom-theme .quick-user-lock { color: var(--red); border-color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.custom-theme .feedback.success, .custom-theme .solved .user-lock, .custom-theme .solved .quick-user-lock { color: var(--green-bright); border-color: var(--green-bright); background: color-mix(in srgb, var(--green-bright) 14%, transparent); }
.custom-theme .button-danger { background: var(--red); color: var(--bg); }
.custom-theme .button-accent, .custom-theme .button-submit, .custom-theme .quick-add, .custom-theme .quick-user.active, .custom-theme .success-check { color: var(--bg); }
.custom-theme .success-overlay { background: radial-gradient(circle, var(--panel), var(--bg) 66%); }
.custom-theme .success-content strong { color: var(--ink); }
.custom-theme .success-content p { color: var(--green-bright); }
.custom-theme .admin-message.error, .custom-theme .form-error { color: var(--red); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
