/* ===========================================================================
   Codes.Live — components.css
   Buttons, controls, transport, panels, and the shared visualizer layout.
   ========================================================================== */

/* ---------------------------------------------------------------- Icon button */
.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
  color: var(--text-dim); transition: background var(--dur), color var(--dur);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------------------------------------------------------------- Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 15px; border-radius: var(--r-md); font-size: 13.5px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  transition: transform .12s var(--ease), background var(--dur), border-color var(--dur), box-shadow var(--dur), opacity var(--dur);
  white-space: nowrap; user-select: none;
}
.btn svg { width: 16px; height: 16px; }
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn--primary {
  background: var(--accent-gradient); border-color: transparent; color: var(--on-accent);
  box-shadow: 0 6px 20px -6px color-mix(in srgb, var(--indigo) 45%, transparent);
}
.btn--primary:hover { box-shadow: 0 10px 28px -6px color-mix(in srgb, var(--indigo) 60%, transparent); filter: brightness(1.05); }
.btn--ghost { background: transparent; }
.btn--danger { color: var(--c-swap); border-color: color-mix(in srgb, var(--c-swap) 35%, transparent); }
.btn--danger:hover { background: color-mix(in srgb, var(--c-swap) 14%, transparent); }
.btn--sm { padding: 6px 11px; font-size: 12.5px; }
.btn--icon { padding: 9px; }

/* ---------------------------------------------------------------- Segmented */
.segmented {
  display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--border);
}
.segmented__btn {
  padding: 6px 13px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--text-dim);
  transition: background var(--dur), color var(--dur); white-space: nowrap;
}
.segmented__btn:hover { color: var(--text); }
.segmented__btn.is-active { background: var(--elevated); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------------------------------------------------------------- Fields */
.field { display: inline-flex; flex-direction: column; gap: 5px; }
.field__label { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.field--row { flex-direction: row; align-items: center; gap: 9px; }

.input, .select {
  padding: 8px 12px; border-radius: var(--r-md); background: var(--surface-2);
  border: 1px solid var(--border); color: var(--text); font-size: 13.5px;
  transition: border-color var(--dur), box-shadow var(--dur); min-width: 0;
}
.input:focus, .select:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px color-mix(in srgb, var(--indigo) 22%, transparent); }
.input::placeholder { color: var(--muted); }
.input--mono { font-family: var(--font-mono); }
.select {
  appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5L6 8l3-3.5' stroke='%238b94a7' stroke-width='1.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}

/* ---------------------------------------------------------------- Slider */
.slider { -webkit-appearance: none; appearance: none; width: 130px; height: 5px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent-gradient); border: 2px solid var(--surface); box-shadow: 0 2px 8px rgba(0,0,0,.4); cursor: grab;
}
.slider::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--indigo); border: 2px solid var(--surface); cursor: grab; }
.slider:active::-webkit-slider-thumb { cursor: grabbing; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 13px; color: var(--text-dim); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch__track { position: relative; width: 38px; height: 22px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); transition: background var(--dur); flex-shrink: 0; }
.switch__track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: transform var(--dur) var(--ease), background var(--dur); }
.switch input:checked + .switch__track { background: color-mix(in srgb, var(--indigo) 60%, transparent); }
.switch input:checked + .switch__track::after { transform: translateX(16px); background: #fff; }

/* ===========================================================================
   Visualizer layout
   ========================================================================== */
.viz { position: relative; display: flex; flex-direction: column; height: 100%; animation: fade-in .35s var(--ease); }

/* Top-right demo controls: theme toggle + fullscreen (classroom / projector). */
.viz__controls { position: absolute; top: 14px; right: clamp(14px, 4vw, 36px); z-index: 6; display: flex; align-items: center; gap: 8px; }
.viz__ctrl {
  width: 64px; height: 36px; display: grid; place-items: center; padding: 0;
  border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-dim); cursor: pointer;
  transition: color var(--dur), border-color var(--dur), background var(--dur);
}
.viz__ctrl:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface); }
.viz__ctrl svg { width: 18px; height: 18px; }
.viz__fs.is-on { color: var(--accent, var(--indigo)); border-color: var(--accent, var(--indigo)); }

