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

:root {
  color-scheme: dark;
  --bg: #090b10;
  --bg-soft: #0d1118;
  --panel: #111827;
  --panel-2: #151d2e;
  --panel-3: #1a1024;
  --text: #f4f7fb;
  --muted: #aab4c2;
  --faint: #6f7b8b;
  --border: #2b3445;
  --cyan: #1ae8ff;
  --magenta: #ff4fd8;
  --amber: #f9d65c;
  --green: #56ff8b;
  --red: #ff6b7a;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
  --radius: 8px;
}

html {
  min-height: 100%;
  font-size: 18px;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(26, 232, 255, 0.08), transparent 32%),
    linear-gradient(225deg, rgba(255, 79, 216, 0.08), transparent 34%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-frame {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.history-rail {
  border-right: 1px solid var(--border);
  background: rgba(9, 11, 16, 0.78);
  backdrop-filter: blur(18px);
  width: min(320px, 88vw);
  height: 100vh;
  height: 100dvh;
  padding: 18px;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 900;
  transform: translateX(-105%);
  transition: transform 180ms ease;
  overflow: hidden;
}

body.history-open .history-rail {
  transform: translateX(0);
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  width: 100%;
  max-width: 100%;
  text-align: left;
  color: var(--text);
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius);
  padding: 10px;
}

.history-item:hover,
.history-item.active {
  background: var(--panel);
  border-color: var(--border);
}

.history-title {
  display: block;
  font-weight: 720;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  color: var(--muted);
  display: block;
  font-size: 0.78rem;
  margin-top: 2px;
}

.workspace {
  min-width: 0;
  padding: 18px;
}

.topbar,
.status-strip,
.panel {
  border: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.84);
  box-shadow: var(--shadow);
}

.topbar {
  border-radius: var(--radius);
  min-height: 74px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  flex: 0 0 auto;
}

.brand h1 {
  font-size: clamp(1.3rem, 2.2vw, 1.9rem);
  margin: 0;
  line-height: 1.05;
}

.brand-subline {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 3px;
}

.brand p {
  color: var(--muted);
  margin: 0;
  font-size: 0.9rem;
}

.version-badge {
  border: 1px solid rgba(26, 232, 255, 0.48);
  border-radius: 999px;
  color: var(--cyan);
  background: rgba(26, 232, 255, 0.08);
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  max-width: 100%;
  padding: 2px 9px;
  font-size: 0.74rem;
  font-weight: 820;
  line-height: 1.2;
  white-space: nowrap;
}

.topbar-actions,
.button-row,
.settings-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.icon-button,
.tool-button,
.mini-button,
.action-button,
.share-button {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--panel-2);
  min-height: 42px;
  transition: border-color 160ms ease, transform 160ms ease, background 160ms ease;
}

.icon-button {
  width: 44px;
  display: inline-grid;
  place-items: center;
}

.tool-button,
.mini-button,
.action-button,
.share-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  font-weight: 720;
}

.mini-button {
  min-height: 36px;
  font-size: 0.82rem;
  color: var(--muted);
}

.icon-button:hover,
.tool-button:hover,
.mini-button:hover,
.action-button:hover,
.share-button:hover {
  border-color: var(--cyan);
  transform: translateY(-1px);
}

.primary {
  background: linear-gradient(135deg, var(--cyan), var(--green));
  color: #031015;
  border-color: transparent;
}

.status-strip {
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  min-height: 46px;
  margin: 14px 0;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 0.86rem;
}

.status-strip span:first-child {
  color: var(--text);
  font-weight: 700;
  flex: 1 1 280px;
}

.status-strip a {
  color: var(--cyan);
}

.tool-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr) minmax(220px, 280px);
  gap: 14px;
  align-items: start;
}

.panel {
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}

.panel-head,
.preview-head,
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.panel h2,
.modal-panel h2 {
  margin: 0;
  font-size: 1rem;
}

.field-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin: 14px 0 6px;
  font-weight: 720;
}

.text-field,
.source-box {
  width: 100%;
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--bg-soft);
  border-radius: var(--radius);
  padding: 11px 12px;
  outline: none;
}

.text-field:focus,
.source-box:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(26, 232, 255, 0.13);
}

.source-box {
  min-height: 240px;
  resize: vertical;
}

.drop-zone {
  position: relative;
  border: 1px dashed rgba(26, 232, 255, 0.45);
  border-radius: var(--radius);
  min-height: 54px;
  display: grid;
  place-items: center;
  margin-top: 10px;
  color: var(--muted);
  background: rgba(26, 232, 255, 0.04);
  text-align: center;
  padding: 10px;
}

