/* ===========================================================================
   Codes.Live — layout.css
   App shell, sidebar, topbar, home landing.
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: 1fr;            /* sidebar is an overlay drawer, hidden by default */
  height: 100vh;
  height: 100dvh;
  position: relative;
  background:
    radial-gradient(1200px 700px at 12% -8%, var(--bg-grad-1), transparent 55%),
    radial-gradient(1100px 800px at 105% 10%, var(--bg-grad-2), transparent 50%),
    var(--bg);
}

/* ---------------------------------------------------------------- Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: fixed; inset: 0 auto 0 0;
  width: min(86vw, var(--sidebar-w));
  transform: translateX(-102%);
  transition: transform var(--dur) var(--ease);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(18px);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 40;
}
.app.sidebar-open .sidebar { transform: none; }
.app.sidebar-open .sidebar-scrim { opacity: 1; visibility: visible; pointer-events: auto; }
.sidebar__brand {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--topbar-h); padding: 0 18px;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: -.03em; }
.brand__mark { display: grid; place-items: center; filter: drop-shadow(0 4px 12px rgba(99,102,241,.4)); }
.brand__accent { color: var(--cyan); }
.sidebar__close { display: grid; }

.sidebar__search {
  position: relative; margin: 14px 14px 8px; display: flex; align-items: center;
}
.sidebar__search-icon { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.sidebar__search input {
  width: 100%; padding: 9px 12px 9px 36px; 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);
}
.sidebar__search input::placeholder { color: var(--muted); }
.sidebar__search input:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px color-mix(in srgb, var(--indigo) 22%, transparent); }
.sidebar__kbd {
  position: absolute; right: 10px; font-size: 11px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; pointer-events: none;
}

.nav { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 10px 16px; }
.nav__group-label {
  font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted); padding: 16px 10px 7px;
}
.nav__item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: 10px; color: var(--text-dim);
  font-size: 13.5px; font-weight: 500; transition: background var(--dur), color var(--dur);
  position: relative;
}
.nav__item:hover { background: var(--surface-2); color: var(--text); }
.nav__item.is-active { background: color-mix(in srgb, var(--indigo) 16%, transparent); color: var(--text); }
.nav__item.is-active::before {
  content: ""; position: absolute; left: -10px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 18px; border-radius: 4px; background: var(--accent-gradient);
}
.nav__item-icon { width: 20px; height: 20px; display: grid; place-items: center; opacity: .9; flex-shrink: 0; }
.nav__item-icon svg { width: 18px; height: 18px; }
.nav__empty { color: var(--muted); font-size: 13px; padding: 18px 12px; text-align: center; }

.sidebar__footer {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.sidebar__footer-text { font-size: 11px; color: var(--muted); line-height: 1.3; }

.theme-toggle {
  position: relative; width: 46px; height: 26px; border-radius: 99px; flex-shrink: 0;
  background: var(--surface-2); border: 1px solid var(--border); transition: background var(--dur);
}
.theme-toggle::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--accent-gradient); transition: transform var(--dur) var(--ease-bounce);
}
:root[data-theme="light"] .theme-toggle::after { transform: translateX(20px); }
.theme-toggle__icon { position: absolute; top: 50%; transform: translateY(-50%); font-size: 12px; line-height: 1; }
.theme-toggle__icon--sun { right: 6px; opacity: .55; }
.theme-toggle__icon--moon { left: 6px; opacity: .55; }

/* Scrim must never be a grid item (it would steal a grid column and wrap .main). */
.sidebar-scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity var(--dur); z-index: 35;
}

/* ---------------------------------------------------------------- Main */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  position: relative;
  display: flex; align-items: center; gap: 14px; height: var(--topbar-h);
  padding: 0 22px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 60%, transparent);
  backdrop-filter: blur(14px); z-index: 30; flex-shrink: 0;
}
.topbar__menu { display: none; }
/* On a visualization page the app top bar is unnecessary — the demo has its own
   back button + controls — so hide it there. */
.app.is-viz .topbar { display: none; }
.topbar__brand { flex: 0 0 auto; margin-right: 4px; text-decoration: none; }
.topbar__spacer { flex: 1; }
.topbar__link { font-size: 13px; color: var(--muted); transition: color var(--dur); }
.topbar__link:hover { color: var(--text); }

