* { 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[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 {
  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; }
.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);
}
.share-btn {
  background: #1a1e28;
  border: 1px solid #2a3040;
  color: #d9dde3;
  font-size: 0.7rem;
  font-family: inherit;
  cursor: pointer;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  display: none;
  white-space: nowrap;
}
.share-char { font-size: 1.3em; color: #FFD43B; }
.share-btn:hover { color: #FFD43B; border-color: #306998; }
.share-btn.visible { display: block; }
.share-btn.copied { color: #61dafb; background: #12151e; border-color: #61dafb; }
.visualize-btn {
  background: #1a1e28;
  border: 2px solid #2a3040;
  color: #7ec8e3;
  padding: 0.5rem 0.8rem;
  font-family: inherit;
  font-size: 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  display: none;
}
.visualize-btn.visible { display: block; }
.visualize-btn:hover { border-color: #306998; color: #FFD43B; }
.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; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}
.copied { color: #306998; font-size: 0.75rem; margin-top: 0.4rem; }


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; }

.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; }

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

/* Responsive - must come last */
@media (max-width: 900px) {
  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;
  }
}
