:root {
  --bg: #1a1a1a;
  --bg-2: #222;
  --panel: #262626;
  --border: #3e3e3e;
  --text: #eff1f6;
  --muted: #9aa0a6;
  --accent: #2cbb5d;
  --accent-text: #0b140e;
  --easy: #00b8a3;
  --medium: #ffc01e;
  --hard: #ff375f;
  --danger: #ff375f;
  --ok: #2cbb5d;
  --code-bg: #2a2a2a;
  --mono: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --radius: 3px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.page-center {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.card h1 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 600;
}

.sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 11px;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: #6b6b6b;
}

.field { margin-bottom: 14px; }

.password-wrap {
  position: relative;
}
.password-wrap input {
  padding-right: 40px;
}
.eye-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  padding: 0;
}
.eye-btn:hover { color: var(--text); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius);
  padding: 9px 14px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 13px; }

.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 8px 0 0; }

.app {
  height: 100%;
  display: grid;
  grid-template-rows: 48px 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.brand { font-weight: 600; font-size: 14px; }
.topbar .spacer { flex: 1; }
.pill {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px 8px;
  color: var(--text);
  letter-spacing: 0.14em;
}
.badge {
  font-size: 11px;
  text-transform: capitalize;
  padding: 2px 7px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  color: var(--muted);
}
.muted { color: var(--muted); }
.tiny { font-size: 12px; color: var(--muted); }

.workspace {
  display: flex;
  min-height: 0;
}
.problem-pane, .editor-pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.problem-pane {
  width: 42%;
  min-width: 240px;
  flex: 0 0 auto;
  background: var(--bg);
}
.editor-pane {
  flex: 1 1 auto;
  min-width: 280px;
  background: #1e1e1e;
}
.gutter {
  flex: 0 0 5px;
  background: var(--border);
  z-index: 2;
}
.gutter:hover,
.gutter.dragging {
  background: #6b6b6b;
}
.gutter-col { cursor: col-resize; }
.gutter-row { cursor: row-resize; }
body.resizing-col { cursor: col-resize; user-select: none; }
body.resizing-row { cursor: row-resize; user-select: none; }
.problem-scroll {
  overflow: auto;
  padding: 20px 22px 40px;
}
.problem-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.problem-head h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
}
.diff {
  font-size: 13px;
  font-weight: 600;
  text-transform: capitalize;
}
.diff.easy { color: var(--easy); }
.diff.medium { color: var(--medium); }
.diff.hard { color: var(--hard); }

.problem-desc {
  font-size: 15px;
  color: #e8e8e8;
}
.problem-desc p {
  margin: 0 0 14px;
}
.problem-desc .io-note {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 0 0 18px;
  font-size: 13px;
}
.problem-desc .io-note .k {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
}
.problem-desc .io-note pre {
  margin: 0 0 10px;
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre-wrap;
}
.problem-desc .io-note pre:last-child { margin-bottom: 0; }

.example {
  margin: 0 0 18px;
}
.example h3 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 600;
}
.example-box {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
}
.example-box .k {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  margin-top: 8px;
}
.example-box .k:first-child { margin-top: 0; }
.example-box pre {
  margin: 4px 0 0;
  white-space: pre-wrap;
  font-family: inherit;
  font-size: inherit;
}

#editor { flex: 1 1 auto; min-height: 80px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  flex-wrap: wrap;
}
.toolbar select,
.toolbar .btn {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius);
  box-sizing: border-box;
}
.toolbar select {
  width: auto;
  min-width: 140px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%239aa0a6' d='M1 1l5 5 5-5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.toolbar .btn.sm {
  padding: 0 12px;
  font-size: 13px;
}

.console {
  height: 220px;
  min-height: 100px;
  flex: 0 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.console-tabs {
  display: flex;
  gap: 2px;
  padding: 0 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.console-tab {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  border-radius: 0;
}
.console-tab.active {
  color: var(--text);
  border-bottom-color: var(--text);
}
.console-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px 14px;
}
.case-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.chip {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 600;
}
.chip.active {
  background: #333;
  border-color: #6b6b6b;
}
.chip.pass { color: var(--ok); }
.chip.fail { color: var(--hard); }
.case-block { min-height: 0; }
.case-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin: 10px 0 6px;
}
.case-label:first-of-type { margin-top: 0; }
.pretty-io {
  margin: 0;
  padding: 8px 10px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--text);
  min-height: 48px;
}
textarea.stdin {
  min-height: 72px;
  resize: vertical;
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
}
pre.output {
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre-wrap;
  color: #d7d7d7;
}

.result-summary {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
}
.result-summary.pass { color: var(--ok); }
.result-summary.fail { color: var(--hard); }

.tests { display: grid; gap: 8px; margin-bottom: 10px; }
.test-card {
  border: 1px solid var(--border);
  background: var(--code-bg);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
}
.test-card .row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 600;
}
.test-card.pass .row { color: var(--ok); }
.test-card.fail .row { color: var(--hard); }
.test-card .kv {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: #cfcfcf;
  white-space: pre-wrap;
}
.test-card .kv span {
  display: block;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 2px;
}

.admin-shell {
  height: 100%;
  display: grid;
  grid-template-rows: 48px 1fr;
}
.admin-grid {
  display: grid;
  grid-template-columns: 1.3fr 0.9fr;
  min-height: 0;
}
.catalog, .rooms {
  overflow: auto;
  padding: 18px 20px 40px;
}
.rooms { border-left: 1px solid var(--border); background: var(--bg-2); }

.section { margin-bottom: 22px; }
.section h2 {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
}
.section.easy h2 { color: var(--easy); }
.section.medium h2 { color: var(--medium); }
.section.hard h2 { color: var(--hard); }

.plist { display: grid; gap: 6px; }
.pitem {
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  width: 100%;
}
.pitem:hover { border-color: #555; }
.pitem.selected { border-color: #888; background: #2e2e2e; }
.pitem .title { font-weight: 600; }
.pitem .blurb { color: var(--muted); font-size: 13px; margin-top: 2px; }
.empty-sec { color: var(--muted); font-size: 13px; padding: 6px 2px; }

.create-bar {
  display: flex;
  gap: 8px;
  align-items: end;
  margin: 8px 0 18px;
  flex-wrap: wrap;
}
.create-bar .field { margin: 0; min-width: 160px; }
.room-code-flash {
  font-family: var(--mono);
  font-size: 26px;
  letter-spacing: 0.18em;
  margin: 8px 0 12px;
}

.room {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  margin-bottom: 8px;
}
.room .code {
  font-family: var(--mono);
  letter-spacing: 0.12em;
}
.room-actions { display: flex; gap: 6px; }

.login-wrap { max-width: 380px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  z-index: 20;
}
.modal {
  width: min(420px, calc(100% - 32px));
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.modal h3 { margin: 0 0 8px; font-size: 16px; }
.modal p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.ended-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 12, 12, 0.82);
  display: grid;
  place-items: center;
  z-index: 30;
}
.ended-card {
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 28px 32px;
  border-radius: var(--radius);
}
.ended-card h2 { margin: 0 0 8px; }
.ended-card p { color: var(--muted); margin: 0 0 16px; }

@media (max-width: 900px) {
  .admin-grid { grid-template-columns: 1fr; }
  .rooms { border-left: 0; border-top: 1px solid var(--border); }
}
