:root {
  color-scheme: light;
  --bg: #f5f7f6;
  --panel: #ffffff;
  --panel-soft: #eef4f1;
  --ink: #18201d;
  --muted: #68746e;
  --line: #d8e2dd;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #cdece6;
  --trimmed: rgba(198, 58, 45, 0.22);
  --trimmed-line: rgba(198, 58, 45, 0.16);
  --danger-soft: #f7e6e2;
  --shadow: 0 18px 50px rgba(24, 32, 29, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.09), transparent 36%),
    linear-gradient(315deg, rgba(197, 94, 72, 0.08), transparent 32%),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: flex;
  align-items: center;
  padding: 32px 0;
}

.workspace {
  width: 100%;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.switch {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  width: 44px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border-radius: 999px;
  background: #aebbb6;
  transition: background 160ms ease;
}

.switch-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transform: translateX(0);
  transition: transform 160ms ease;
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(20px);
}

.switch:focus-within,
.icon-button:focus-visible,
input:focus,
textarea:focus {
  outline: 3px solid var(--accent-soft);
  outline-offset: 2px;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(310px, 0.75fr);
  gap: 18px;
  align-items: stretch;
}

.editor-panel,
.results-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.editor-panel {
  min-height: 640px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.panel-header label,
.search-row label {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.icon-button:hover {
  background: var(--danger-soft);
  color: #983c2f;
}

.editor-surface {
  position: relative;
  flex: 1;
  min-height: 520px;
  background: var(--panel);
}

.highlight-layer,
textarea {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 18px;
  border: 0;
  font-size: 1rem;
  line-height: 1.65;
  letter-spacing: 0;
  tab-size: 4;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.highlight-layer {
  z-index: 1;
  margin: 0;
  overflow: hidden;
  background: var(--panel);
  color: var(--ink);
  font-family: inherit;
  pointer-events: none;
}

textarea {
  z-index: 2;
  resize: none;
  overflow: auto;
  background: transparent;
  color: var(--ink);
  caret-color: var(--ink);
}

.editor-surface.is-highlighting textarea {
  color: transparent;
}

.trimmed-char {
  background: var(--trimmed);
  border-radius: 3px;
}

.trimmed-blank {
  display: inline-block;
  width: 2.25rem;
  height: 1em;
  border-radius: 3px;
  background: var(--trimmed-line);
  vertical-align: -0.12em;
}

textarea::placeholder,
input::placeholder {
  color: #99a39f;
}

.results-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  min-height: 118px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.stat-wide {
  grid-column: 1 / -1;
}

.stat-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: clamp(2rem, 4vw, 3.1rem);
  line-height: 1;
  letter-spacing: 0;
}

.search-box {
  margin-top: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.search-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.match-count {
  flex: 0 0 auto;
  padding: 5px 8px;
  border-radius: 8px;
  background: #fff;
  color: var(--accent-strong);
  font-size: 0.85rem;
  font-weight: 800;
}

input[type="search"] {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 24px, 680px);
    align-items: flex-start;
    padding: 18px 0;
  }

  .topbar,
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .switch {
    justify-self: start;
  }

  .editor-grid {
    display: grid;
  }

  .editor-panel {
    min-height: 460px;
  }

  .editor-surface {
    min-height: 360px;
  }

  .results-panel {
    padding: 14px;
  }
}

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

  .stat {
    min-height: 98px;
  }

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