.breadcrumb { display: flex; align-items: center; gap: 8px; font-size: 14px; min-width: 0; }
.breadcrumb a { color: var(--muted); transition: color var(--dur); }
/* .breadcrumb a:hover { color: var(--text); } */
.breadcrumb__sep { color: var(--muted); opacity: .6; }
.breadcrumb__current { font-weight: 600; font-size: 1.1rem;  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.view { flex: 1; min-height: 0; overflow-y: auto; position: relative; }
.view:focus { outline: none; }

/* ---------------------------------------------------------------- Home */
.home { animation: fade-in .5s var(--ease); }
.hero {
  position: relative; overflow: hidden;
  padding: clamp(24px, 3vw, 64px) clamp(22px, 5vw, 64px) clamp(24px, 3vw, 64px);
  border-bottom: 1px solid var(--border);
}
.hero__glow {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(560px 320px at 78% -10%, color-mix(in srgb, var(--indigo) 14%, transparent), transparent 60%),
    radial-gradient(620px 360px at 8% 120%, color-mix(in srgb, var(--indigo) 8%, transparent), transparent 60%);
}
.hero__inner { position: relative; max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; text-align: center; }
.hero__badge {
  display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600;
  color: var(--text-dim); padding: 6px 13px; border: 1px solid var(--border);
  border-radius: 99px; background: var(--surface-2); margin-bottom: 22px;
}
.hero__badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c-sorted); box-shadow: 0 0 10px var(--c-sorted); }
.hero h1 { font-size: clamp(24px, 4vw, 54px); font-weight: 800; line-height: 1.04; letter-spacing: -.035em; }
.hero p { margin: 16px auto 0; font-size: clamp(15px, 2.2vw, 19px); color: var(--text-dim); max-width: 620px; }
.hero__accent { color: var(--indigo); }
.hero__legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 20px; margin-top: 24px; }
.hero__legend span { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--text-dim); }
.hero__legend i { width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 16%, transparent); }
.hero__legend .is-easy   { color: var(--easy); }
.hero__legend .is-medium { color: var(--medium); }
.hero__legend .is-hard   { color: var(--hard); }
.hero__legend i { background: currentColor; }
.hero__legend b { color: var(--text); font-weight: 700; }

/* Brand mark in the top bar (LeetCode/HackerRank: logo top-left). */
.topbar__brand { display: inline-flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 700; letter-spacing: -.02em; color: var(--text); white-space: nowrap; }
.topbar__logo { flex: 0 0 auto; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-gradient); color: var(--on-accent); box-shadow: 0 4px 12px -4px color-mix(in srgb, var(--brand) 60%, transparent); }
.topbar__logo svg { width: 17px; height: 17px; }
.topbar__brand b { color: var(--indigo); font-weight: 700; }
.home__search-band { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; margin-top: 30px; }
.home__search {
  position: relative; display: flex; align-items: center; gap: 14px;
  width: 100%; max-width: 680px; height: 64px; padding: 0 22px;
  background: var(--elevated); border: 1px solid var(--border-strong); border-radius: 18px;
  box-shadow: 0 12px 34px -18px rgba(0,0,0,.55);
  transition: border-color .15s, box-shadow .15s;
}
.home__search:focus-within { border-color: var(--indigo); box-shadow: 0 0 0 4px color-mix(in srgb, var(--indigo) 20%, transparent), 0 12px 34px -18px rgba(0,0,0,.55); }
.home__search-icon { color: var(--muted); display: grid; place-items: center; flex: 0 0 auto; }
.home__search:focus-within .home__search-icon { color: var(--indigo); }
.home__search input { flex: 1; min-width: 0; height: 100%; background: none; border: none; outline: none; color: var(--text); font-size: 18px; font-weight: 500; font-family: inherit; }
.home__search input::placeholder { color: var(--muted); font-weight: 400; }
.home__search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.home__search-kbd { flex: 0 0 auto; font-family: var(--font-mono); font-size: 12px; color: var(--muted); width: 24px; height: 24px; display: grid; place-items: center; border: 1px solid var(--border-strong); border-radius: 7px; background: var(--surface); }
.home__search-clear { flex: 0 0 auto; width: 26px; height: 26px; border: none; background: none; cursor: pointer; color: var(--muted); border-radius: 50%; display: grid; place-items: center; font-size: 13px; line-height: 1; }
.home__search-clear:hover { color: var(--text); background: var(--border); }
.home__search-count { font-size: 12.5px; color: var(--muted); font-family: var(--font-mono); text-align: center; }

