:root {
  --bg-0: #0d1117;
  --bg-1: #111827;
  --bg-2: #182233;
  --bg-3: #1f2937;
  --text-0: #e5ecf5;
  --text-1: #a6b4c8;
  --accent: #30a6ff;
  --accent-2: #18c2a6;
  --warn: #ff6b6b;
  --border: #2a3a52;
  --chip: #243248;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text-0);
  background: var(--bg-0);
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(1200px 420px at 50% -240px, #223652 0%, transparent 62%);
  z-index: 0;
}

.app-shell {
  width: 100%;
  max-width: 1120px;
  margin: 0.75rem auto 1rem;
  padding: 0 0.5rem;
  display: grid;
  gap: 0.55rem;
  position: relative;
  z-index: 1;
}

.panel {
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--border);
  border-radius: 12px;
}

.topbar {
  padding: 0.65rem 0.85rem;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.meta-captions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
}

.title-wrap h1 {
  margin: 0;
  font-size: clamp(1.75rem, 4.2vw, 2.45rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
}

.subtitle {
  margin: 0.2rem 0 0;
  color: var(--text-1);
  font-size: 0.92rem;
}

.tokenizer-caption {
  margin: 0;
  color: var(--text-1);
  font-size: 0.9rem;
  white-space: nowrap;
}

.voice-model-caption {
  margin: 0;
  color: var(--text-1);
  font-size: 0.82rem;
  white-space: nowrap;
}

.tokenizer-caption code {
  font-family: "IBM Plex Mono", monospace;
  color: var(--text-0);
  background: #0f1724;
  border: 1px solid var(--border);
  padding: 0.1rem 0.35rem;
  border-radius: 5px;
}

.voice-model-caption code {
  font-family: "IBM Plex Mono", monospace;
  color: var(--text-0);
  background: #0f1724;
  border: 1px solid var(--border);
  padding: 0.08rem 0.32rem;
  border-radius: 5px;
}

.tokenizer-caption a {
  color: #8ecbff;
  text-decoration: none;
}

.tokenizer-caption a:hover {
  text-decoration: underline;
}

.controlbar {
  padding: 0.5rem 0.75rem;
}

.control-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem;
}

button,
textarea {
  font: inherit;
}

button {
  background: var(--bg-3);
  color: var(--text-0);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.42rem 0.68rem;
}

button {
  cursor: pointer;
  background: linear-gradient(180deg, #27496c, #1f3c59);
}

button:hover:enabled {
  border-color: #41658f;
}

.metrics {
  padding: 0.45rem 0.6rem;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  height: 92px;
}

.metric-tile {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #111a29;
  padding: 0.4rem 0.6rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
}

.metric-label {
  color: var(--text-1);
  font-size: 0.76rem;
  font-family: "IBM Plex Mono", monospace;
}

.metric-value {
  font-size: clamp(1.2rem, 2.5vw, 1.7rem);
  line-height: 1.1;
  color: #f6fbff;
}

.runtime {
  height: 96px;
  padding: 0.45rem 0.7rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  overflow: hidden;
  min-width: 0;
}

.runtime-left {
  display: flex;
  flex-direction: column;
  min-width: 210px;
}

.runtime-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
  min-width: 0;
  width: 100%;
}

.runtime-label {
  color: var(--text-1);
  font-size: 0.82rem;
  font-family: "IBM Plex Mono", monospace;
}

.runtime-value {
  font-size: clamp(1.25rem, 2.3vw, 1.75rem);
  font-weight: 700;
  line-height: 1;
}

.runtime-details {
  color: var(--text-1);
  line-height: 1.35;
  font-size: 0.86rem;
  overflow: hidden;
  min-width: 0;
}

.share-btn {
  white-space: nowrap;
  padding: 0.38rem 0.62rem;
}

#voice-start {
  white-space: nowrap;
}

.runtime-details.error {
  color: var(--warn);
}

.runtime.results-mode .runtime-details {
  color: #c8d6e8;
  font-size: 0.95rem;
}

.runtime.results-mode .runtime-details .result-line {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.runtime.results-mode .runtime-details strong {
  color: #f4f9ff;
}

.input-mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
  padding: 0.55rem 0.65rem 0.4rem;
  border-bottom: 1px solid var(--border);
  background: #101a2b;
}