/* Back-to-list button placed before the problem title. */
.viz__back {
  flex: 0 0 auto; width: 64px; height: 36px; display: grid; place-items: center;
  border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-dim); transition: color var(--dur), border-color var(--dur), background var(--dur);
}
.viz__back:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface); }
.viz__back svg { width: 18px; height: 18px; }

.viz--fullscreen {
  position: fixed; inset: 0; z-index: 60; height: 100%;
  background: var(--bg); animation: fade-in .2s var(--ease);
}
/* In fullscreen, hide the right sidebar and the problem title/description so the
   main component (the stage) fills the screen — but KEEP the back button as a
   minimal top-left header row. */
.viz--fullscreen .viz__header { padding: 12px clamp(14px, 4vw, 36px); }
.viz--fullscreen .viz__title-text { font-size: clamp(18px, 2.4vw, 24px); }
.viz--fullscreen .viz__desc,
.viz--fullscreen .viz__tags { display: none; }   /* keep back + title + difficulty only */
.viz--fullscreen .side { display: none; }
.viz--fullscreen .viz__body--with-side { grid-template-columns: 1fr; }
.viz--fullscreen .toolbar { padding-top: 12px; padding-bottom: 12px; }

/* LeetCode-style problem header: modest title, difficulty pill, topic tags. */
.viz__header { padding: 20px clamp(18px, 4vw, 40px) 16px; border-bottom: 1px solid var(--border); }
.viz__title { font-size: clamp(19px, 2.2vw, 25px); font-weight: 700; letter-spacing: -.02em; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.viz__title-text { color: var(--text); }
.viz__title-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: color-mix(in srgb, var(--accent, var(--indigo)) 16%, var(--surface-2)); color: var(--accent, var(--indigo)); }
.viz__title-icon svg { width: 20px; height: 20px; }
.viz__diff { font-size: 13px; font-weight: 600; padding: 3px 13px; border-radius: 99px; }
.viz__diff[data-diff="easy"]   { color: var(--easy);   background: color-mix(in srgb, var(--easy) 14%, transparent); }
.viz__diff[data-diff="medium"] { color: var(--medium); background: color-mix(in srgb, var(--medium) 16%, transparent); }
.viz__diff[data-diff="hard"]   { color: var(--hard);   background: color-mix(in srgb, var(--hard) 14%, transparent); }
/* "Open on LeetCode" link next to the title. */
.viz__lc { flex: 0 0 auto; display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; color: var(--muted); transition: color var(--dur), background var(--dur); }
.viz__lc:hover { color: var(--indigo); background: var(--surface-2); }
.viz__lc svg { width: 18px; height: 18px; }
.viz__tags { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.viz__tag { font-size: 11.5px; font-weight: 500; color: var(--text-dim); background: var(--surface-2); border: 1px solid var(--border); padding: 3px 10px; border-radius: 99px; }
.viz__desc { margin-top: 12px; color: var(--text-dim); font-size: 14px; max-width: 760px; }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px;
  padding: 18px clamp(18px, 4vw, 40px); border-bottom: 1px solid var(--border);
}
.toolbar__group { display: flex; align-items: flex-end; gap: 10px; }
.toolbar__sep { width: 1px; align-self: stretch; background: var(--border); margin: 2px 2px; }
.toolbar__spacer { flex: 1; }

.viz__body { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr; gap: 0; }
.viz__body--with-side { grid-template-columns: 1fr minmax(260px, 320px); }

.stage {
  position: relative; min-height: 0; min-width: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background:
    linear-gradient(var(--grid-line) 1px, transparent 1px) 0 0 / 100% 28px,
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px) 0 0 / 28px 100%;
}
.stage--scroll { overflow: auto; align-items: flex-start; }
.stage__canvas { display: block; width: 100%; height: 100%; }
.stage__inner { width: 100%; height: 100%; position: relative; }
.stage__empty { color: var(--muted); font-size: 14px; text-align: center; padding: 40px; }

