/* ==========================================================================
   Python cheatsheet (/python) — standalone from the Bootstrap theme so the
   page stays dense, fast and scannable.
   ========================================================================== */

:root {
  --bg:            #ffffff;
  --bg-alt:        #f7f7f5;
  --surface:       #ffffff;
  --surface-alt:   #fafaf9;
  --text:          #1f2328;
  --text-strong:   #111318;
  --muted:         #6e7781;
  --border:        #e4e4e1;
  --border-soft:   #eeeeec;
  --code-bg:       #f8f8f6;
  --accent:        #c79100;
  --accent-hover:  #a07500;
  --accent-soft:   rgba(199, 145, 0, 0.12);
  --mark-bg:       #ffe28a;
  --mark-text:     #3d2f00;
  --hit-bg:        rgba(199, 145, 0, 0.14);
  --shadow:        0 1px 2px rgba(16, 18, 22, 0.05), 0 6px 20px rgba(16, 18, 22, 0.05);
  --topbar-h:      58px;

  /* syntax */
  --t-comment:   #6a737d;
  --t-string:    #0a5b3d;
  --t-keyword:   #cf222e;
  --t-constant:  #0550ae;
  --t-builtin:   #0550ae;
  --t-call:      #6f42c1;
  --t-defname:   #6f42c1;
  --t-classname: #953800;
  --t-number:    #0550ae;
  --t-decorator: #953800;
  --t-self:      #953800;
  --t-magic:     #6f42c1;
  --t-table:     #953800;
  --t-key:       #0550ae;
  --t-command:   #6f42c1;
  --t-flag:      #0550ae;
}

html[data-theme="dark"] {
  --bg:            #131316;
  --bg-alt:        #18181b;
  --surface:       #1b1b1f;
  --surface-alt:   #202025;
  --text:          #e4e4e7;
  --text-strong:   #fafafa;
  --muted:         #a1a1aa;
  --border:        #2e2e34;
  --border-soft:   #26262b;
  --code-bg:       #17171a;
  --accent:        #ffc800;
  --accent-hover:  #fed136;
  --accent-soft:   rgba(255, 200, 0, 0.14);
  --mark-bg:       #6a5000;
  --mark-text:     #fff3c4;
  --hit-bg:        rgba(255, 200, 0, 0.10);
  --shadow:        0 1px 2px rgba(0, 0, 0, 0.4);

  --t-comment:   #7f9f6f;
  --t-string:    #ce9178;
  --t-keyword:   #c586c0;
  --t-constant:  #569cd6;
  --t-builtin:   #4ec9b0;
  --t-call:      #dcdcaa;
  --t-defname:   #dcdcaa;
  --t-classname: #4ec9b0;
  --t-number:    #b5cea8;
  --t-decorator: #dcdcaa;
  --t-self:      #9cdcfe;
  --t-magic:     #9cdcfe;
  --t-table:     #4ec9b0;
  --t-key:       #9cdcfe;
  --t-command:   #dcdcaa;
  --t-flag:      #9cdcfe;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg:            #131316;
    --bg-alt:        #18181b;
    --surface:       #1b1b1f;
    --surface-alt:   #202025;
    --text:          #e4e4e7;
    --text-strong:   #fafafa;
    --muted:         #a1a1aa;
    --border:        #2e2e34;
    --border-soft:   #26262b;
    --code-bg:       #17171a;
    --accent:        #ffc800;
    --accent-hover:  #fed136;
    --accent-soft:   rgba(255, 200, 0, 0.14);
    --mark-bg:       #6a5000;
    --mark-text:     #fff3c4;
    --hit-bg:        rgba(255, 200, 0, 0.10);
    --shadow:        0 1px 2px rgba(0, 0, 0, 0.4);

    --t-comment:   #7f9f6f;
    --t-string:    #ce9178;
    --t-keyword:   #c586c0;
    --t-constant:  #569cd6;
    --t-builtin:   #4ec9b0;
    --t-call:      #dcdcaa;
    --t-defname:   #dcdcaa;
    --t-classname: #4ec9b0;
    --t-number:    #b5cea8;
    --t-decorator: #dcdcaa;
    --t-self:      #9cdcfe;
    --t-magic:     #9cdcfe;
    --t-table:     #4ec9b0;
    --t-key:       #9cdcfe;
    --t-command:   #dcdcaa;
    --t-flag:      #9cdcfe;
  }
}

/* --------------------------------------------------------------- base --- */

*, *::before, *::after { box-sizing: border-box; }

