:root {
  --page: #111315;
  --surface: #1b1e22;
  --soft: #25292e;
  --soft-hover: #353229;
  --ink: #f2f0e8;
  --muted: #aaa79e;
  --line: #383d43;
  --gold: #f2c230;
  --gold-hover: #d7a900;
  --gold-dim: rgba(242, 194, 48, 0.14);
  --danger: #432727;
  --danger-hover: #5c3330;
  --danger-text: #f7d45b;
  --error: #ff8a80;
  --ok: #6ee7b7;
  --font-sans: "Manrope", "Segoe UI", system-ui, sans-serif;
  --font-mono: "DM Mono", "Cascadia Mono", Consolas, monospace;
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at top right, rgba(242, 194, 48, 0.06), transparent 36%), var(--page);
  color: var(--ink);
  font-family: var(--font-sans);
  line-height: 1.5;
}

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--soft);
  padding: 0.12rem 0.36rem;
  border-radius: 4px;
  color: var(--gold);
}

.hidden {
  display: none !important;
}

.app-shell {
  width: min(1360px, 100%);
  margin: 0 auto;
  padding: 1rem clamp(0.9rem, 2.5vw, 1.8rem) 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Topbar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.topbar-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.back-hub {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--ink);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  transition: border-color 0.2s, background 0.2s;
}

.back-hub:hover {
  border-color: var(--gold);
  background: var(--soft-hover);
}

.brand-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.brand-block h1 {
  margin: 0.15rem 0 0;
  font-size: clamp(1.15rem, 2vw, 1.55rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.accent-gold {
  color: var(--gold);
}

.topbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.stat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.stat-pill {
  display: flex;
  flex-direction: column;
  padding: 0.38rem 0.75rem;
  border-radius: 8px;
  background: var(--soft);
  border: 1px solid var(--line);
  min-width: 96px;
}

.stat-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--muted);
  letter-spacing: 0.06em;
}

.stat-pill strong {
  font-size: 0.95rem;
  color: var(--gold);
}

.stat-pill small {
  font-weight: 500;
  color: var(--muted);
}

/* Tabs */
.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.65rem 1.05rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--ink);
  border-color: var(--gold-hover);
}

.tab-btn.is-active {
  background: var(--gold);
  color: #111315;
  border-color: var(--gold);
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

/* Cards & Controls */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.card-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
}

.card-sub {
  margin: 0.25rem 0 0;
  font-size: 0.84rem;
  color: var(--muted);
}

.mono-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  background: var(--gold-dim);
  border: 1px solid rgba(242, 194, 48, 0.35);
  color: var(--gold);
}

.mono-badge.muted {
  background: var(--soft);
  border-color: var(--line);
  color: var(--muted);
}

input[type="text"],
input:not([type]) {
  width: 100%;
  height: 40px;
  padding: 0 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--gold-hover);
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="text"]:focus,
input:not([type]):focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(242, 194, 48, 0.16);
}

input::placeholder {
  color: #7c7a74;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 40px;
  padding: 0 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.18s, border-color 0.18s, transform 0.1s;
}

.btn:active {
  transform: translateY(1px);
}

.btn-sm {
  height: 34px;
  padding: 0 0.78rem;
  font-size: 0.82rem;
}

.btn-gold {
  background: var(--gold);
  color: #111315;
}

.btn-gold:hover {
  background: var(--gold-hover);
}

.btn-soft {
  background: var(--soft);
  border-color: var(--line);
  color: var(--ink);
}

.btn-soft:hover {
  background: var(--soft-hover);
  border-color: var(--gold-hover);
}

.btn-danger {
  background: var(--danger);
  border-color: rgba(255, 138, 128, 0.28);
  color: var(--danger-text);
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.link-btn {
  border: none;
  background: none;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
}

.link-btn:hover {
  text-decoration: underline;
}

/* Tab 1 Layout */
.dict-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1.05fr) minmax(360px, 1.25fr);
  gap: 1rem;
  align-items: start;
}

.dict-left {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
}

.quick-samples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.chip {
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.2rem 0.62rem;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.chip:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.result-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.result-direction {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

/* Dashed animated border echoing app_gui.py */
.dashed-gold-box {
  position: relative;
  min-height: 156px;
  max-height: 300px;
  overflow-y: auto;
  padding: 1rem;
  border-radius: 10px;
  background: var(--soft);
  border: 2px dashed rgba(242, 194, 48, 0.65);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.result-placeholder {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.result-entry {
  text-align: center;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(56, 61, 67, 0.75);
}

.result-entry:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.result-word {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--gold);
}

.result-meaning {
  margin-top: 0.2rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
}

.result-relations {
  margin-top: 0.45rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.rel-pills {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.32rem;
}

.rel-pill {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 6px;
  padding: 0.12rem 0.48rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  cursor: pointer;
}

.rel-pill:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.avl-path-strip {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  background: var(--page);
  border: 1px solid var(--line);
}

.path-label {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--muted);
}

.path-nodes {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.path-step {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  padding: 0.18rem 0.48rem;
  border-radius: 6px;
  background: var(--soft);
  border: 1px solid var(--line);
  color: var(--ink);
}

.path-step.is-found {
  background: var(--gold-dim);
  border-color: var(--gold);
  color: var(--gold);
  font-weight: 700;
}

.path-arrow {
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 0.74rem;
}

/* Manage Form */
.manage-form {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
}

.field span {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}

.manage-actions {
  display: grid;
  grid-template-columns: 1.3fr 1fr auto;
  gap: 0.5rem;
  margin-top: 0.2rem;
}

.feedback-banner {
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  font-size: 0.84rem;
  border: 1px solid var(--gold);
  background: var(--gold-dim);
  color: var(--ink);
}

.feedback-banner.is-error {
  border-color: var(--error);
  background: rgba(255, 138, 128, 0.12);
  color: var(--error);
}

.ops-history {
  border-top: 1px solid var(--line);
  padding-top: 0.7rem;
}

.ops-title {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.ops-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 155px;
  overflow-y: auto;
}

.ops-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.79rem;
  padding: 0.32rem 0.55rem;
  border-radius: 6px;
  background: var(--page);
  border: 1px solid rgba(56, 61, 67, 0.6);
}

.ops-tag {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--soft);
  color: var(--gold);
}

/* Right Dictionary Table */
.dict-right {
  min-height: 690px;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.65rem;
}

.filter-count {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--gold);
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  background: var(--soft);
  border: 1px solid var(--line);
}

.word-table-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--page);
  overflow: auto;
  max-height: 540px;
}