/* Side panel (pseudocode / info / legend) */
.side {
  border-left: 1px solid var(--border); overflow-y: auto; padding: 8px;
  display: flex; flex-direction: column; gap: 18px; background: color-mix(in srgb, var(--surface) 40%, transparent);
}
.panel { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-2); }
.panel__head { display: flex; align-items: center; justify-content: space-between; padding: 10px 13px; border-bottom: 1px solid var(--border); font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.panel__body { padding: 13px; }

/* Pseudocode */
.pseudocode { font-family: var(--font-mono); font-size: 12.5px; line-height: 1.7; }
.pseudocode .line { display: flex; gap: 12px; padding: 1px 8px; border-radius: 6px; color: var(--text-dim); transition: background .18s, color .18s; white-space: pre; }
.pseudocode .line__no { color: var(--muted); opacity: .5; user-select: none; min-width: 16px; text-align: right; }
.pseudocode .line.is-active { background: color-mix(in srgb, var(--accent, var(--indigo)) 18%, transparent); color: var(--text); }
.pseudocode .line.is-active .line__no { color: var(--accent, var(--indigo)); opacity: 1; }
.pseudocode .indent { padding-left: 18px; }
.pseudocode .indent-2 { padding-left: 36px; }
.pseudocode .indent-3 { padding-left: 54px; }
.pseudocode .kw { color: var(--violet); }
.pseudocode .fn { color: var(--cyan); }
.pseudocode .num { color: var(--c-compare); }
.pseudocode .cmt { color: var(--muted); font-style: italic; }

/* Legend */
.legend { display: flex; flex-wrap: wrap; gap: 7px 14px; }
.legend__item { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-dim); }
.legend__swatch { width: 13px; height: 13px; border-radius: 4px; flex-shrink: 0; box-shadow: inset 0 0 0 1px rgba(255,255,255,.12); }

/* Stat pills */
.stats { display: flex; flex-wrap: wrap; gap: 8px; }
.stat-pill {
  display: inline-flex; flex-direction: column; gap: 1px; padding: 8px 6px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--border); min-width: 76px;
}
.stat-pill b { font-size: 16px; font-weight: 700; font-family: var(--font-mono); letter-spacing: -.02em; }
.stat-pill span { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* Status line */
.status {
  font-size: 13.5px; color: var(--text-dim); padding: 9px 14px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--border); min-height: 38px;
  display: flex; align-items: center; gap: 8px; line-height: 1.35;
}
.status b, .status .mono { color: var(--text); }
.status__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c-primary); flex-shrink: 0; }

/* ===========================================================================
   Transport / playback bar
   ========================================================================== */
.transport {
  display: flex; align-items: center; gap: 14px;
  padding: 12px clamp(18px, 4vw, 40px); border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 60%, transparent); backdrop-filter: blur(10px);
  flex-shrink: 0;
}
.transport__buttons { display: flex; align-items: center; gap: 6px; }
.transport__btn {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
  color: var(--text-dim); border: 1px solid transparent; transition: background var(--dur), color var(--dur);
}
.transport__btn:hover { background: var(--surface-2); color: var(--text); }
.transport__btn:disabled { opacity: .35; pointer-events: none; }
.transport__btn svg { width: 18px; height: 18px; }
.transport__play {
  width: 46px; height: 46px; border-radius: 13px; color: var(--on-accent);
  background: var(--accent-gradient); box-shadow: 0 6px 18px -5px color-mix(in srgb, var(--indigo) 45%, transparent);
}
.transport__play:hover { filter: brightness(1.08); background: var(--accent-gradient); color: var(--on-accent); }
.transport__play svg { width: 20px; height: 20px; }

.transport__scrub { flex: 1; display: flex; align-items: center; gap: 12px; min-width: 0; }
.scrubber { position: relative; flex: 1; height: 6px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; }
.scrubber__fill { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: var(--accent-gradient); width: 0%; }
.scrubber__thumb { position: absolute; top: 50%; transform: translate(-50%, -50%); width: 15px; height: 15px; border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.45); left: 0%; pointer-events: none; }
.transport__time { font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); white-space: nowrap; min-width: 78px; text-align: right; }