/* `hidden` has to beat the flex displays below */
[hidden] { display: none !important; }

body.cheatsheet {
  margin: 0;
  background: var(--bg-alt);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body.cheatsheet a { color: var(--accent); text-decoration: none; }
body.cheatsheet a:hover { color: var(--accent-hover); text-decoration: underline; }

kbd {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-alt);
  color: var(--muted);
}

mark {
  background: var(--mark-bg);
  color: var(--mark-text);
  border-radius: 3px;
  padding: 0 1px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 10px 16px;
  background: var(--surface);
  z-index: 100;
}
.skip-link:focus { left: 8px; top: 8px; }

/* ------------------------------------------------------------- topbar --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.01em;
  color: var(--text-strong) !important;
  white-space: nowrap;
}
.brand:hover { color: var(--accent) !important; text-decoration: none; }

.search-wrap {
  position: relative;
  flex: 1 1 auto;
  max-width: 460px;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 11px;
  width: 15px;
  height: 15px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

#search {
  width: 100%;
  height: 36px;
  padding: 0 66px 0 34px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}
#search::-webkit-search-cancel-button { display: none; }
#search::placeholder { color: var(--muted); }
#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface);
}

.search-hint { position: absolute; right: 10px; pointer-events: none; }
.search-wrap:focus-within .search-hint { display: none; }

.search-clear {
  position: absolute;
  right: 8px;
  width: 22px;
  height: 22px;
  padding: 0;
  font-size: 17px;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}
.search-clear:hover { color: var(--text); background: var(--border-soft); }

.topbar-links {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}
.topbar-links a {
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted) !important;
  border-radius: 6px;
}
.topbar-links a:hover {
  color: var(--text-strong) !important;
  background: var(--surface-alt);
  text-decoration: none;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--muted);
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}
.icon-btn:hover { color: var(--text-strong); background: var(--surface-alt); border-color: var(--border); }
.icon-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] #theme-toggle .icon-sun { display: block; }
html[data-theme="dark"] #theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) #theme-toggle .icon-sun { display: block; }
  html:not([data-theme="light"]) #theme-toggle .icon-moon { display: none; }
}

.nav-toggle { display: none; }

/* --------------------------------------------------------------- page --- */

.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: flex-start;
  gap: 40px;
}

/* ------------------------------------------------------------ sidebar --- */

.sidebar {
  flex: 0 0 232px;
  position: sticky;
  top: var(--topbar-h);
  align-self: flex-start;
  max-height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 28px 0 40px;
}

.nav-group + .nav-group { margin-top: 26px; }

.nav-title {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.sidebar ul { list-style: none; margin: 0; padding: 0; }

.sidebar a {
  display: block;
  padding: 4px 10px 4px 11px;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--muted) !important;
  border-left: 2px solid var(--border-soft);
  border-radius: 0 5px 5px 0;
}
.sidebar a:hover {
  color: var(--text-strong) !important;
  background: var(--surface-alt);
  text-decoration: none;
}
.sidebar a.active {
  color: var(--text-strong) !important;
  border-left-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}
.sidebar li.hidden { display: none; }
.nav-group.hidden { display: none; }

/* --------------------------------------------------------------- main --- */

#content {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 940px;
  padding: 36px 0 80px;
}

.hero { margin-bottom: 34px; }

.hero h1 {
  margin: 0 0 8px;
  font-size: 34px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-strong);
}

.hero-meta { margin: 0; font-size: 13px; color: var(--muted); }

.group-head {
  margin: 46px 0 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.group-head:first-of-type { margin-top: 8px; }
.group-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}
.group-head p { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.group-head.hidden { display: none; }

/* -------------------------------------------------------------- cards --- */

.card {
  margin: 0 0 18px;
  padding: 20px 22px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}
.card.hidden { display: none; }

.card-title {
  margin: 0 0 14px;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text-strong);
}
.card-title a {
  float: right;
  margin-left: 10px;
  font-size: 15px;
  color: var(--border) !important;
  font-weight: 400;
}
.card:hover .card-title a { color: var(--muted) !important; }
.card-title a:hover { color: var(--accent) !important; text-decoration: none; }

.block { margin: 0 0 14px; }
.block.hidden { display: none; }

/* --------------------------------------------------------------- code --- */

.block-code { position: relative; }

.block-code pre {
  margin: 0;
  padding: 12px 0;
  overflow-x: auto;
  background: var(--code-bg);
  border: 1px solid var(--border-soft);
  border-radius: 9px;
}

