* { margin: 0; padding: 0; box-sizing: border-box; }
html {
  background-color: #f0efe8;
}
html::after {
  content: '';
  position: fixed;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background:
    linear-gradient(90deg, rgba(48,105,152,1) 0%, rgba(48,105,152,0) 50%),
    linear-gradient(270deg, rgba(255,212,59,1) 0%, rgba(255,212,59,0) 50%);
  transform: rotate(var(--bg-rotate, 0deg));
  filter: hue-rotate(var(--bg-hue, 0deg));
  transition: transform var(--bg-duration, 0.6s) ease-in-out, filter var(--bg-duration, 0.6s) ease-in-out;
  animation: var(--bg-anim, none);
  animation-play-state: var(--bg-play-state, running);
  z-index: -1;
  pointer-events: none;
}
body {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  color: #2a2a2a;
  min-height: 100vh;
  padding: 2rem;
  max-width: 1000px;
  margin: 0 auto;
  position: relative;
}
body > * { position: relative; z-index: 1; }

h1 { color: #306998; font-size: 1.6rem; margin-bottom: 0.3rem; }
.subtitle { color: #444; font-size: 1rem; margin-bottom: 1.5rem; font-weight: normal; display: inline-flex; align-items: center; gap: 0.6rem; }
.subtitle a { color: #306998; text-decoration: none; }
.subtitle a:hover { color: #FFD43B; }

/* GitHub link inside the header: outlined button-style so it doesn't read like sentence continuation */
.github-link {
  display: inline-block;
  margin-left: 0.9rem;
  padding: 0.12rem 0.6rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  color: #2a2a2a;
  text-decoration: none;
  font-size: 0.85rem;
  background: rgba(255,255,255,0.6);
  white-space: nowrap;
}
.github-link:hover { border-color: #306998; color: #306998; }

.input-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  align-items: center;
}
.input-row.hidden { display: none; }
input[type="text"] {
  background: #1a1e28;
  border: 2px solid #2a3040;
  color: #FFD43B;
  padding: 0.7rem 1rem;
  font-family: inherit;
  font-size: 1.2rem;
  width: 4rem;
  text-align: center;
  border-radius: 6px;
  transition: width 180ms ease, padding 180ms ease, text-align 180ms ease, font-size 140ms ease;
}
/* wide placeholder state: larger to show helper text, collapses after first char */
input[type="text"].wide {
  /* use the input 'size' attribute to precisely fit the placeholder; allow width to be governed by it */
  font-size: 0.75rem; /* smaller than the random button */
  width: auto !important;
  text-align: left;
  padding-left: 0.6rem;
}
input[type="text"].wide::placeholder { font-size: 0.75rem; color: #bfbfbf; }
/* make placeholder text greyer for initial state */
input[type="text"]::placeholder { color: #9e9e9e; }
input:focus { outline: none; border-color: #306998; box-shadow: 0 0 0 3px rgba(48,105,152,0.2); }
.btn {
  background: #1a1e28;
  border: 2px solid #2a3040;
  color: #FFD43B; /* brighter button text */
  padding: 0.7rem 1rem;
  font-family: inherit;
  font-size: 0.85rem;
  border-radius: 6px;
  cursor: pointer;
}
.btn:hover { border-color: #306998; }
.mode-toggle {
  display: inline-flex;
  border: 1px solid #ccc;
  border-radius: 6px;
  overflow: hidden;
  height: 36px;
}
.mode-opt {
  background: rgba(255,255,255,0.4);
  border: none;
  padding: 0 0.7rem;
  font-family: inherit;
  font-size: 0.8rem;
  color: #555;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.mode-opt:not(:last-child) { border-right: 1px solid #ccc; }
.mode-opt.active { background: #306998; color: #fff; }
.mode-opt:hover:not(.active) { background: rgba(48,105,152,0.1); }
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: #2a2a2a;
  font-size: 0.85rem;
  margin-left: 1rem;
  padding: 0 0.5rem; /* remove vertical padding */
  height: 36px; /* constrain box height so it's shorter */
  border: 1px solid #ddd;
  border-radius: 6px;
  background: rgba(255,255,255,0.6);
  line-height: 1; /* tighten line-height */
  box-sizing: border-box;
}
.toggle input { accent-color: #306998; margin: 0; width: 16px; height: 16px; transform: scale(0.95); }
.toggle label { cursor: pointer; }
.toggle input:checked + label { color: #306998; font-weight: 600; }

.result-wrapper {
  position: relative;
  margin-bottom: 2rem;
}
.result-wrapper.hidden { display: none; }
.result {
  background: #12151e;
  border: none;
  border-left: 4px solid #FFD43B;
  border-radius: 8px;
  padding: 1.2rem;
  display: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}
.result.visible { display: block; }
.result-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.8rem;
  color: #7a8ba8;
  font-size: 0.85rem;
  gap: 1rem;
}
.result-header #resultChar {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.result-header #resultMeta {
  flex-shrink: 0;
  text-align: right;
}
.result-expr {
  background: #0a0c12;
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  word-break: break-all;
  white-space: pre-wrap;
  line-height: 1.5;
  font-size: 0.85rem;
  color: #FFD43B;
  cursor: pointer;
  border: none;
}
.result-expr:hover { box-shadow: 0 0 0 2px #306998; }
@keyframes copied-flash {
  0%   { box-shadow: 0 0 0 2px #FFD43B; }
  60%  { box-shadow: 0 0 0 4px #FFD43B44; }
  100% { box-shadow: none; }
}
.result-expr.copied-flash { animation: copied-flash 0.5s ease-out forwards; }
.result-sidebar {
  position: absolute;
  top: 0;
  left: calc(100% + 0.6rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}
.step-counter {
  color: #3345d1;
  font-size: 1.1rem;
  font-weight: bold;
  white-space: nowrap;
  text-align: center;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.3);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.step-counter.active {
  opacity: 1;
  transform: scale(1);
}
.step-counter.bump {
  transform: scale(1.3);
}
@keyframes viz-glow {
  0%, 100% { box-shadow: 0 0 6px 1px rgba(126,200,227,0.3); }
  50%       { box-shadow: 0 0 14px 4px rgba(126,200,227,0.6); }
}
@keyframes viz-arrow-bounce {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50%       { transform: translateY(4px); opacity: 1; }
}
.viz-wrap {
  position: relative;
  display: none;
  flex-direction: column;
  align-items: center;
}
.viz-wrap.visible { display: flex; }
.viz-wrap.hide-arrow::after { display: none; }
.viz-wrap::after {
  content: '↑';
  position: absolute;
  top: calc(100% + 0.1rem);
  left: 0;
  right: 0;
  text-align: center;
  font-size: 3.5rem;
  line-height: 1;
  color: #7ec8e3;
  text-shadow: 0 0 6px rgba(0,0,0,0.8), 0 2px 4px rgba(0,0,0,0.6);
  animation: viz-arrow-bounce 1.2s ease-in-out infinite;
  pointer-events: none;
}
.visualize-btn {
  background: #1a1e28;
  border: 2px solid #7ec8e3;
  color: #7ec8e3;
  padding: 0.65rem 1.1rem;
  font-family: inherit;
  font-size: 0.88rem;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  animation: viz-glow 2s ease-in-out infinite;
}
.visualize-btn:hover {
  background: #7ec8e3;
  border-color: #7ec8e3;
  color: #12151e;
  animation: none;
  box-shadow: 0 0 16px rgba(126,200,227,0.5);
}
.result-expr .highlight {
  background: rgba(255, 212, 59, 0.3);
  padding: 0 2px;
  border-radius: 2px;
  animation: pulse 0.4s ease;
}
.result-expr .fade-in {
  color: #7ec8e3;
  animation: fadeIn 0.4s ease;
}
@keyframes pulse {
  0%, 100% { background: rgba(255, 212, 59, 0.3); }
  50% { background: rgba(255, 212, 59, 0.6); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.copied { color: #306998; font-size: 0.75rem; margin-top: 0.4rem; }

.graph-cta {
  display: block;
  text-align: center;
  padding: 1.2rem 2rem;
  margin: 1.5rem auto;
  max-width: 600px;
  background: linear-gradient(135deg, #306998 0%, #7ec8e3 100%);
  border: none;
  border-radius: 10px;
  color: #fff;
  font: bold 1.15rem/1.4 monospace;
  text-decoration: none;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}
.graph-cta:hover {
  box-shadow: 0 0 24px rgba(126, 200, 227, 0.4);
  transform: translateY(-2px);
}
.graph-cta-sub {
  display: block;
  font-weight: normal;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.7);
  margin-top: 0.3rem;
}

code {
  background: #1a1e28;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  color: #7ec8e3;
  font-size: 0.85rem;
  word-break: break-all;
}
.main-panel ol, .main-panel ul {
  padding-left: 1.5rem;
  font-size: 0.85rem;
  color: #555;
  line-height: 1.7;
}
.main-panel ol li, .main-panel ul li {
  margin-bottom: 0.4rem;
}
pre {
  background: #12151e;
  border: none;
  border-radius: 6px;
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.8rem;
  line-height: 1.7;
  color: #c0c8d8;
  margin: 0.8rem 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
th { text-align: left; color: #888; padding: 0.4rem 0.8rem; border-bottom: 1px solid #ddd; }
td { padding: 0.4rem 0.8rem; border-bottom: 1px solid #e8e8e0; }
td.num, th.num { text-align: center; font-variant-numeric: tabular-nums; }
tr.group-start td { border-top: 2px solid #bbb; }
tr.pair-second td { border-top: 1px dashed #ddd; }
.metric-tag {
  font-size: 0.72rem;
  background: #f0f0e8;
  border: 1px solid #ccc;
  border-radius: 3px;
  padding: 0 4px;
  color: #666;
  vertical-align: middle;
}

.op-table { margin: 0.5rem 0; }
.op-table td { padding: 0.3rem 0.8rem; font-size: 0.8rem; }
.op-table td:first-child { color: #306998; }
.op-table td:nth-child(2) { color: #555; }
.op-table td:nth-child(3) { color: #999; font-size: 0.75rem; }

/* Tabs */
.main-tabs {
  display: flex;
  gap: 0;
  border-bottom: none;
  margin-bottom: 0;
  position: relative;
}
.main-tabs::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.5), transparent);
}
.main-tab {
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
  color: #222; /* darker so labels stand out */
  cursor: pointer;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: none;
  font-family: inherit;
}
.main-tab:hover { color: #306998; }
.main-tab.active {
  color: #306998;
  background: #fff;
  border-color: #ddd;
  border-bottom-color: #fff;
  margin-bottom: -2px;
  font-weight: bold;
}
.main-panel {
  display: none;
  background: #fff;
  border: 1px solid #ddd;
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.main-panel.active { display: block; }
.main-panel p { color: #555; line-height: 1.7; font-size: 0.85rem; margin-bottom: 0.8rem; }
.main-panel p:last-child { margin-bottom: 0; }
.main-panel ul {
  color: #555;
  font-size: 0.85rem;
  line-height: 1.7;
  margin: 0 0 0.8rem 1.2rem;
}
.main-panel li { margin-bottom: 0.3rem; }
.main-panel strong { color: #306998; }
.note { color: #666; font-size: 0.8rem; margin-bottom: 0.5rem; }
.note-spaced { margin-bottom: 1.2rem; }

/* Tooltip (shared by .tip and .stat-card) */
.tiptext {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #12151e;
  color: #d0d4dc;
  padding: 0.4rem 0.7rem;
  border-radius: 4px;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 10;
  margin-bottom: 4px;
}
.tip {
  position: relative;
  border-bottom: 1px dotted #306998;
  cursor: help;
}
.tip:hover .tiptext, .stat-card:hover .tiptext { display: block; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1.2rem;
}
.stat-card {
  background: #12151e;
  border-radius: 6px;
  padding: 0.8rem;
  position: relative;
  cursor: help;
}
.stat-card .stat-val { color: #FFD43B; font-size: 1.2rem; margin-bottom: 0.2rem; font-weight: bold; }
.stat-card .stat-label { color: #7a8ba8; font-size: 0.75rem; }

/* Strategy tags */
.strategies { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
.strategy-tag {
  background: #1a1e28;
  padding: 0.2rem 0.6rem;
  border-radius: 3px;
  font-size: 0.75rem;
  color: #8a94a8;
}
.strategy-tag .count { color: #FFD43B; font-weight: bold; }
.strategy-sort-bar { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.7rem; }
.strategy-sort-btn {
  font-family: inherit; font-size: 0.75rem; cursor: pointer;
  padding: 0.2rem 0.6rem; border-radius: 4px;
  background: none; border: 1px solid #ccc; color: #888;
}
.strategy-sort-btn:hover { border-color: #306998; color: #306998; }
.strategy-sort-btn.active { border-color: #306998; color: #306998; font-weight: 600; }

.divider { border-top: 2px solid #c8c8be; margin: 1.2rem 0; }

.openable-frame { margin: 1.2rem 0; border-top: 3px solid #999; border-bottom: 3px solid #999; padding: 0.6rem 0; }
.openable-frame summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.openable-frame summary::-webkit-details-marker { display: none; }
.openable-frame summary::before {
  content: '▶';
  font-size: 0.65rem;
  color: #888;
  transition: transform 0.15s;
  display: inline-block;
}
.openable-frame[open] summary::before { transform: rotate(90deg); }
.openable-frame > :not(summary) { margin-top: 0.2rem; }

/* Code panel */
.code-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.code-example-btn {
  background: #1a1e28;
  border: 1px solid #2a3040;
  color: #7ec8e3;
  padding: 0.3rem 0.8rem;
  font-family: inherit;
  font-size: 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.code-example-btn:hover { border-color: #306998; color: #FFD43B; }
.code-example-btn.active { border-color: #FFD43B; color: #FFD43B; }

.str-input-row { display: flex; gap: 0.6rem; align-items: center; margin-bottom: 0.8rem; }
.str-input {
  flex: 1; font-family: inherit; font-size: 1rem;
  padding: 0.5rem 0.8rem; border-radius: 6px;
  border: 1px solid #ddd; outline: none;
  background: #fff; color: #222;
}
.str-input:focus { border-color: #306998; box-shadow: 0 0 0 3px rgba(48,105,152,0.15); }
.str-result { display: none; margin-top: 0.5rem; }
.str-result.visible { display: block; }
.str-result-meta { color: #7a8ba8; font-size: 0.8rem; margin-bottom: 0.4rem; }

.code-editor-wrap {
  background: #12151e;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #2a3040;
  box-shadow: 0 4px 24px rgba(0,0,0,0.25);
  margin-bottom: 1rem;
  transition: box-shadow 0.2s, border-color 0.2s;
}
.code-editor-wrap:focus-within {
  border-color: #306998;
  box-shadow: 0 4px 32px rgba(48,105,152,0.25);
}
.code-editor-titlebar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 0.9rem;
  background: #0e1118;
  border-bottom: 1px solid #2a3040;
}
.titlebar-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
}
.dot-red    { background: #ff5f57; }
.dot-yellow { background: #febc2e; }
.dot-green  { background: #28c840; }
.titlebar-filename {
  margin-left: 0.5rem;
  font-size: 0.72rem;
  color: #3a4a5a;
}
.code-editor {
  display: block;
  width: 100%;
  min-height: 450px;
  background: #12151e;
  color: #c0c8d8;
  border: none;
  border-bottom: 1px solid #2a3040;
  padding: 1rem;
  font-family: inherit;
  font-size: 0.82rem;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  box-sizing: border-box;
}
.code-editor::placeholder { color: #3a4050; }
.code-editor-compact { min-height: 100px; max-height: 180px; overflow-y: auto; resize: none; }
.top-code-wrap {
  height: 0;
  overflow: hidden;
  transition: height 1.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.top-code-wrap .code-examples { margin-bottom: 0.6rem; }
.code-editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
}
.code-byte-count {
  color: #3a4a5a;
  font-size: 0.75rem;
}
.code-compile-btn {
  padding: 0.4rem 1.2rem;
  font-size: 0.82rem;
  background: #306998;
  border-color: #306998;
  color: #fff;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.code-compile-btn:hover {
  background: #FFD43B;
  border-color: #FFD43B;
  color: #12151e;
  box-shadow: 0 0 12px rgba(255,212,59,0.35);
}
.code-result {
  display: none;
}
.code-result.visible {
  display: block;
}
.code-result-inner {
  background: #0e1118;
  border: 1px solid #2a3040;
  border-left: 3px solid #FFD43B;
  border-radius: 6px;
  padding: 1rem;
}
.top-code-wrap .code-result-inner .result-expr {
  max-height: 180px;
  overflow-y: auto;
}
.code-result-meta {
  color: #7a8ba8;
  font-size: 0.75rem;
  margin-bottom: 0.6rem;
}

/* Responsive - must come last */
@media (max-width: 900px) {
  .viz-wrap::after { display: none; }
  body { padding: 1.25rem; max-width: min(1000px, 96%); }
  h1 { font-size: 1.4rem; }
  .subtitle { font-size: 0.98rem; gap: 0.45rem; }
  .main-tab { padding: 0.5rem 0.95rem; font-size: 0.88rem; }
  .main-panel { padding: 1.1rem; }
}

@media (max-width: 600px) {
  body { padding: 1rem; max-width: 98%; }
  .subtitle { display: block; font-size: 0.95rem; margin-bottom: 0.8rem; }
  .github-link { margin-left: 0; margin-top: 0.25rem; display: inline-block; }
  .input-row { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
  input[type="text"] { width: 4.5rem; min-width: 3.6rem; font-size: 1.05rem; border: 2px solid #2a3040; box-shadow: 0 1px 0 rgba(0,0,0,0.3) inset; }
  .btn { width: auto; padding: 0.6rem 0.9rem; }
  .toggle { flex-basis: 100%; margin-top: 0.4rem; height: 32px; padding: 0 0.5rem; }
  .toggle input { width: 14px; height: 14px; }
  .main-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 0.4rem; }
  .main-tab { flex: 0 0 auto; padding: 0.45rem 0.8rem; border-radius: 6px; }
  .main-panel { padding: 1rem; }
  .result { padding: 0.9rem; }
  .result-expr { font-size: 0.8rem; }
  .result-sidebar {
    position: static;
    flex-direction: row;
    justify-content: flex-start;
    margin-top: 0.5rem;
  }
  pre { font-size: 0.75rem; }
  .main-panel table, .op-table, table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}