.transport__speed { display: flex; align-items: center; gap: 9px; }
.transport__speed-label { font-size: 12px; color: var(--muted); font-family: var(--font-mono); min-width: 30px; }

/* ===========================================================================
   Shared visualization primitives
   ========================================================================== */
/* Array of cells (used by list / stack / queue / hashing / DP) */
.cells { display: flex; gap: 8px; flex-wrap: wrap; }
.cell {
  position: relative; display: grid; place-items: center; min-width: 48px; height: 48px; padding: 0 6px;
  border-radius: var(--r-sm); background: var(--surface-2); border: 1.5px solid var(--border);
  font-family: var(--font-mono); font-weight: 600; font-size: 15px;
  transition: background var(--dur), border-color var(--dur), transform var(--dur) var(--ease), color var(--dur);
}
.cell__index { position: absolute; bottom: -19px; left: 0; right: 0; text-align: center; font-size: 10.5px; color: var(--muted); font-family: var(--font-mono); }
.cell.is-active { border-color: var(--c-primary); color: var(--c-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-primary) 22%, transparent); }
.cell.is-compare { border-color: var(--c-compare); color: var(--c-compare); }
.cell.is-done { border-color: var(--c-sorted); color: var(--c-sorted); background: color-mix(in srgb, var(--c-sorted) 12%, var(--surface-2)); }

/* Generic node (tree / graph / linked list) */
.gnode {
  display: grid; place-items: center; border-radius: 50%; background: var(--surface-2);
  border: 2px solid var(--border-strong); font-family: var(--font-mono); font-weight: 600;
  transition: all var(--dur) var(--ease);
}

/* Empty / hint badge */
.hint {
  display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted);
  padding: 7px 12px; border-radius: 99px; background: var(--surface-2); border: 1px dashed var(--border-strong);
}

/* Toast */
.toast-host { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  padding: 10px 16px; border-radius: var(--r-md); background: var(--elevated); border: 1px solid var(--border-strong);
  color: var(--text); font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow);
  animation: pop .25s var(--ease-bounce); display: flex; align-items: center; gap: 9px;
}
.toast--error { border-color: color-mix(in srgb, var(--c-swap) 50%, transparent); }
.toast--success { border-color: color-mix(in srgb, var(--c-sorted) 50%, transparent); }

/* ===========================================================================
   Data-structure primitives (stack / queue / list / hashing)
   ========================================================================== */
.ds-stage { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; gap: 48px; padding: 30px; overflow: auto; }
.dscol { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.dscol__label, .dsrow__label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.dscell {
  position: relative; display: flex; align-items: center; justify-content: center;
  min-width: 64px; height: 48px; padding: 0 14px; border-radius: 10px;
  background: var(--elevated); border: 1.5px solid var(--border-strong);
  font-family: var(--font-mono); font-weight: 600; font-size: 16px;
  transition: transform .3s var(--ease), opacity .3s, border-color .25s, background .25s, color .25s, box-shadow .25s;
}
.dscell.is-enter, .dscell.is-leaving { opacity: 0; transform: translateY(-18px) scale(.92); }
.dscell.is-active { border-color: var(--accent, var(--c-primary)); color: var(--accent, var(--c-primary)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, var(--c-primary)) 22%, transparent); }
.dscell.is-flash { border-color: var(--c-compare); color: var(--c-compare); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-compare) 20%, transparent); }
.dscell.is-done { border-color: var(--c-sorted); color: var(--c-sorted); background: color-mix(in srgb, var(--c-sorted) 12%, var(--elevated)); }
.dscell.is-ghost { opacity: .4; border-style: dashed; }
.dscell__tag { position: absolute; right: -8px; top: 50%; transform: translate(100%, -50%); font-size: 10.5px; font-weight: 700; letter-spacing: .05em; color: var(--accent, var(--c-primary)); white-space: nowrap; }
.dscell__tag--below { right: auto; left: 50%; top: auto; bottom: -8px; transform: translate(-50%, 100%); }
.dscell__idx { position: absolute; bottom: -20px; left: 0; right: 0; text-align: center; font-size: 10.5px; color: var(--muted); font-family: var(--font-mono); }
.stackbox {
  display: flex; flex-direction: column-reverse; gap: 8px; padding: 12px;
  border: 1.5px solid var(--border); border-bottom-width: 3px; border-radius: 14px;
  background: color-mix(in srgb, var(--surface-2) 70%, transparent); min-width: 112px; min-height: 76px;
  align-items: center;
}
.dsrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ds-conn { width: 22px; height: 2px; background: var(--border-strong); position: relative; }
.ds-conn::after { content: ""; position: absolute; right: -1px; top: 50%; transform: translateY(-50%); border: 5px solid transparent; border-left-color: var(--border-strong); }
.ds-empty { color: var(--muted); font-size: 13px; padding: 18px; }
.ds-log { font-family: var(--font-mono); font-size: 12px; line-height: 1.85; max-height: 200px; overflow: auto; display: flex; flex-direction: column-reverse; }
.ds-log__op { color: var(--text-dim); }
.ds-log__op b { color: var(--accent, var(--c-primary)); }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; padding: 2px 0; }
.kv span { color: var(--muted); } .kv b { font-family: var(--font-mono); }