.block-code code {
  display: block;
  min-width: max-content;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12.8px;
  line-height: 1.65;
  tab-size: 4;
  color: var(--text);
}

.cl {
  display: block;
  padding: 0 16px;
  min-height: 1.65em;
  border-left: 2px solid transparent;
}
.cl.dim { opacity: 0.3; }
.cl.hit { background: var(--hit-bg); border-left-color: var(--accent); }

.copy {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 2;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s, color .12s, border-color .12s;
}
.block-code:hover .copy,
.copy:focus-visible { opacity: 1; }
.copy:hover { color: var(--text-strong); border-color: var(--muted); }
.copy.done { opacity: 1; color: var(--accent); border-color: var(--accent); }
@media (hover: none) { .copy { opacity: 1; } }

/* syntax colours */
.t-comment   { color: var(--t-comment); font-style: italic; }
.t-string    { color: var(--t-string); }
.t-keyword   { color: var(--t-keyword); }
.t-constant  { color: var(--t-constant); }
.t-builtin   { color: var(--t-builtin); }
.t-call      { color: var(--t-call); }
.t-defname   { color: var(--t-defname); font-weight: 600; }
.t-classname { color: var(--t-classname); font-weight: 600; }
.t-number    { color: var(--t-number); }
.t-decorator { color: var(--t-decorator); }
.t-self      { color: var(--t-self); font-style: italic; }
.t-magic     { color: var(--t-magic); }
.t-table     { color: var(--t-table); font-weight: 600; }
.t-key       { color: var(--t-key); }
.t-command   { color: var(--t-command); font-weight: 600; }
.t-flag      { color: var(--t-flag); }

/* -------------------------------------------------------------- notes --- */

.block-notes ul { list-style: none; margin: 0; padding: 0; }

.block-notes li {
  position: relative;
  margin: 0 0 7px;
  padding-left: 17px;
  font-size: 14.5px;
  color: var(--text);
}
.block-notes li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.62em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.55;
}
.block-notes li.hidden { display: none; }

.block-para { font-size: 14.5px; color: var(--text); }

.card-body code {
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.87em;
  background: var(--code-bg);
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  color: var(--text-strong);
}
.card-body strong { color: var(--text-strong); font-weight: 650; }

/* -------------------------------------------------------------- table --- */

.block-table { overflow-x: auto; }

.block-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.block-table th,
.block-table td {
  padding: 7px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border-soft);
}
.block-table th {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom-color: var(--border);
}
.block-table tbody tr:last-child td { border-bottom: 0; }
.block-table tbody tr:hover { background: var(--surface-alt); }

/* ------------------------------------------------------------ results --- */

.results-bar {
  position: sticky;
  top: calc(var(--topbar-h) + 8px);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
}
.results-bar strong { color: var(--text-strong); }
.results-bar button {
  margin-left: auto;
  padding: 3px 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.results-bar button:hover { color: var(--text-strong); border-color: var(--muted); }

.no-results {
  padding: 28px 20px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 12px;
}

.page-footer {
  margin-top: 48px;
  padding-top: 18px;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

.to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.to-top:hover { color: var(--text-strong); border-color: var(--muted); }
.to-top svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* --------------------------------------------------------- responsive --- */

@media (max-width: 1040px) {
  .topbar-links a { display: none; }
  .nav-toggle { display: inline-flex; }

  .page { display: block; padding: 0 16px; }

  .sidebar {
    display: none;
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    max-height: calc(100vh - var(--topbar-h));
    padding: 18px 20px 30px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 35;
  }
  .sidebar.open { display: block; }

  #content { max-width: none; padding-top: 26px; }
}

@media (max-width: 620px) {
  .brand { display: none; }
  .topbar-inner { padding: 0 12px; gap: 10px; }
  .search-wrap { max-width: none; }
  .hero h1 { font-size: 27px; }
  .card { padding: 16px 14px 6px; border-radius: 10px; }
  .block-code code { font-size: 12px; }
  .cl { padding: 0 12px; }
}

/* -------------------------------------------------------------- print --- */

@media print {
  .topbar, .sidebar, .to-top, .copy, .results-bar, .card-title a { display: none !important; }
  body.cheatsheet { background: #fff; color: #000; font-size: 11px; }
  .page { display: block; padding: 0; }
  #content { max-width: none; padding: 0; }
  .card { break-inside: avoid; box-shadow: none; margin-bottom: 10px; }
  .block-code pre { break-inside: avoid; }
}
