:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef3f2;
  --text: #111827;
  --muted: #5b6675;
  --border: #d9e1e7;
  --accent: #0f766e;
  --accent-strong: #0b5f58;
  --accent-soft: #e0f2f1;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(15, 23, 42, .08);
  --radius: 20px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #111827;
    --surface-2: #162033;
    --text: #f3f6fb;
    --muted: #a8b3c2;
    --border: #263449;
    --accent: #2dd4bf;
    --accent-strong: #5eead4;
    --accent-soft: #12312e;
    --danger: #fda29b;
    --shadow: 0 18px 45px rgba(0, 0, 0, .28);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button, input, textarea, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(14px + env(safe-area-inset-top, 0px)) clamp(16px, 4vw, 34px) 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 44px; height: 44px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
}
.logo svg { width: 25px; height: 25px; fill: currentColor; }
.brand h1 { margin: 0; font-size: clamp(19px, 4vw, 26px); letter-spacing: -.03em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.pill, .badge {
  display: inline-flex; align-items: center; min-height: 32px;
  padding: 6px 11px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-strong);
  border: 1px solid var(--border); font-size: 13px; font-weight: 700; white-space: nowrap;
}
.badge { min-height: 30px; font-size: 12px; }

.layout {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 30px);
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(340px, .95fr);
  gap: 18px;
  align-items: start;
}
.left-col, .right-col { display: grid; gap: 18px; min-width: 0; }
.right-col { position: sticky; top: 92px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(18px, 3vw, 26px);
}
.card h2 { margin: 0; font-size: 21px; letter-spacing: -.02em; }
.card-head { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; margin-bottom: 18px; }
.card-head p, .field small, .mode-card small { color: var(--muted); }
.card-head p { margin: 4px 0 0; font-size: 14px; }

.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { display: grid; gap: 7px; margin-bottom: 14px; font-weight: 700; }
.field > span:first-child { font-size: 14px; }
.field small { font-weight: 500; font-size: 12.5px; }
input, textarea, select {
  width: 100%; min-height: 48px;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text);
  padding: 12px 13px; outline: none;
}
textarea { min-height: 120px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; }
#htmlInput { min-height: 300px; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }

.password-wrap { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.mini-btn, .btn, .tab {
  min-height: 44px; border-radius: 13px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 10px 14px; cursor: pointer; font-weight: 800;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #04211d; } }
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost:hover, .mini-btn:hover, .tab:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.big { min-height: 54px; padding-inline: 22px; font-size: 16px; }
button:disabled { opacity: .58; cursor: not-allowed; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.hidden { display: none !important; }

.status {
  margin: 14px 0 0; padding: 12px 13px; border-radius: 14px;
  background: var(--surface-2); color: var(--muted); font-size: 14px;
}
.status.ok { color: var(--accent-strong); }
.status.err { color: var(--danger); }

.mode-box { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; border: 0; padding: 0; margin: 4px 0 16px; }
.mode-box legend { font-weight: 800; margin-bottom: 8px; }
.mode-card {
  display: flex; gap: 10px; align-items: flex-start;
  border: 1px solid var(--border); border-radius: 16px; padding: 14px; cursor: pointer; background: var(--surface);
}
.mode-card input { width: 20px; min-height: 20px; margin-top: 2px; accent-color: var(--accent); }
.mode-card span { display: grid; gap: 2px; }
.mode-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

.toolbar {
  display: grid; grid-template-columns: auto minmax(140px, 1fr) auto minmax(140px, 1fr) auto auto;
  gap: 8px; margin: 8px 0 14px;
}
.check { display: flex; gap: 10px; align-items: center; min-height: 48px; font-weight: 700; }
.check input { width: 20px; min-height: 20px; accent-color: var(--accent); }
.summary { align-self: center; color: var(--muted); font-weight: 700; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

.preview-card iframe {
  width: 100%; min-height: 520px; border: 1px solid var(--border); border-radius: 16px; background: #fff;
}
.clean-list { margin: 12px 0 0; padding-left: 20px; color: var(--muted); }
.clean-list li + li { margin-top: 8px; }
.mobile-tabs { display: none; gap: 8px; }
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (prefers-color-scheme: dark) { .tab.active { color: #04211d; } }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding-bottom: calc(96px + var(--safe-bottom)); }
  .right-col { position: static; }
  .mobile-tabs { display: flex; }
  .layout:not(.show-preview) .preview-card { display: none; }
  .layout.show-preview .compose-card { display: none; }
  .preview-card iframe { min-height: 62vh; }
  .actions {
    position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-bottom)); z-index: 30;
    padding: 10px; border: 1px solid var(--border); border-radius: 18px;
    background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(16px); box-shadow: var(--shadow);
  }
  .actions .btn { flex: 1; }
}

@media (max-width: 640px) {
  .topbar { align-items: flex-start; }
  .brand p { display: none; }
  .grid.two, .mode-box { grid-template-columns: 1fr; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar input, .toolbar select { grid-column: span 2; }
  .card-head { flex-direction: column; }
  #htmlInput { min-height: 240px; }
  .top-actions { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}


.origin-box {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center;
  border: 1px solid var(--border); border-radius: 14px; padding: 12px; margin: 0 0 14px; background: var(--surface-2);
}
.origin-box span { font-weight: 800; font-size: 13px; }
.origin-box code { overflow-wrap: anywhere; color: var(--accent-strong); font-weight: 700; }
input[readonly] { background: var(--surface-2); }
@media (max-width: 640px) { .origin-box { grid-template-columns: 1fr; } }

.api-docs {
  margin: 14px 0 0; padding: 14px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface-2); color: var(--muted); overflow-x: auto; font-size: 12.5px; line-height: 1.55;
}

.direct-box { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.direct-box h3 { margin: 0 0 6px; font-size: 17px; }
.direct-box p { color: var(--muted); }
