:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #edf2f7;
  --line: #d7dee8;
  --text: #121820;
  --muted: #5d6b78;
  --accent: #39c6a3;
  --accent-2: #f2b84b;
  --danger: #ff6b6b;
  --ok: #53d769;
  --ad-bg: #fff8e7;
  --shadow: 0 18px 44px rgba(30, 44, 62, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root.dark {
  color-scheme: dark;
  --bg: #101316;
  --surface: #171c21;
  --surface-2: #20262d;
  --line: #303841;
  --text: #edf2f7;
  --muted: #98a5b3;
  --ad-bg: rgba(242, 184, 75, 0.08);
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 10%, rgba(57, 198, 163, 0.16), transparent 28rem),
    linear-gradient(135deg, var(--bg), #ffffff 55%, #f3f0e8);
  color: var(--text);
}

:root.dark body {
  background:
    radial-gradient(circle at 15% 10%, rgba(57, 198, 163, 0.14), transparent 28rem),
    linear-gradient(135deg, var(--bg), #13171b 55%, #1b1713);
}

button,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1720px, calc(100% - 20px));
  margin: 0 auto;
  padding: 8px 0 18px;
  font-size: 0.9rem;
}

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

.ad-slot {
  display: grid;
  place-items: center;
  gap: 4px;
  border: 1px dashed rgba(242, 184, 75, 0.74);
  border-radius: 8px;
  background: var(--ad-bg);
  color: var(--muted);
  text-align: center;
  font-size: 0.72rem;
  text-transform: uppercase;
}

.ad-slot strong {
  color: var(--text);
  font-size: 0.8rem;
}

.ad-slot-top,
.ad-slot-bottom {
  min-height: 58px;
  margin-bottom: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  object-fit: contain;
  display: block;
  padding: 2px;
  border: 1px solid rgba(57, 198, 163, 0.22);
  background: rgba(255, 255, 255, 0.72);
  border-radius: 8px;
}

h1,
h2,
p {
  margin: 0;
}

.brand-name {
  display: inline-block;
  color: var(--text);
  font-size: 1.08rem;
  font-weight: 800;
  line-height: 1.1;
  text-decoration: none;
}

.brand p,
.surface-head p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.86rem;
}

.top-actions,
.panel-actions,
.control-strip {
  display: flex;
  align-items: center;
  gap: 8px;
}

.primary-button,
.icon-button,
.link-button,
.segment,
.tool-item,
.quick-grid button {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--surface);
  border-radius: 8px;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.primary-button {
  min-height: 34px;
  padding: 0 12px;
  background: var(--accent);
  color: #07100d;
  border-color: transparent;
  font-weight: 700;
}

.icon-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.link-button {
  padding: 5px 9px;
  color: var(--accent);
}

button:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.workspace {
  display: grid;
  grid-template-columns: 184px minmax(0, 1fr) 150px;
  gap: 8px;
}

