:root {
  color-scheme: dark;
  --bg: #0c0f14;
  --surface: #141923;
  --surface-2: #1b2230;
  --line: #2a3445;
  --text: #f4f7fb;
  --muted: #9aa8bc;
  --accent: #60a5fa;
  --accent-2: #2dd4bf;
  --danger: #fb7185;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea,
input {
  font: inherit;
}

.app-shell {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100vh;
  padding: 22px;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.7rem, 3vw, 2.55rem);
  line-height: 1.08;
  letter-spacing: 0;
}

.app-header p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 1rem;
}

.header-status {
  min-width: 220px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  text-align: right;
  font-size: 0.9rem;
}

.toolbar,
.options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.toolbar button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 13px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, color 160ms ease, transform 120ms ease;
}

.toolbar button:hover,
.toolbar button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.toolbar button:first-child,
.toolbar button:nth-child(2) {
  background: #17304f;
  border-color: #245782;
}

.toolbar button:active,
.toolbar button.is-pressed,
.toolbar button.is-processing {
  transform: translateY(1px);
}

.toolbar button:disabled {
  cursor: progress;
  opacity: 0.86;
}

.toolbar button.is-processing {
  border-color: rgba(96, 165, 250, 0.9);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.14);
}

.toolbar button.is-pressed {
  background: #1f3d63;
}

.toolbar button.is-success {
  border-color: rgba(45, 212, 191, 0.95);
  box-shadow: 0 0 0 4px rgba(45, 212, 191, 0.18);
  animation: buttonPulse 720ms ease;
}

.toolbar button.is-error {
  border-color: rgba(251, 113, 133, 0.95);
  box-shadow: 0 0 0 4px rgba(251, 113, 133, 0.15);
}

@keyframes buttonPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(45, 212, 191, 0.34);
  }
  100% {
    box-shadow: 0 0 0 8px rgba(45, 212, 191, 0);
  }
}

.options {
  min-height: 36px;
  color: var(--muted);
  font-size: 0.93rem;
}

.options label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(320px, 1.15fr) minmax(260px, 0.85fr);
  gap: 14px;
  flex: 1;
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
  font-size: 0.98rem;
  font-weight: 700;
}

.panel-heading span {
  color: var(--muted);
  font-size: 0.84rem;
}

textarea,
.preview {
  flex: 1;
  width: 100%;
  min-height: 460px;
  border: 0;
  background: #10151d;
  color: var(--text);
  resize: none;
  outline: none;
  padding: 16px;
  line-height: 1.62;
  font-size: 1rem;
}

.preview {
  overflow: auto;
  white-space: normal;
}

.preview p {
  margin: 0 0 1em;
}

.preview a {
  color: #93c5fd;
  text-decoration-color: rgba(147, 197, 253, 0.55);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  border-radius: 4px;
}

.preview a:hover,
.preview a:focus-visible {
  color: #bfdbfe;
  background: rgba(96, 165, 250, 0.12);
  outline: none;
}

.status-panel {
  padding-bottom: 14px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
}

.status-grid div {
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: #10151d;
}

.status-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.79rem;
}

.status-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 1.55rem;
}

.status-section {
  padding: 0 14px 14px;
}

.status-section h3 {
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.badge-list,
.detected-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.badge,
.detected-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10151d;
  color: var(--text);
  padding: 7px 9px;
  font-size: 0.84rem;
}

.badge {
  color: var(--accent-2);
}

.detected-item {
  display: grid;
  gap: 3px;
  width: 100%;
}

.detected-item small {
  color: var(--muted);
}

.empty,
.status-section p {
  color: var(--muted);
  font-size: 0.9rem;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: min(360px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 13px;
  background: rgba(20, 25, 35, 0.96);
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease, border-color 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.is-success {
  border-color: rgba(45, 212, 191, 0.7);
}

.toast.is-error {
  border-color: rgba(251, 113, 133, 0.75);
}

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

  textarea,
  .preview {
    min-height: 330px;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 14px;
  }

  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-status {
    text-align: left;
    min-width: 0;
  }

  .toolbar button {
    flex: 1 1 140px;
  }

  .toast {
    right: 14px;
    bottom: 14px;
  }

  .options label {
    white-space: normal;
  }
}