/* ---------------------------------------------------------------- Responsive */
@media (max-width: 820px) {
  .viz__body--with-side { grid-template-columns: 1fr; }
  .viz__body--with-side .side { border-left: none; border-top: 1px solid var(--border); flex-direction: row; flex-wrap: wrap; }
  .toolbar { padding: 14px 18px; }
  .transport__time { display: none; }
}

/* ===========================================================================
   Auth: top-bar button, lazy-load spinner, and the sign-in gate
   ========================================================================== */
.topbar__auth { flex: 0 0 auto; display: flex; align-items: center; }
.authbtn {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 13px;
  border-radius: 10px; font-size: 13.5px; font-weight: 600; font-family: inherit;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  transition: border-color var(--dur), background var(--dur);
}
.authbtn:hover { border-color: var(--border-strong); background: var(--surface); }
.authbtn__gh, .authbtn__out { display: grid; place-items: center; color: var(--text-dim); }
.authbtn.is-disabled { opacity: .55; cursor: not-allowed; }
.authbtn--user { padding: 5px 11px 5px 5px; }
.authbtn__avatar { width: 22px; height: 22px; border-radius: 50%; display: block; }

.viz-load { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; color: var(--muted); font-size: 14px; }
.viz-load__spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--indigo); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.gate { position: relative; overflow: hidden; min-height: 100%; display: grid; place-items: center; padding: 40px 20px; animation: fade-in .3s var(--ease); }

/* A real, live visualization plays — lightly blurred — behind the sign-in card. */
.gate__preview {
  position: absolute; inset: 0; z-index: 0; overflow: hidden;
  pointer-events: none; user-select: none;
  filter: blur(3px) saturate(1.05);
  opacity: .9;
}
:root[data-theme="dark"] .gate__preview { opacity: .8; }
/* The mounted demo lives here — static (slightly scaled to crop blurred edges). */
.gate__preview-inner {
  position: absolute; inset: 0; width: 100%; height: 100%;
  transform: scale(1.04); transform-origin: center;
}
.gate__preview-inner > .viz { height: 100%; }
.gate__scrim {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(78% 76% at 50% 47%,
    color-mix(in srgb, var(--bg) 66%, transparent) 0%,
    color-mix(in srgb, var(--bg) 34%, transparent) 56%,
    color-mix(in srgb, var(--bg) 6%, transparent) 100%);
}

