:root {
  --bg: #0f1220;
  --bg-elev: #151931;
  --panel: #0c0f1c;
  --text: #e7ecff;
  --muted: #aab2d5;
  --accent: #7c93ff;
  --accent-2: #3fd1c9;
  --warn: #ffb86b;
  --danger: #ff6b6b;
  --ok: #5be37d;
  --grid-line: #1e2748;
  --cell: #12162b;
  --cell-visited: #1a2140;
  --cell-frontier: #283469;
  --cell-path: #3fd1c9;
  --cell-start: #5be37d;
  --cell-end: #ff6b6b;
  --cell-wall: #0b0f1f;
  --cell-weight: #1d2549;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --pad: 14px;
  --pad-lg: 18px;
  --pad-xl: 22px;
  --cell-size: 22px;
  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Inter, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

[data-theme="light"] {
  --bg: #f6f7fb;
  --bg-elev: #ffffff;
  --panel: #ffffff;
  --text: #0e1329;
  --muted: #5e6a95;
  --accent: #4b61f7;
  --accent-2: #0cb8ac;
  --grid-line: #e6e9f5;
  --cell: #ffffff;
  --cell-visited: #eef1fb;
  --cell-frontier: #dee6ff;
  --cell-path: #0cb8ac;
  --cell-start: #07a864;
  --cell-end: #e04747;
  --cell-wall: #e9ecf8;
  --cell-weight: #f1f4fe;
  --shadow: 0 10px 25px rgba(0,0,0,.08);
}

html, body {
  height: 100%;
  margin: 0;
  background: radial-gradient(1200px 800px at 10% 0%, rgba(124,147,255,.08), transparent 60%),
              radial-gradient(1200px 800px at 90% 0%, rgba(63,209,201,.08), transparent 60%),
              var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app { display: grid; grid-template-rows: auto 1fr auto; min-height: 100vh; }

header { position: sticky; top: 0; z-index: 10; backdrop-filter: saturate(120%) blur(10px); background: linear-gradient(0deg, rgba(17,20,38,.75), rgba(17,20,38,.75)); border-bottom: 1px solid rgba(255,255,255,.06); }

.wrap { max-width: 1280px; margin: 0 auto; padding: 10px 16px; }
.toolbar { display: grid; grid-template-columns: 1fr auto auto auto; gap: 12px; align-items: center; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; letter-spacing: 0.2px; }
.badge { font-size: 12px; padding: 4px 8px; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: white; box-shadow: var(--shadow); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }

.btn { background: var(--bg-elev); color: var(--text); border: 1px solid rgba(255,255,255,.08); border-radius: var(--radius-xs); padding: 8px 12px; cursor: pointer; transition: transform .06s ease, background .2s ease, border-color .2s ease, box-shadow .2s ease; box-shadow: 0 0 0 rgba(0,0,0,0); user-select: none; }
.btn:hover { box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn[disabled] { opacity: .6; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }
.btn.warn { background: var(--warn); color: #0e1329; border-color: transparent; }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.18); }
.btn.toggle[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 1px; }

.seg { display: inline-grid; grid-auto-flow: column; background: var(--bg-elev); border: 1px solid rgba(255,255,255,.08); border-radius: var(--radius-xs); overflow: hidden; }
.seg button { border: 0; padding: 8px 10px; background: transparent; color: var(--text); cursor: pointer; }
.seg button[aria-pressed="true"]{ background: rgba(124,147,255,.15); }

main { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; max-width: 1280px; margin: 16px auto; padding: 0 16px 16px; }
@media (max-width: 1100px){ main { grid-template-columns: 1fr; } }

.card { background: linear-gradient(180deg, rgba(255,255,255,.02), rgba(255,255,255,.00)); border: 1px solid rgba(255,255,255,.08); border-radius: var(--radius); box-shadow: var(--shadow); }

#gridWrap { padding: var(--pad); }
#grid { display: grid; grid-template-columns: repeat(var(--cols), var(--cell-size)); grid-auto-rows: var(--cell-size); gap: 1px; background: var(--grid-line); border-radius: var(--radius-sm); padding: 1px; outline: none; user-select: none; }

.cell { background: var(--cell); border-radius: 6px; transition: background .2s ease, transform .08s ease; position: relative; overflow: hidden; }
.cell.wall { background: var(--cell-wall); }
.cell.visited { background: var(--cell-visited); }
.cell.frontier { background: var(--cell-frontier); }
.cell.path { background: var(--cell-path); box-shadow: inset 0 0 0 2px rgba(255,255,255,.12); }
.cell.start { background: var(--cell-start); }
.cell.end { background: var(--cell-end); }
.cell.weight::after { content: attr(data-w); position: absolute; right: 2px; bottom: 0px; font-size: 10px; color: var(--muted); opacity: .9; }

.legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.legend .chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.legend .dot { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

aside#side { padding: var(--pad); display: grid; gap: 12px; }
.row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; }
.row .note { color: var(--muted); font-size: 12px; }
.group { border-top: 1px dashed rgba(255,255,255,.12); padding-top: 10px; margin-top: 10px; }
.field { display: grid; gap: 4px; font-size: 13px; }
.field label { color: var(--muted); }
.field input[type="range"] { width: 100%; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.pill { font-size: 12px; padding: 4px 8px; border-radius: 999px; background: rgba(124,147,255,.15); color: var(--text); }

footer { border-top: 1px solid rgba(255,255,255,.06); color: var(--muted); font-size: 12px; }
.kbd { font: 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; background: rgba(124,147,255,.15); padding: 3px 6px; border-radius: 6px; }
.log { max-height: 160px; overflow: auto; border-radius: var(--radius-xs); border: 1px dashed rgba(255,255,255,.12); padding: 8px; font-family: ui-monospace, Menlo, Monaco, Consolas, monospace; font-size: 12px; background: var(--panel); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

.active-border { position: relative; }
.active-border::before { content: ""; position: absolute; inset: -2px; border-radius: var(--radius); padding: 2px; background: linear-gradient(135deg, rgba(124,147,255,.4), rgba(63,209,201,.4)) border-box; -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; opacity: 0; transition: opacity .25s ease; pointer-events: none; }
.active-border.running::before { opacity: 1; animation: pulse 1.6s linear infinite; }

@keyframes pulse { 0% { filter: hue-rotate(0deg) brightness(1); } 50% { filter: hue-rotate(30deg) brightness(1.2); } 100% { filter: hue-rotate(0deg) brightness(1); } }

* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.25) transparent; }
*::-webkit-scrollbar { height: 8px; width: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(255,255,255,.25); border-radius: 8px; }

@media (prefers-reduced-motion: reduce){ .cell { transition: none; } .btn { transition: none; } .active-border::before { animation: none; } }


