:root{
  --bg: #14171a;
  --panel: #1b1f23;
  --panel-soft: #20252a;
  --border: #2c3238;
  --text: #e6e9ec;
  --text-dim: #9aa3ab;
  --undo: #29c7c0;      /* cyan = undo stack */
  --redo: #e8a23a;      /* amber = redo stack */
  --danger: #e0566b;
  --font-mono: 'JetBrains Mono', monospace;
  --font-ui: 'Inter', sans-serif;
}

*{ box-sizing:border-box; }
body{
  margin:0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  height:100vh;
  display:flex;
  flex-direction:column;
}

/* ===== TOPBAR ===== */
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 0.8em 1.4em;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand{
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.05rem;
  display:flex;
  align-items:center;
  gap: 0.5em;
}
.brand-mark{ color: var(--undo); }
.topbar-actions{ display:flex; gap: 0.6em; }

.tbtn{
  background: var(--panel-soft);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.5em 0.9em;
  border-radius: 6px;
  cursor: pointer;
  display:flex;
  align-items:center;
  gap: 0.5em;
  transition: border-color 0.15s, background 0.15s;
}
.tbtn:hover:not(:disabled){ border-color: var(--undo); }
.tbtn:disabled{ opacity:0.4; cursor:not-allowed; }
.tbtn-danger:hover:not(:disabled){ border-color: var(--danger); }
.tbtn kbd{
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  background: var(--bg);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  border: 1px solid var(--border);
}

/* ===== APP LAYOUT ===== */
.app{
  flex:1;
  display:grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1px;
  background: var(--border);
  overflow:hidden;
}

.editor-pane{
  background: var(--bg);
  display:flex;
  flex-direction:column;
  padding: 1.2em 1.4em;
  min-width:0;
}
.pane-label{
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 0.7em;
}
.pane-label .dim{ text-transform:none; letter-spacing:0; color:#5d666e; }

#editor{
  flex:1;
  width:100%;
  resize:none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 1.7;
  padding: 1em 1.2em;
}
#editor:focus{ outline:none; border-color: var(--undo); }

.statusbar{
  display:flex;
  gap: 1.4em;
  margin-top: 0.8em;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* ===== SIDE PANE ===== */
.side-pane{
  background: var(--bg);
  display:flex;
  flex-direction:column;
  min-width:0;
}
.tabs{
  display:flex;
  border-bottom: 1px solid var(--border);
}
.tab{
  flex:1;
  background:none;
  border:none;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.9em 0.5em;
  cursor:pointer;
  border-bottom: 2px solid transparent;
}
.tab.is-active{
  color: var(--text);
  border-bottom-color: var(--undo);
}
.tab-panel{ display:none; padding: 1.2em 1.4em; overflow-y:auto; }
.tab-panel.is-active{ display:flex; flex-direction:column; flex:1; }

.panel-note{
  font-size: 0.82rem;
  color: var(--text-dim);
  margin: 0 0 1.1em;
  line-height:1.55;
}
.panel-note strong{ color: var(--text); }

/* Stack visualizer */
.stack-columns{ display:grid; grid-template-columns:1fr 1fr; gap:1em; flex:1; min-height:0; }
.stack-col{ display:flex; flex-direction:column; min-height:0; }
.stack-title{
  font-family: var(--font-mono);
  font-size: 0.8rem;
  margin:0 0 0.6em;
}
.undo-title{ color: var(--undo); }
.redo-title{ color: var(--redo); }
.stack-title span{ color: var(--text-dim); font-weight:400; }

.stack-visual{
  display:flex;
  flex-direction: column-reverse; /* top of stack renders at the top */
  gap: 6px;
  overflow-y:auto;
  flex:1;
  padding: 0.3em;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.stack-card{
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.45em 0.6em;
  white-space: nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}
.stack-card.is-top{
  border-color: var(--undo);
  color: var(--text);
}
.redo-col .stack-card.is-top{ border-color: var(--redo); }
.stack-empty{
  font-size: 0.78rem;
  color: #5d666e;
  text-align:center;
  margin: auto;
}

/* Find & Replace */
.field{
  display:flex;
  flex-direction:column;
  gap: 0.4em;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 0.9em;
}
.field input{
  font-family: var(--font-ui);
  font-size: 0.9rem;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55em 0.7em;
  border-radius: 6px;
}
.field input:focus{ outline:none; border-color: var(--undo); }
.checkbox-field{
  display:flex; align-items:center; gap:0.5em;
  font-size: 0.82rem; color: var(--text-dim);
  margin-bottom: 1em;
}
.btn-row{ display:flex; gap: 0.5em; flex-wrap:wrap; margin-bottom: 1em; }
.match-status{
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* Word Frequency */
.freq-summary{
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 1em;
}
.freq-list{ display:flex; flex-direction:column; gap: 0.5em; }
.freq-row{ display:flex; align-items:center; gap: 0.7em; }
.freq-word{
  font-family: var(--font-mono);
  font-size: 0.8rem;
  width: 90px;
  flex-shrink:0;
  overflow:hidden;
  text-overflow:ellipsis;
}
.freq-bar-track{
  flex:1;
  height: 8px;
  background: var(--panel);
  border-radius: 4px;
  overflow:hidden;
}
.freq-bar-fill{
  height:100%;
  background: linear-gradient(90deg, var(--undo), var(--redo));
  border-radius:4px;
}
.freq-count{
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  width: 28px;
  text-align:right;
}

/* Footer */
.site-footer{
  text-align:center;
  padding: 0.7em;
  font-size: 0.75rem;
  color: var(--text-dim);
  background: var(--panel);
  border-top: 1px solid var(--border);
}

/* Highlighted match flash */
.flash-highlight{ animation: flash 0.5s ease; }
@keyframes flash{
  0%{ background: rgba(41,199,192,0.25); }
  100%{ background: transparent; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 880px){
  .app{ grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .stack-columns{ grid-template-columns: 1fr; }
}