.gate__card {
  position: relative; z-index: 2; width: 100%; max-width: 412px; text-align: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px) saturate(1.1); -webkit-backdrop-filter: blur(8px) saturate(1.1);
  border: 1px solid var(--border-strong); border-radius: 22px; padding: 34px 34px 28px;
  box-shadow: 0 36px 90px -28px rgba(0,0,0,.45), 0 6px 18px -10px rgba(0,0,0,.3);
  animation: gate-pop .4s var(--ease) both;
}
@keyframes gate-pop { from { opacity: 0; transform: translateY(12px) scale(.975); } to { opacity: 1; transform: none; } }
.gate__brand { font-size: 11px; font-weight: 800; letter-spacing: .16em; color: var(--muted); margin-bottom: 16px; }
.gate__brand span { color: var(--brand); }
.gate__icon {
  width: 66px; height: 66px; margin: 0 auto 18px; display: grid; place-items: center; color: var(--brand);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 36%, color-mix(in srgb, var(--brand) 26%, transparent), color-mix(in srgb, var(--brand) 8%, transparent));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--brand) 26%, transparent), 0 10px 26px -8px color-mix(in srgb, var(--brand) 50%, transparent);
}
.gate__title { font-size: 22px; font-weight: 750; letter-spacing: -.02em; }
.gate__sub { margin-top: 9px; color: var(--text-dim); font-size: 14.5px; line-height: 1.5; }
.gate__sub b {
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.06em;
  color: #13ae4d;
}
.gate__sub strike {
  position: relative;
  display: inline-block;
  color: #8f9194;
  font-weight: 500;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}
.gate__btn {
  margin-top: 22px; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 13px 18px; border-radius: 13px; font-size: 14.5px; font-weight: 650;
  color: #fff; background: #1f2328; border: 1px solid #1f2328;
  box-shadow: 0 8px 20px -10px rgba(0,0,0,.5);
  transition: filter var(--dur), transform .12s var(--ease), box-shadow var(--dur);
}
.gate__btn:hover { filter: brightness(1.2); transform: translateY(-1px); box-shadow: 0 12px 26px -10px rgba(0,0,0,.55); }
.gate__btn:active { transform: translateY(0) scale(.985); }
.gate__btn svg { flex: 0 0 auto; }
/* Pro / paywall buttons use the brand green; stack when there are two. */
.gate__btn--pay { background: var(--accent-gradient); border-color: transparent; color: var(--on-accent); box-shadow: 0 10px 24px -10px color-mix(in srgb, var(--brand) 55%, transparent); }
.gate__btn--pay + .gate__btn--pay { margin-top: 10px; }
.gate__icon--pro { color: var(--brand-gold); background: radial-gradient(circle at 50% 36%, color-mix(in srgb, var(--brand-gold) 24%, transparent), color-mix(in srgb, var(--brand-gold) 8%, transparent)); box-shadow: 0 0 0 1px color-mix(in srgb, var(--brand-gold) 28%, transparent), 0 10px 26px -8px color-mix(in srgb, var(--brand-gold) 50%, transparent); }
.gate__fine { margin-top: 13px; font-size: 12px; color: var(--muted); }
.gate__note { margin-top: 22px; font-size: 13px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; line-height: 1.45; }
.gate__back { display: inline-block; margin-top: 16px; font-size: 13px; color: var(--text-dim); transition: color var(--dur); }
.gate__back:hover { color: var(--brand); }

/* ===========================================================================
   Solution-diagram page — Brilliant.com style: calm tinted backdrop, soft
   rounded cards, generous whitespace, friendly pill controls, a dotted stage
   card hero, and a big round play button. Scoped to .viz (home is untouched).
   ========================================================================== */
.viz {
  background:
    radial-gradient(1000px 520px at 50% -8%, color-mix(in srgb, var(--brand) 8%, transparent), transparent 62%),
    var(--bg);
}

/* Two-column shell: a left main column + a full-page-height right sidebar.
   The sidebar is its own grid column, so it spans the entire page height
   (alongside the header, toolbar and transport) — not just the stage. */
.viz { display: grid; grid-template-columns: 1fr; }
.viz--has-side { grid-template-columns: 1fr minmax(270px, 360px); }
.viz--fullscreen.viz--has-side { grid-template-columns: 1fr; }   /* sidebar hidden in fullscreen */
.viz__main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* Header — airy and friendly; no hard divider rule. */
.viz__header { padding: clamp(20px, 3vw, 32px) clamp(22px, 5vw, 56px) 8px; border-bottom: 0; }
.viz__title { font-size: clamp(22px, 2.7vw, 31px); font-weight: 800; letter-spacing: -.022em; gap: 14px; }
/* Controls live inline in the title row, pushed to the RIGHT edge (Back stays left). */
.viz .viz__controls { position: static; gap: 8px; margin-left: auto; }
.viz__title .viz__back, .viz__title .viz__ctrl { width: 40px; height: 38px; }
.viz__back, .viz__ctrl { border-radius: 12px; background: var(--surface); }
.viz__diff { font-size: 13px; font-weight: 700; padding: 5px 15px; }
.viz__tag { font-size: 12px; padding: 5px 13px; background: var(--surface); }
.viz__desc { font-size: 15px; line-height: 1.55; }