.drop-zone.dragging {
  border-color: var(--green);
  color: var(--green);
}

.drop-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}

.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  width: 42px;
  height: 24px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  border-radius: 999px;
  position: relative;
  flex: 0 0 auto;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 160ms ease, background 160ms ease;
}

.switch input:checked + span {
  border-color: var(--green);
}

.switch input:checked + span::after {
  transform: translateX(18px);
  background: var(--green);
}

.action-button {
  width: 100%;
  flex: 1 1 150px;
}

.preview-panel {
  min-height: calc(100vh - 152px);
}

.preview-source {
  color: var(--muted);
  margin: 0 0 4px;
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.preview-head h2 {
  margin: 0;
  font-size: clamp(1.4rem, 3vw, 2.4rem);
  line-height: 1.12;
}

.tabs {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  background: var(--bg-soft);
  display: flex;
  width: 100%;
}

.tab {
  flex: 1 1 0;
  min-height: 34px;
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 720;
}

.tab.active {
  background: var(--cyan);
  color: #031015;
}

.article-output {
  margin-top: 18px;
  border-top: 1px solid var(--border);
  padding-top: 18px;
  color: #eef5ff;
  font-size: 1.02rem;
}

.article-output h1,
.article-output h2,
.article-output h3 {
  color: var(--amber);
  margin: 1.2em 0 0.35em;
  line-height: 1.18;
}

.article-output p {
  margin: 0 0 0.9em;
}

.article-output ul,
.article-output ol {
  padding-left: 1.3em;
}

.article-output blockquote {
  border-left: 4px solid var(--magenta);
  margin: 1em 0;
  padding-left: 14px;
  color: var(--muted);
}

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  min-height: 240px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
}

.image-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.image-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-soft);
}

.image-card img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  display: block;
}

.image-card span {
  display: block;
  color: var(--muted);
  padding: 8px;
  font-size: 0.74rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.share-stack {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

body.export-link-ready #copy-result-btn,
body.export-link-ready .share-stack {
  display: none;
}

.export-result {
  margin-top: 14px;
  padding: 12px 0 14px;
  border-top: 1px solid rgba(26, 232, 255, 0.36);
  border-bottom: 1px solid rgba(255, 79, 216, 0.26);
}

body.export-link-ready .export-result {
  margin-top: 2px;
  border-top: 0;
}

.export-result[hidden] {
  display: none;
}

.export-kicker {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 850;
  text-transform: uppercase;
}

.export-title {
  color: var(--cyan);
  display: inline-block;
  font-weight: 850;
  margin-bottom: 10px;
  overflow-wrap: anywhere;
}

.export-url-label {
  color: var(--muted);
  display: block;
  font-size: 0.78rem;
  font-weight: 720;
  margin-bottom: 5px;
}

.export-url {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(26, 232, 255, 0.42);
  border-radius: var(--radius);
  background: rgba(6, 13, 22, 0.92);
  color: var(--text);
  padding: 9px 10px;
  font: inherit;
  font-size: 0.84rem;
}

.export-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.export-actions .mini-button {
  justify-content: flex-start;
  min-width: 0;
}

.share-button {
  width: 100%;
  justify-content: flex-start;
  min-height: 48px;
}

.share-button.accent-cyan {
  border-color: rgba(26, 232, 255, 0.55);
}

.share-button.accent-magenta {
  border-color: rgba(255, 79, 216, 0.55);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.modal-panel {
  position: relative;
  width: min(520px, 100%);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 16px;
}

.bookmarklet-link {
  color: var(--cyan);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  text-decoration: none;
  font-weight: 720;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(20px);
  background: #061115;
  border: 1px solid var(--cyan);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 1200;
  max-width: min(680px, calc(100vw - 36px));
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1120px) {
  .tool-grid {
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  }

  .action-rail {
    grid-column: 1 / -1;
  }

  .share-stack {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .export-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  html {
    font-size: 17px;
  }

  .workspace {
    padding: 10px;
  }

  .topbar,
  .preview-head,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions,
  .tabs,
  .tool-button,
  .mini-button {
    width: 100%;
  }

  .tool-button,
  .mini-button {
    justify-content: center;
  }

  .tool-grid {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    min-height: auto;
  }

  .share-stack {
    grid-template-columns: 1fr 1fr;
  }

  .export-actions {
    grid-template-columns: 1fr 1fr;
  }

  .switch-row {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