/* Search box relocated into the top-bar header on the home page. */
.topbar__search { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(540px, 52vw); min-width: 0; display: flex; align-items: center; z-index: 1; }
.topbar__search:empty { display: none; }
.topbar__search .home__search { width: 100%; max-width: none; height: 40px; padding: 0 14px; gap: 10px; border-radius: 11px; box-shadow: none; }
.topbar__search .home__search input { font-size: 14.5px; }
.home__main > .home__search-count { text-align: left; margin: 0 0 14px; min-height: 15px; }
@media (max-width: 600px) {
   .topbar__search { display: none; }
}
.hero__stats { display: flex; flex-wrap: wrap; gap: 30px; margin-top: 34px; }
.hero__stat { display: flex; flex-direction: column; }
.hero__stat b { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.hero__stat span { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

.home__body {
  display: grid; grid-template-columns: 196px minmax(0, 1fr) 272px; gap: clamp(18px, 2.6vw, 38px);
  padding: clamp(22px, 3vw, 44px) clamp(20px, 4vw, 56px) 80px; align-items: start;
  padding-bottom: 20px;
}
.home__main { min-width: 0; }

/* Left table-of-contents rail: a vertical spine line with the section in view
   enlarged. The grow uses transform: scale (GPU, no reflow blur) so it reads as
   a crisp, quick snap rather than a slow font-size tween. The grey spine is a
   background gradient (not a border) so the bold current-marker — a pseudo on
   the same x — sits inside the padding box and is never clipped by overflow. */
.home__toc { position: sticky; top: 16px; align-self: start; display: flex; flex-direction: column;
  max-height: calc(100vh - 32px); overflow-y: auto; padding-left: 18px;
  background: linear-gradient(var(--border), var(--border)) 0 0 / 2px 100% no-repeat; }
.home__toc-link {
  position: relative; display: block; width: 100%; text-align: left;
  padding: 6px 4px; background: none; border: 0; cursor: pointer; color: var(--muted); font-family: inherit;
  transition: color .14s ease;
}
.home__toc-link:hover { color: var(--text-dim); }
.home__toc-link.is-current { color: var(--text); }
/* bold accent segment marking the current section, sitting on the spine line —
   mirrors the sidebar's active-nav bar (var(--accent-gradient)). */
.home__toc-link.is-current::before {
  content: ""; position: absolute; left: -18px; top: 2px; bottom: 2px; width: 4px;
  border-radius: 4px; background: var(--accent-gradient);
  box-shadow: 0 0 10px -1px color-mix(in srgb, var(--text) 45%, transparent);
}
.home__toc-name {
  display: block; font-size: 17px; font-weight: 700; line-height: 1.2; letter-spacing: -.012em;
  transform: scale(.706); transform-origin: left center;
  transition: transform .16s cubic-bezier(.22,.68,.32,1), color .14s ease;
}
.home__toc-link.is-current .home__toc-name { transform: scale(1); }
.cat { margin-bottom: 30px; scroll-margin-top: 20px; }
.cat__head { display: flex; align-items: center; gap: 11px; margin-bottom: 12px; }
.cat__step {
  flex: 0 0 auto; font-family: var(--font-mono); font-size: 12px; font-weight: 700;
  color: var(--indigo); background: color-mix(in srgb, var(--indigo) 13%, transparent);
  min-width: 28px; height: 24px; display: grid; place-items: center; padding: 0 8px;
  border-radius: 7px; letter-spacing: .02em;
}
.cat__title { font-size: 19px; font-weight: 700; letter-spacing: -.02em; }
.cat__count { font-size: 12.5px; color: var(--muted); font-family: var(--font-mono); }
.cat__line { flex: 1; height: 1px; background: var(--border); }

/* ---- problem list (LeetCode / HackerRank table) ---- */
.list {
  display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  background: var(--surface); box-shadow: var(--shadow-sm);
}
.row {
  display: flex; align-items: center; gap: 13px;
  padding: 10px 16px; border: 0; border-bottom: 1px solid var(--border);
  cursor: pointer; text-align: left; color: var(--text);
  transition: background .12s ease;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: color-mix(in srgb, var(--indigo) 7%, var(--surface)); }
.row.is-highlighted { background: color-mix(in srgb, var(--indigo) 13%, var(--surface)); box-shadow: inset 3px 0 0 var(--indigo); }
.row__icon {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--row-accent, var(--indigo)) 14%, var(--surface-2));
  color: var(--row-accent, var(--indigo));
}
.row__icon svg { width: 16px; height: 16px; }
.row__title { font-size: 14.5px; font-weight: 500; letter-spacing: -.01em; flex: 0 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color .12s ease; }
.row:hover .row__title, .row.is-highlighted .row__title { color: var(--indigo); }
.row__tag {
  flex: 0 0 auto; font-size: 11px; font-weight: 500; color: var(--text-dim);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 2px 9px; border-radius: 99px; white-space: nowrap;
}
.row__spacer { flex: 1 1 auto; }
.row__diff {
  flex: 0 0 auto; font-size: 12px; font-weight: 600; padding: 3px 0; border-radius: 99px;
  white-space: nowrap; width: 68px; text-align: center;
}
.row__diff[data-diff="intro"]   { color: var(--intro);   background: color-mix(in srgb, var(--intro) 14%, transparent); }
.row__diff[data-diff="easy"]   { color: var(--easy);   background: color-mix(in srgb, var(--easy) 14%, transparent); }
.row__diff[data-diff="medium"] { color: var(--medium); background: color-mix(in srgb, var(--medium) 16%, transparent); }
.row__diff[data-diff="hard"]   { color: var(--hard);   background: color-mix(in srgb, var(--hard) 14%, transparent); }
.row__go { flex: 0 0 auto; color: var(--muted); opacity: 0; transition: opacity var(--dur), transform var(--dur), color var(--dur); display: grid; place-items: center; }
.row__go svg { width: 16px; height: 16px; }
.row:hover .row__go, .row.is-highlighted .row__go { opacity: .85; transform: translateX(2px); color: var(--indigo); }