.word-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.word-table thead th {
  position: sticky;
  top: 0;
  background: var(--soft);
  color: var(--muted);
  text-align: left;
  padding: 0.65rem 0.8rem;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  border-bottom: 1px solid var(--line);
  z-index: 1;
}

.word-table tbody tr {
  border-bottom: 1px solid rgba(56, 61, 67, 0.45);
  cursor: pointer;
  transition: background 0.14s;
}

.word-table tbody tr:hover {
  background: var(--soft-hover);
}

.word-table td {
  padding: 0.58rem 0.8rem;
  vertical-align: top;
}

.col-idx {
  width: 64px;
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 0.78rem;
}

.col-word {
  width: 34%;
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--gold);
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.pagination-info {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--muted);
}

/* Tab 2: Visualizer */
.viz-layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.viz-controls,
.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.inline-form input {
  width: 210px;
  height: 34px;
}

.tree-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
}

.crumb-btn {
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--ink);
  border-radius: 6px;
  padding: 0.22rem 0.55rem;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  cursor: pointer;
}

.crumb-btn:hover,
.crumb-btn.is-current {
  border-color: var(--gold);
  color: var(--gold);
}

.svg-stage {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: radial-gradient(circle at center, rgba(242, 194, 48, 0.04), transparent 65%), var(--page);
  overflow-x: auto;
  padding: 0.5rem;
}

.tree-svg {
  width: 100%;
  min-width: 680px;
  height: auto;
  display: block;
}

.tree-node-group {
  cursor: pointer;
}

.tree-node-group:hover .tree-node-rect {
  stroke: var(--gold);
  stroke-width: 2.2;
}

.node-inspector {
  padding: 0.75rem 0.95rem;
  border-radius: 8px;
  background: var(--soft);
  border: 1px solid var(--line);
  font-size: 0.88rem;
}

.sandbox-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.preset-label {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.sandbox-custom {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}

.sandbox-custom input {
  height: 36px;
  font-family: var(--font-mono);
  font-size: 0.84rem;
}

.sandbox-playback {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.playback-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.step-status-pill {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--gold);
  padding: 0.28rem 0.7rem;
  border-radius: 6px;
  background: var(--soft);
  border: 1px solid var(--line);
}

.rotation-banner {
  padding: 0.7rem 0.95rem;
  border-radius: 8px;
  background: var(--soft);
  border-left: 4px solid var(--gold);
  font-size: 0.88rem;
  font-weight: 600;
}

.rotation-banner.has-rotation {
  background: var(--gold-dim);
  color: var(--gold);
}

.sandbox-inorder-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.84rem;
  color: var(--muted);
}

/* Tab 3: Benchmark */
.benchmark-meta {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  background: var(--page);
  border: 1px solid var(--line);
}

.bench-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.bench-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.bench-table th,
.bench-table td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.bench-table th {
  background: var(--soft);
  color: var(--muted);
  font-size: 0.78rem;
}

.bench-bad {
  color: var(--error);
  font-family: var(--font-mono);
  font-weight: 700;
}

.bench-good {
  color: var(--ok);
  font-family: var(--font-mono);
  font-weight: 700;
}

.bench-section-title {
  margin: 0.4rem 0 0;
  font-size: 0.92rem;
  color: var(--gold);
}

.bench-svg-card {
  padding: 0.95rem;
  border-radius: 10px;
  background: var(--page);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.bench-svg {
  width: 100%;
  height: auto;
  display: block;
}

.bench-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.85rem;
}

.bench-chart-card {
  padding: 0.95rem;
  border-radius: 10px;
  background: var(--page);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.bar-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.78rem;
}

.bar-label-line {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: var(--soft);
  overflow: hidden;
}

.bar-fill-bst {
  height: 100%;
  background: linear-gradient(90deg, #ef4444, #ff8a80);
}

.bar-fill-avl {
  height: 100%;
  background: linear-gradient(90deg, #d7a900, #f2c230);
}

/* Footer */
.app-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.9rem 1.2rem;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--muted);
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.footer-links a {
  color: var(--gold);
  text-decoration: none;
  font-family: var(--font-mono);
}

.footer-links a:hover {
  text-decoration: underline;
}

/* Toast */
.toast {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 50;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--gold);
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.5);
}

.toast.is-error {
  border-color: var(--error);
  color: var(--error);
}

@media (max-width: 960px) {
  .dict-grid {
    grid-template-columns: 1fr;
  }

  .dict-right {
    min-height: 460px;
  }
}

@media (max-width: 640px) {
  .form-row-2,
  .manage-actions,
  .sandbox-custom {
    grid-template-columns: 1fr;
  }

  .inline-form input {
    width: 100%;
  }
}

