/* Theme variables live in shared/variables.css — loaded before this file. */

* { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg, #0f1117);
  color: var(--text, #e2e8f0);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Page header ────────────────────────────────────── */
.page-header {
  text-align: center;
  padding: 1.5rem 1.5rem 0.75rem;
  border-bottom: 1px solid var(--border, #2d3148);
  flex-shrink: 0;
}

.page-header h1 { font-size: 1.65rem; font-weight: 700; margin-bottom: 0.3rem; }
.page-header h1 .accent { color: var(--accent-2); }
.page-header p { color: var(--muted, #8892a4); font-size: 0.875rem; max-width: 600px; margin: 0 auto; }

.back-link {
  display: inline-block;
  margin-bottom: 0.6rem;
  color: var(--muted, #8892a4);
  text-decoration: none;
  font-size: 0.8rem;
}
.back-link:hover { color: var(--accent-2); }

.ai-disclaimer {
  font-size: 0.72rem;
  color: var(--muted, #8892a4);
  margin-top: 0.4rem;
  opacity: 0.7;
}

/* ── Theme toggle ───────────────────────────────────── */
.theme-toggle {
  position: fixed;
  top: 0.75rem;
  right: 1rem;
  z-index: 100;
  background: var(--surface, #1a1d27);
  border: 1px solid var(--border, #2d3148);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text, #e2e8f0);
  line-height: 1;
}
.theme-toggle:hover { background: var(--surface-2, #22253a); }

/* ── Preset bar ─────────────────────────────────────── */
.preset-bar {
  display: flex;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border, #2d3148);
  flex-wrap: wrap;
  flex-shrink: 0;
  background: var(--surface, #1a1d27);
}

.preset-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted, #8892a4);
  align-self: center;
  margin-right: 0.2rem;
}

.preset-btn {
  background: var(--surface-2, #22253a);
  border: 1px solid var(--border, #2d3148);
  border-radius: 20px;
  padding: 0.25rem 0.7rem;
  font-size: 0.75rem;
  color: var(--text, #e2e8f0);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-family: inherit;
}
.preset-btn:hover { background: var(--highlight); border-color: var(--accent-2); }
.preset-btn.active { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }

/* ── Main layout ────────────────────────────────────── */
.tok-layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Left: Input + output ──────────────────────────── */
.tok-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border, #2d3148);
}

.tok-input-area {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border, #2d3148);
  flex-shrink: 0;
}

.tok-textarea {
  width: 100%;
  background: var(--code-bg, #151820);
  border: 1px solid var(--border, #2d3148);
  border-radius: 6px;
  color: var(--text, #e2e8f0);
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 0.875rem;
  line-height: 1.6;
  padding: 0.6rem 0.75rem;
  resize: vertical;
  min-height: 80px;
  max-height: 160px;
}
.tok-textarea:focus { outline: none; border-color: var(--accent-2); }

.input-hint {
  font-size: 0.7rem;
  color: var(--muted, #8892a4);
  margin-top: 0.3rem;
}

.tok-output-area {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.output-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted, #8892a4);
  margin-bottom: 0.5rem;
}

.tok-rendered {
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 0.9rem;
  line-height: 2;
  word-break: break-word;
  white-space: pre-wrap;
}

/* ── Token spans ────────────────────────────────────── */
.tok-span {
  border-radius: 3px;
  padding: 1px 0;
  cursor: pointer;
  transition: filter 0.1s;
  position: relative;
}
.tok-span:hover { filter: brightness(1.2); }

/* 8 cycling token colors */
.tok-c0 { background: rgba(91, 163, 0, 0.25); border-bottom: 2px solid #5ba300; }
.tok-c1 { background: rgba(0, 158, 176, 0.2); border-bottom: 2px solid #009eb0; }
.tok-c2 { background: rgba(123, 94, 167, 0.2); border-bottom: 2px solid #7b5ea7; }
.tok-c3 { background: rgba(201, 122, 46, 0.2); border-bottom: 2px solid #c97a2e; }
.tok-c4 { background: rgba(199, 62, 62, 0.2); border-bottom: 2px solid #c73e3e; }
.tok-c5 { background: rgba(80, 160, 255, 0.2); border-bottom: 2px solid #50a0ff; }
.tok-c6 { background: rgba(245, 200, 66, 0.2); border-bottom: 2px solid #f5c842; }
.tok-c7 { background: rgba(160, 200, 100, 0.2); border-bottom: 2px solid #a0c864; }

html[data-theme="light"] .tok-c0 { background: rgba(74, 138, 0, 0.12); }
html[data-theme="light"] .tok-c1 { background: rgba(0, 125, 143, 0.1); }
html[data-theme="light"] .tok-c2 { background: rgba(107, 78, 151, 0.1); }
html[data-theme="light"] .tok-c3 { background: rgba(176, 106, 32, 0.1); }
html[data-theme="light"] .tok-c4 { background: rgba(179, 48, 48, 0.1); }
html[data-theme="light"] .tok-c5 { background: rgba(9, 105, 218, 0.1); }
html[data-theme="light"] .tok-c6 { background: rgba(170, 140, 0, 0.1); }
html[data-theme="light"] .tok-c7 { background: rgba(80, 140, 40, 0.1); }

/* whitespace tokens: subtle underline only */
.tok-ws {
  border-bottom: 2px dotted var(--border, #2d3148);
  background: transparent;
}
.tok-ws:hover { background: var(--highlight); }

/* ── Right: Stats panel ─────────────────────────────── */
.tok-stats {
  overflow-y: auto;
  padding: 0.75rem 1rem;
  background: var(--surface, #1a1d27);
}

.stat-section {
  margin-bottom: 1.25rem;
}

.stat-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted, #8892a4);
  margin-bottom: 0.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border, #2d3148);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
}

.stat-key { color: var(--muted, #8892a4); }
.stat-val { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ── Type breakdown bars ─────────────────────────────── */
.type-bar-wrap {
  margin-top: 0.4rem;
}

.type-bar-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
  font-size: 0.75rem;
}

.type-bar-label { color: var(--muted, #8892a4); width: 72px; flex-shrink: 0; }
.type-bar-count { color: var(--text, #e2e8f0); width: 28px; text-align: right; flex-shrink: 0; }

.type-bar-track {
  flex: 1;
  height: 8px;
  background: var(--surface-2, #22253a);
  border-radius: 4px;
  overflow: hidden;
}

.type-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.type-bar-fill--words  { background: #5ba300; }
.type-bar-fill--numbers { background: #c97a2e; }
.type-bar-fill--punct  { background: #009eb0; }
.type-bar-fill--ws     { background: var(--border, #2d3148); }
.type-bar-fill--other  { background: #7b5ea7; }

/* ── Token detail panel ──────────────────────────────── */
.tok-detail {
  background: var(--surface-2, #22253a);
  border: 1px solid var(--border, #2d3148);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  margin-top: 0.75rem;
  min-height: 72px;
}

.tok-detail-placeholder {
  color: var(--muted, #8892a4);
  font-style: italic;
}

.tok-detail-text {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.9rem;
  font-weight: 600;
  word-break: break-all;
  margin-bottom: 0.4rem;
}

.tok-detail-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  color: var(--muted, #8892a4);
  font-size: 0.72rem;
}

.tok-detail-bytes {
  font-family: monospace;
  letter-spacing: 0.04em;
  color: var(--accent-2);
  word-break: break-all;
}

/* ── Accuracy note ───────────────────────────────────── */
.accuracy-note {
  font-size: 0.72rem;
  color: var(--muted, #8892a4);
  padding: 0.4rem 0.6rem;
  background: var(--surface-2, #22253a);
  border-radius: 4px;
  border-left: 2px solid var(--accent-4);
  margin-top: 0.75rem;
}

/* ── Mode toggle bar ─────────────────────────────────── */
.mode-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.mode-toggle-group {
  display: flex;
  border: 1px solid var(--border, #2d3148);
  border-radius: 5px;
  overflow: hidden;
  flex-shrink: 0;
}

.mode-btn {
  background: var(--surface-2, #22253a);
  border: none;
  padding: 0.25rem 0.65rem;
  font-size: 0.72rem;
  color: var(--muted, #8892a4);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.mode-btn + .mode-btn { border-left: 1px solid var(--border, #2d3148); }
.mode-btn:hover:not(:disabled) { background: var(--highlight); color: var(--text, #e2e8f0); }
.mode-btn.mode-btn--active { background: var(--accent-2); color: #fff; }
.mode-btn:disabled { opacity: 0.55; cursor: not-allowed; }

.mode-status {
  font-size: 0.72rem;
  color: var(--muted, #8892a4);
}
.mode-status--loading { color: var(--accent-2); font-style: italic; }
.mode-status--error   { color: #c73e3e; }

/* ── Preset explanation ──────────────────────────────── */
.preset-explanation {
  font-size: 0.78rem;
  color: var(--accent-2);
  padding: 0.4rem 0.6rem;
  background: rgba(0,158,176,0.06);
  border-radius: 4px;
  border-left: 2px solid var(--accent-2);
  margin-top: 0.75rem;
  line-height: 1.5;
  display: none;
}
.preset-explanation.visible { display: block; }

/* ── Mobile tab bar ──────────────────────────────────── */
.mobile-tab-bar {
  display: none;
  background: var(--surface, #1a1d27);
  border-bottom: 1px solid var(--border, #2d3148);
  padding: 0;
}
.mobile-tab {
  flex: 1;
  padding: 0.6rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted, #8892a4);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
}
.mobile-tab.active { color: var(--accent-2); border-bottom-color: var(--accent-2); }

@media (max-width: 700px) {
  .mobile-tab-bar { display: flex; }

  .tok-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  .tok-main  { display: none; }
  .tok-stats { display: none; }

  .tok-main.panel-active  { display: flex; }
  .tok-stats.panel-active { display: block; }
}