/* ---- tag filter sidebar ---- */
.home__aside { position: sticky; top: 16px; align-self: start; }
.tagfilter {
  display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 36px);
  border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); padding: 14px;
}
.tagfilter__title { display: flex; align-items: center; justify-content: space-between; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); }
.tagfilter__clear { border: none; background: none; cursor: pointer; color: var(--indigo); font-size: 11.5px; font-weight: 600; font-family: inherit; padding: 0; }
.tagfilter__clear:hover { text-decoration: underline; }
.tagfilter__search {
  width: 100%; height: 32px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text); padding: 0 10px; font-size: 12.5px; font-family: inherit; outline: none;
}
.tagfilter__search:focus { border-color: var(--indigo); }
.tagfilter__active { display: flex; flex-wrap: wrap; gap: 6px; }
.tagfilter__active:empty { display: none; }
.tagfilter__list { display: flex; flex-wrap: wrap; gap: 6px; overflow-y: auto; min-height: 0; padding-right: 2px; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; font-family: inherit;
  padding: 4px 9px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-dim); cursor: pointer; white-space: nowrap; transition: border-color var(--dur), color var(--dur);
}
.tag-chip:hover { border-color: var(--border-strong); color: var(--text); }
.tag-chip.is-active { background: var(--accent-gradient); color: var(--on-accent); border-color: transparent; }
.tag-chip__count { font-family: var(--font-mono); font-size: 10px; opacity: .7; }
.tag-chip__x { font-weight: 700; font-size: 13px; line-height: 1; }

.home__empty { padding: 60px; text-align: center; color: var(--muted); }

@media (max-width: 1200px) {
  .home__body { grid-template-columns: minmax(0, 1fr) 272px; }
  .home__toc { display: none; }
}
@media (max-width: 1080px) {
  .home__body { grid-template-columns: 1fr; }
  .home__toc { display: none; }
  .home__aside { position: static; }
  .tagfilter { max-height: none; }
  .tagfilter__list { max-height: 210px; }
}

/* ---------------------------------------------------------------- Responsive */
@media (max-width: 900px) {
  .row__tag { display: none; }
  .row__go { display: none; }
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, var(--sidebar-w));
    transform: translateX(-102%); transition: transform var(--dur) var(--ease);
  }
  .app.sidebar-open .sidebar { transform: none; }
  .sidebar__close { display: grid; }
  .topbar__menu { display: grid; }
  .app.sidebar-open .sidebar-scrim { opacity: 1; visibility: visible; pointer-events: auto; }
}