/* Toolbar — soft, rounded, sentence-case labels (no shouty uppercase). */
.viz .toolbar { gap: 12px 14px; padding: 8px clamp(22px, 5vw, 56px) 14px; border-bottom: 0; }
.viz .field__label { text-transform: none; letter-spacing: 0; font-size: 12px; font-weight: 600; color: var(--text-dim); }
.viz .btn { border-radius: 12px; font-weight: 700; }
.viz .select, .viz .input { border-radius: 12px; }
.viz .segmented { border-radius: 14px; padding: 4px; }
.viz .segmented__btn { border-radius: 10px; }

/* Body — the interactive becomes a soft hero card with room to breathe. */
.viz__body { padding: 6px clamp(16px, 4vw, 44px) clamp(16px, 2.6vw, 26px); gap: clamp(16px, 2vw, 24px); }
.viz__body--with-side { grid-template-columns: 1fr minmax(264px, 348px); }
.viz .stage {
  border-radius: 24px; border: 1px solid var(--border);
  background:
    radial-gradient(var(--grid-line) 1.3px, transparent 1.3px) 0 0 / 30px 30px,
    var(--surface);
  box-shadow: var(--shadow-sm);
}

/* Side — ONE rounded rail in its own grid column, floating the FULL page height;
   panels become flat sections divided by hairlines. */
.viz .side {
  align-self: stretch; min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-gutter: stable;
  margin: clamp(16px, 2.6vw, 26px) clamp(16px, 4vw, 44px) clamp(16px, 2.6vw, 26px) 0;
  border-left: 0; padding: 6px; gap: 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-sm);
}
/* Don't let a tall, overflowing rail compress its children (flex-shrink would
   squash min-height items like .status, spilling their text). Keep natural
   heights and scroll instead; break long words rather than overflow. */
.viz .side > * { flex-shrink: 0; }
/* Let sections shrink to the rail width (so wide content doesn't push the whole
   sidebar sideways). Only the code block scrolls horizontally — within itself. */
.viz .side .panel, .viz .side .panel__body { min-width: 0; }
.viz .side .pseudocode { overflow-x: auto; max-width: 100%; overscroll-behavior-x: contain; }
.viz .side .status, .viz .side .panel__body, .viz .side .legend__item { overflow-wrap: break-word; min-width: 0; }
.viz .side .panel { border: 0; border-radius: 12px; background: transparent; box-shadow: none; }
.viz .side .panel:not(:last-child) { border-bottom: 1px solid var(--border); border-radius: 0; }
.viz .panel__head { text-transform: none; letter-spacing: 0; font-size: 13px; font-weight: 700; color: var(--text); padding: 13px 16px; }
.viz .panel__body { padding: 15px 16px; }
/* free-standing pills/status inside the rail need contrast against the rail surface */
.viz .side .stat-pill, .viz .side .status { border-radius: 14px; background: var(--surface-2); }

/* Transport — a friendly floating bar with a big round play button. */
.viz .transport {
  margin: 0 clamp(16px, 4vw, 44px) clamp(16px, 2.6vw, 26px); padding: 11px 14px;
  border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); box-shadow: var(--shadow-sm); backdrop-filter: none;
}
.viz .transport__btn { border-radius: 12px; }
.viz .transport__play { width: 54px; height: 54px; border-radius: 50%; }
.viz .scrubber { height: 8px; }

/* Fullscreen — drop the card insets so the interactive fills the screen. */
.viz--fullscreen .viz__body { padding: 0; gap: 0; }
.viz--fullscreen .stage { border-radius: 0; border: 0; box-shadow: none; }
.viz--fullscreen .transport { margin: 0; border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0; }
