:root {
  --bg: #161718; --panel: #1b1d1e; --panel-2: #131415; --line: #34373a;
  --text: #e4e5e6; --muted: #9b9ea1; --accent: #2563eb;
  --good: #22c55e; --warn: #f59e0b; --bad: #ef4444; --tip: #38bdf8;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-2: 0 6px 18px rgba(0, 0, 0, .45);
  --fs-xs: 11px; --fs-sm: 12px; --fs-base: 13px; --fs-md: 14px; --fs-lg: 15px; --fs-2xl: 26px;
  --radius: 8px; --radius-sm: 6px;
  --canvas-w: 2600px; --canvas-h: 1800px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: var(--fs-base); line-height: 1.5;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app-header { display: flex; align-items: center; justify-content: space-between; padding: 9px 18px; border-bottom: 1px solid var(--line); }
.app-header h1 { margin: 0; font-size: var(--fs-lg); font-weight: 600; letter-spacing: -.01em; }
.screen { padding: 20px; }
.hidden { display: none !important; }

.btn {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 6px 12px; cursor: pointer;
  font-size: var(--fs-base); font-weight: 500; line-height: 1.4;
  transition: background .12s, border-color .12s;
}
.btn:hover { border-color: var(--accent); background: #2a2c2e; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4fd0; border-color: #1d4fd0; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-icon { display: inline-flex; align-items: center; justify-content: center; padding: 7px; color: var(--muted); }
.btn-icon:hover { color: var(--text); }
.btn-icon svg { display: block; }
.btn-back { display: inline-flex; align-items: center; gap: 6px; }
.btn-back svg { display: block; }

.picker-controls { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: var(--fs-base); font-weight: 500; user-select: none; }
.switch input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.filter-bar { display: flex; gap: 8px; margin-bottom: 18px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.q-card {
  background: var(--panel); border-radius: 12px; padding: 16px; cursor: pointer;
  box-shadow: var(--shadow-1); transition: transform .12s, box-shadow .12s;
}
.q-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.q-card h3 { margin: 0 0 10px; font-size: var(--fs-md); font-weight: 600; }
.q-tags { display: flex; gap: 6px; }
.tag { font-size: var(--fs-xs); font-weight: 500; padding: 3px 9px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }

#playground-screen { padding: 0; height: calc(100vh - 47px); display: flex; flex-direction: column; }
.top-bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.challenge-title { flex: 1; font-size: var(--fs-md); font-weight: 600; }
.top-actions { display: flex; gap: 8px; }
.reqs-panel { padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--line); font-size: var(--fs-base); }
.reqs-panel strong { font-weight: 600; }
.reqs-panel ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }
.reqs-panel li { margin-bottom: 2px; }
.workspace { flex: 1; display: flex; min-height: 0; }

.palette { width: 210px; border-right: 1px solid var(--line); padding: 12px; overflow-y: auto; }
.palette-search { width: 100%; padding: 7px 9px; margin-bottom: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--text); font-size: var(--fs-base); }
.palette-search::placeholder { color: var(--muted); }
.palette-tabs { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }
.palette-tab { font-size: var(--fs-xs); font-weight: 500; padding: 4px 9px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--panel); color: var(--muted); cursor: pointer; transition: color .12s, border-color .12s; }
.palette-tab:hover { color: var(--text); }
.palette-tab.active { color: #fff; background: var(--accent); border-color: var(--accent); }
.palette-item { display: flex; align-items: center; gap: 9px; padding: 8px 9px; margin-bottom: 5px; background: var(--panel); border: 1px solid transparent; border-radius: var(--radius-sm); cursor: grab; font-size: var(--fs-base); transition: border-color .12s; touch-action: none; }
.palette-drag-ghost { position: fixed; pointer-events: none; z-index: 100; opacity: .85; transform: translate(-50%, -50%); width: 160px; border-color: var(--accent); }
.palette-item:hover { border-color: var(--line); }
.palette-item .glyph { width: 18px; text-align: center; flex: none; }

.canvas-wrap { flex: 1; position: relative; overflow: auto; touch-action: none; }

.zoom-sizer { position: relative; width: var(--canvas-w); height: var(--canvas-h); pointer-events: none; }
.zoom-layer { position: absolute; top: 0; left: 0; width: var(--canvas-w); height: var(--canvas-h); transform-origin: 0 0; pointer-events: none; }
.edge-layer, .canvas { position: absolute; top: 0; left: 0; width: var(--canvas-w); height: var(--canvas-h); }
.edge-layer { pointer-events: none; }

.canvas { pointer-events: none; background:
  repeating-linear-gradient(0deg, transparent, transparent 23px, rgba(255, 255, 255, .035) 24px),
  repeating-linear-gradient(90deg, transparent, transparent 23px, rgba(255, 255, 255, .035) 24px); }
.canvas-wrap::-webkit-scrollbar { width: 12px; height: 12px; }
.canvas-wrap::-webkit-scrollbar-thumb { background: #34373a; border-radius: 8px; border: 3px solid var(--bg); }
.canvas-wrap::-webkit-scrollbar-thumb:hover { background: #45494d; }

.canvas-wrap, .palette, .feedback-panel { scrollbar-width: thin; scrollbar-color: #34373a transparent; }

.node {
  position: absolute; pointer-events: auto; touch-action: none; min-width: 96px; max-width: 210px;
  padding: 9px 11px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); cursor: move; user-select: none; text-align: left;
  box-shadow: var(--shadow-1); transition: outline-color .1s, box-shadow .12s;
}
.node:hover { box-shadow: var(--shadow-2); }
.node .node-label { display: block; font-size: var(--fs-base); font-weight: 600; line-height: 1.3; }
.node .node-type { display: block; margin-top: 1px; font-size: var(--fs-xs); font-weight: 400; color: var(--muted); }
.node .node-desc { display: block; margin-top: 5px; font-size: var(--fs-sm); color: #c8cacb; line-height: 1.4; }
.node .node-nudge { display: inline-block; margin-top: 5px; font-size: var(--fs-xs); font-weight: 500; color: var(--accent); cursor: pointer; }
.node .node-nudge:hover { text-decoration: underline; }
.node-editor { display: block; width: 170px; min-height: 48px; margin-top: 6px; padding: 6px; font-size: var(--fs-sm); font-family: inherit; background: var(--panel-2); color: var(--text); border: 1px solid var(--accent); border-radius: var(--radius-sm); resize: vertical; }
.node.linking { border-color: var(--accent); }
.node:focus, .node:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.node.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.node.drop-target { outline: 2px dashed var(--good); outline-offset: 3px; box-shadow: 0 0 0 4px rgba(34, 197, 94, .18); }

.node-badge { position: absolute; top: -8px; left: -8px; width: 18px; height: 18px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: var(--fs-sm); font-weight: 700; line-height: 1; color: #fff; box-shadow: var(--shadow-1); }
.node-badge-good { background: var(--good); }
.node-badge-warning { background: var(--warn); }
.node-badge-problem { background: var(--bad); }

.node-port { position: absolute; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); border: 2px solid var(--panel-2); cursor: crosshair; opacity: 0; transition: opacity .1s; }
.node:hover .node-port, .node:focus .node-port { opacity: .9; }
.node-port:hover { opacity: 1; box-shadow: 0 0 0 3px rgba(37, 99, 235, .35); }
.port-right { right: -5px; top: 50%; transform: translateY(-50%); }
.port-left { left: -5px; top: 50%; transform: translateY(-50%); }
.port-top { top: -5px; left: 50%; transform: translateX(-50%); }
.port-bottom { bottom: -5px; left: 50%; transform: translateX(-50%); }

.node-del { position: absolute; top: -8px; right: -8px; width: 18px; height: 18px; border-radius: 50%; background: #3a3d40; color: #e4e5e6; display: flex; align-items: center; justify-content: center; cursor: pointer; opacity: 0; transition: opacity .1s, background .12s; box-shadow: var(--shadow-1); }
.node:hover .node-del, .node:focus .node-del { opacity: 1; }
.node-del:hover { background: #4d5154; }
.node-del svg, .edge-del svg { pointer-events: none; display: block; }

.link-preview { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 4; opacity: .9; pointer-events: none; }
.edge-handle { position: absolute; pointer-events: auto; touch-action: none; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--panel-2); transform: translate(-50%, -50%); cursor: grab; z-index: 6; }
.edge-handle.dragging { cursor: grabbing; }
.edge-del { position: absolute; pointer-events: auto; width: 19px; height: 19px; border-radius: 50%; background: #3a3d40; color: #e4e5e6; display: flex; align-items: center; justify-content: center; transform: translate(-50%, -50%); cursor: pointer; z-index: 6; box-shadow: var(--shadow-1); }
.edge-del:hover { background: #4d5154; }
.edge-label-editor { position: absolute; pointer-events: auto; transform: translate(-50%, -50%); width: 140px; padding: 5px 7px; font-size: var(--fs-sm); font-family: inherit; background: var(--panel-2); color: var(--text); border: 1px solid var(--accent); border-radius: var(--radius-sm); z-index: 7; }

.feedback-panel { width: 320px; border-left: 1px solid var(--line); padding: 16px; overflow-y: auto; }
.feedback-empty { color: var(--muted); font-size: var(--fs-base); }
.feedback-note { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: var(--fs-xs); line-height: 1.5; }
.btn-link { background: none; border: none; padding: 0; color: var(--accent); font-size: inherit; font-family: inherit; cursor: pointer; }
.btn-link:hover { text-decoration: underline; }
.feedback-panel > p { margin: 6px 0 0; font-size: var(--fs-sm); color: var(--muted); }
.score-badge { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.fb-group { margin-top: 18px; }
.fb-group h4 { margin: 0 0 8px; font-size: var(--fs-sm); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.status-icon { vertical-align: -.15em; }
.fb-group h4.fb-icon-good .status-icon { color: var(--good); }
.fb-group h4.fb-icon-problem .status-icon { color: var(--bad); }
.fb-item { border-left: 3px solid var(--line); padding: 3px 0 3px 10px; margin-bottom: 8px; font-size: var(--fs-sm); line-height: 1.45; }
.fb-item .fb-title { display: block; margin-bottom: 1px; font-weight: 600; }
.fb-item span:not(.fb-title) { color: var(--muted); }
.fb-good { border-color: var(--good); }
.fb-warn { border-color: var(--warn); }
.fb-bad { border-color: var(--bad); }
.fb-tip { border-color: var(--tip); }
.fb-error { color: var(--bad); font-size: var(--fs-base); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--muted); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.nr-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.nr-header h3 { margin: 0; font-size: var(--fs-md); font-weight: 600; }
.nr-rating { font-size: var(--fs-xs); font-weight: 600; padding: 3px 9px; border-radius: 999px; color: #fff; white-space: nowrap; }
.nr-rating-good { background: var(--good); }
.nr-rating-warning { background: var(--warn); }
.nr-rating-problem { background: var(--bad); }
.nr-section { margin-top: 14px; }
.nr-section h5 { margin: 0 0 5px; font-size: var(--fs-sm); font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.nr-section p { margin: 0; font-size: var(--fs-sm); line-height: 1.45; }
.nr-section ul { margin: 0; padding-left: 16px; font-size: var(--fs-sm); color: var(--muted); }
.nr-section li { margin-bottom: 4px; line-height: 1.45; }


.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .65); display: flex; align-items: center; justify-content: center; }
.modal-body { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px; width: 380px; box-shadow: var(--shadow-2); }
.modal-body.modal-wide { width: 580px; }
.modal-body h2 { margin: 0 0 8px; font-size: var(--fs-lg); font-weight: 600; }
.modal-body p { margin: 0 0 4px; font-size: var(--fs-sm); color: var(--muted); }
.modal-body input { width: 100%; padding: 8px; margin: 0 0 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--text); font-size: var(--fs-base); }
.modal-body select { width: 100%; padding: 8px; margin: 0 0 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--text); font-size: var(--fs-base); }
.field-label { display: block; margin: 12px 0 5px; font-size: var(--fs-sm); font-weight: 600; color: var(--muted); }
.settings-tabs { display: flex; gap: 4px; margin: 6px 0 4px; border-bottom: 1px solid var(--line); }
.settings-tab { background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 8px 13px; color: var(--muted); font-size: var(--fs-base); font-weight: 600; font-family: inherit; cursor: pointer; transition: color .12s, border-color .12s; }
.settings-tab:hover { color: var(--text); }
.settings-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.modal-body textarea { width: 100%; margin: 12px 0; padding: 9px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--text); font-family: ui-monospace, monospace; font-size: var(--fs-sm); line-height: 1.5; resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.field-hint { margin: -8px 0 12px; font-size: var(--fs-xs); color: var(--muted); }

.preview-section { margin-top: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.preview-section summary { padding: 8px 10px; font-size: var(--fs-sm); font-weight: 600; cursor: pointer; user-select: none; }
.preview-section summary:hover { color: #fff; }
.preview-pre { margin: 0; padding: 10px; max-height: 260px; overflow: auto; border-top: 1px solid var(--line); background: var(--panel-2); font-family: ui-monospace, monospace; font-size: var(--fs-xs); line-height: 1.5; white-space: pre-wrap; word-break: break-word; }

.timer-wrap { display: flex; align-items: center; }
.timer-display { font-variant-numeric: tabular-nums; font-size: var(--fs-md); font-weight: 600; padding: 5px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); cursor: pointer; }
.timer-display:hover { border-color: var(--accent); }
.timer-display.expired { color: var(--bad); border-color: var(--bad); }
.timer-edit { font-size: var(--fs-md); width: 58px; padding: 5px 7px; background: var(--panel-2); border: 1px solid var(--accent); border-radius: var(--radius-sm); color: var(--text); }
.timeup-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 16px; background: rgba(239, 68, 68, .14); border-bottom: 1px solid rgba(239, 68, 68, .5); font-size: var(--fs-base); }
.banner-dismiss { background: transparent; border: none; color: var(--muted); font-size: 16px; cursor: pointer; line-height: 1; }
.banner-dismiss:hover { color: var(--text); }

@media (pointer: coarse) {
  .node-port { width: 16px; height: 16px; opacity: .8; }
  .port-right { right: -9px; } .port-left { left: -9px; }
  .port-top { top: -9px; } .port-bottom { bottom: -9px; }
  .node:hover .node-port, .node-port { opacity: .8; }
  .node-del { opacity: 1; width: 22px; height: 22px; }
  .edge-handle { width: 18px; height: 18px; }
  .edge-del { width: 26px; height: 26px; }
}