.sidebar,
.tool-surface,
.ad-rail {
  background: rgba(23, 28, 33, 0.88);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

:root:not(.dark) .sidebar,
:root:not(.dark) .tool-surface,
:root:not(.dark) .ad-rail {
  background: rgba(255, 255, 255, 0.88);
}

.sidebar {
  border-radius: 8px;
  padding: 10px;
  min-height: calc(100vh - 86px);
}

.ad-slot-sidebar {
  min-height: 170px;
  margin-top: 14px;
}

.ad-rail {
  position: sticky;
  top: 12px;
  align-self: start;
  display: grid;
  gap: 8px;
  border-radius: 8px;
  padding: 8px;
}

.ad-slot-rail {
  min-height: 500px;
}

.ad-slot-rail-small {
  min-height: 180px;
}

.tool-group + .tool-group,
.history-panel {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.group-label,
.eyebrow {
  color: var(--accent-2);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.tool-item {
  display: block;
  width: 100%;
  min-height: 32px;
  margin-top: 6px;
  padding: 0 9px;
  text-align: left;
  color: var(--muted);
  line-height: 30px;
  text-decoration: none;
}

.tool-item.active {
  color: var(--text);
  border-color: rgba(57, 198, 163, 0.7);
  background: rgba(57, 198, 163, 0.12);
}

.tool-surface {
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
}

.surface-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.surface-head h1 {
  margin-top: 4px;
  font-size: clamp(1.05rem, 1.5vw, 1.4rem);
  line-height: 1.2;
}

.status-pill {
  flex: 0 0 auto;
  min-width: 78px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  text-align: center;
  font-size: 0.85rem;
}

.status-pill.ok {
  color: var(--ok);
  border-color: rgba(83, 215, 105, 0.5);
}

.status-pill.error {
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.55);
}

.control-strip {
  flex-wrap: wrap;
  justify-content: space-between;
  padding: 10px 0;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.segment {
  min-height: 32px;
  padding: 0 10px;
  color: var(--muted);
}

.segment.active {
  color: #06100d;
  background: var(--accent);
  border-color: transparent;
  font-weight: 800;
}

.select-wrap,
.check-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

select {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 0 10px;
}

input[type="checkbox"] {
  accent-color: var(--accent);
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.editor-panel,
.inspector,
.quick-tools {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  min-width: 0;
}

.panel-head,
.section-title {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  font-weight: 800;
}

textarea {
  display: block;
  width: 100%;
  min-height: 540px;
  resize: vertical;
  border: 0;
  outline: 0;
  padding: 12px;
  background: #0c1014;
  color: #f5f7fa;
  font: 0.84rem/1.48 "Cascadia Code", "Fira Code", Consolas, monospace;
  border-radius: 0 0 8px 8px;
  tab-size: 2;
}

:root:not(.dark) textarea {
  background: #f8fafc;
  color: #111827;
}

.file-input {
  display: none;
}

textarea::placeholder {
  color: #748191;
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr);
  gap: 8px;
  margin-top: 8px;
}

.ad-slot-bottom {
  margin-top: 8px;
  margin-bottom: 8px;
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 2px 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.site-footer p {
  margin-top: 3px;
}

.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.site-footer a {
  color: var(--text);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--accent);
}

.legal-shell {
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.legal-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  padding: 24px;
}

:root.dark .legal-card {
  background: rgba(23, 28, 33, 0.9);
}

.legal-card h1 {
  font-size: 1.9rem;
}

.legal-card h2 {
  margin-top: 22px;
  font-size: 1.08rem;
}

.legal-card p,
.legal-card li {
  color: var(--muted);
  line-height: 1.65;
}

.legal-card p {
  margin-top: 10px;
}

.legal-card ul {
  padding-left: 20px;
}

.legal-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.legal-nav a {
  color: var(--text);
  text-decoration: none;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--line);
}

.stats-grid div {
  min-height: 76px;
  padding: 12px;
  background: var(--surface);
}

.stats-grid strong {
  display: block;
  font-size: 1.15rem;
}

.stats-grid span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.82rem;
}

.message-box {
  min-height: 68px;
  padding: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.message-box.error {
  color: var(--danger);
}

.message-box.ok {
  color: var(--ok);
}

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

.quick-grid button {
  min-height: 38px;
  padding: 0 10px;
  color: var(--muted);
  text-align: left;
}

.formatter-guide {
  margin-top: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.formatter-guide h2 {
  margin: 0;
  font-size: 1rem;
}

.formatter-guide p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.55;
}

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

.empty-state {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.history-list button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  text-align: left;
  padding: 9px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 980px) {
  .workspace,
  .editor-grid,
  .lower-grid {
    grid-template-columns: 1fr;
  }

  .ad-rail {
    display: none;
  }

  .sidebar {
    min-height: 0;
  }

  .tool-group {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .group-label {
    grid-column: 1 / -1;
  }

  .tool-item {
    margin-top: 0;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 18px, 1480px);
    padding-top: 10px;
  }

  .topbar,
  .surface-head,
  .site-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: space-between;
  }

  .tool-group,
  .stats-grid,
  .quick-grid {
    grid-template-columns: 1fr 1fr;
  }

  textarea {
    min-height: 360px;
  }
}