.input-mode-left {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.input-mode-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.voice-action-hint {
  color: #8fa5c2;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  max-width: 320px;
  white-space: normal;
  line-height: 1.25;
}

.input-mode-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  color: var(--text-1);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.mode-pill {
  position: relative;
  display: inline-flex;
}

.mode-pill input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.mode-pill span {
  padding: 0.28rem 0.62rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #15233a;
  color: #b9c9de;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
  transition: 120ms ease;
}

.mode-pill input:checked + span {
  color: #eef7ff;
  border-color: #42658f;
  background: linear-gradient(180deg, #2a4f77, #224266);
}

.mode-pill input:focus-visible + span {
  outline: 2px solid #5ca4ef;
  outline-offset: 1px;
}

.editor {
  overflow: hidden;
  min-width: 0;
}

.editor-chrome {
  height: 36px;
  border-bottom: 1px solid var(--border);
  background: #0f1725;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.45rem;
  padding: 0 0.65rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot-red {
  background: #f87171;
}

.dot-amber {
  background: #fbbf24;
}

.dot-green {
  background: #34d399;
}

.editor-tab {
  margin-left: 0.3rem;
  padding: 0.22rem 0.52rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #182236;
  color: #d9e6f7;
  font-size: 0.83rem;
  font-family: "IBM Plex Mono", monospace;
}

.editor-mode-badge {
  margin-left: auto;
  padding: 0.18rem 0.5rem;
  border: 1px solid #33507a;
  border-radius: 999px;
  background: #13203a;
  color: #b7cdf0;
  font-size: 0.74rem;
  font-family: "IBM Plex Mono", monospace;
  white-space: nowrap;
}

.editor-body {
  height: 320px;
  padding: 0.5rem;
  background: #0f1724;
  min-width: 0;
}

.editor.results-fit .editor-body {
  height: auto;
}

textarea,
.token-highlight {
  width: 100%;
  margin: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: #dce8f8;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.98rem;
  line-height: 1.5;
}

textarea {
  height: 100%;
  resize: none;
  padding: 0.75rem 0.85rem;
}

textarea:focus {
  outline: 2px solid #2f79bf;
  outline-offset: 1px;
}

textarea:disabled {
  opacity: 0.95;
}

.voice-panel {
  height: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: #dce8f8;
  font-family: "IBM Plex Mono", monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 0.85rem;
}

.voice-panel p {
  margin: 0;
  color: #bfd0e8;
  font-size: 0.92rem;
  line-height: 1.45;
  text-align: center;
  max-width: 680px;
}

#input-highlight-wrap {
  display: grid;
  grid-template-rows: auto auto;
  gap: 0.45rem;
  min-width: 0;
}

.token-highlight {
  min-height: 180px;
  padding: 0.75rem 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
}

.editor.results-fit .token-highlight {
  min-height: 0;
}

.token-chip {
  border-radius: 0.16rem;
  cursor: help;
}

.token-id-row {
  margin: 0;
  min-height: 46px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0b1220;
  padding: 0.45rem 0.55rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.74rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.token-id-chip {
  display: inline-block;
  margin: 0 0.2rem 0.16rem 0;
  padding: 0.03rem 0.22rem;
  border-radius: 0.2rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #ebf3ff;
  cursor: help;
}

.hidden {
  display: none;
}

.token-tooltip {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  max-width: 320px;
  border: 1px solid #36537a;
  background: #0b1321;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.35;
  color: #d9e6f7;
  white-space: pre-wrap;
}

@media (max-width: 900px) {
  .app-shell {
    margin: 0.5rem auto 0.75rem;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .meta-captions {
    align-items: flex-start;
  }

  .tokenizer-caption,
  .voice-model-caption {
    white-space: normal;
  }

  .metrics {
    height: auto;
    grid-template-columns: 1fr;
  }

  .runtime {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
  }

  .runtime-right {
    width: 100%;
    align-items: flex-start;
    flex-direction: column;
    gap: 0.45rem;
  }

  .runtime.results-mode .runtime-details .result-line {
    white-space: normal;
  }

  .editor-body {
    height: 300px;
  }

  .editor-mode-badge {
    display: none;
  }

  .editor.results-fit .editor-body {
    height: auto;
  }
}

@media (max-width: 520px) {
  .control-group {
    gap: 0.45rem;
  }

  button {
    max-width: 100%;
  }

  .input-mode-row {
    flex-wrap: wrap;
    gap: 0.45rem;
  }

  .input-mode-actions {
    width: 100%;
    justify-content: space-between;
  }
}
