:root {
  --accent: #ff0930;
  --bg: #101010;
  --panel: #161616;
  --surface: rgba(255,255,255,.045);
  --surface-hover: rgba(255,255,255,.07);
  --line: rgba(255,255,255,.1);
  --text: #fff;
  --muted: rgba(255,255,255,.58);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }

body { margin: 0; min-width: 320px; background: var(--bg); }
button, input, textarea { font: inherit; }
button { color: inherit; }

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  min-height: 74px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(16,16,16,.94);
  backdrop-filter: blur(16px);
}

.topbar h1, .topbar p { margin: 0; }
.topbar h1 { font-size: 1.25rem; font-weight: 600; letter-spacing: -.015em; }
.topbar-kicker { margin-bottom: 3px !important; color: var(--accent); font-size: .7rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.save-state { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .8rem; }
.save-state span { width: 7px; height: 7px; border-radius: 50%; background: #66d28a; }

.download-button {
  min-height: 42px;
  padding: 10px 17px;
  border: 0;
  border-radius: 9px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  font-weight: 600;
  transition: opacity .15s ease;
}

.download-button:hover { opacity: .84; }
.download-button:active { opacity: .7; }
.download-button:disabled { cursor: not-allowed; opacity: .35; }
.download-button:focus-visible, .device-switcher button:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.workspace {
  display: grid;
  min-height: calc(100vh - 74px);
  grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
}

.editor {
  overflow-y: auto;
  max-height: calc(100vh - 74px);
  padding: 20px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.editor-intro { margin-bottom: 16px; }
.editor-intro h2, .preview-toolbar h2 { margin: 0 0 4px; font-size: 1rem; font-weight: 600; }
.editor-intro p, .preview-toolbar p { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.45; }

.form-section {
  margin-bottom: 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.form-section > summary {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 14px;
  cursor: pointer;
  font-size: .875rem;
  font-weight: 550;
  list-style: none;
}

.form-section > summary::-webkit-details-marker { display: none; }
.form-section > summary::after { content: "+"; color: var(--muted); font-size: 1.05rem; font-weight: 400; }
.form-section[open] > summary::after { content: "−"; }
.form-section > summary:hover { background: rgba(255,255,255,.025); }
.fields { display: grid; gap: 13px; padding: 2px 14px 16px; }
.subgroup { display: grid; gap: 10px; padding-top: 13px; border-top: 1px solid var(--line); }
.subgroup:first-child { padding-top: 0; border-top: 0; }
.subgroup-title { margin: 0; color: var(--muted); font-size: .72rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }

.field { display: grid; gap: 6px; }
.field-label { color: rgba(255,255,255,.72); font-size: .75rem; }
input[type="text"], input[type="url"], textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #fff;
  background: rgba(0,0,0,.24);
}

input[type="text"], input[type="url"] { height: 40px; padding: 0 11px; }
textarea { min-height: 74px; padding: 10px 11px; line-height: 1.4; resize: vertical; }
input:hover, textarea:hover { border-color: rgba(255,255,255,.17); }

.color-row { display: grid; grid-template-columns: 44px 1fr; gap: 8px; }
input[type="color"] { width: 44px; height: 40px; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: rgba(0,0,0,.24); cursor: pointer; }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 5px; }

.switch-field { display: flex; min-height: 34px; align-items: center; justify-content: space-between; gap: 16px; }
.switch-field .field-label { color: #fff; font-size: .8125rem; }
.switch { position: relative; display: inline-flex; flex: 0 0 auto; }
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch-ui { width: 38px; height: 22px; padding: 3px; border-radius: 999px; background: rgba(255,255,255,.16); cursor: pointer; transition: background-color .15s ease; }
.switch-ui::after { display: block; width: 16px; height: 16px; border-radius: 50%; background: #fff; content: ""; transition: transform .15s ease; }
.switch input:checked + .switch-ui { background: var(--accent); }
.switch input:checked + .switch-ui::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-ui { outline: 2px solid var(--accent); outline-offset: 2px; }

.file-control { display: grid; gap: 7px; }
.file-control input { width: 100%; color: var(--muted); font-size: .75rem; }
.file-control input::file-selector-button { margin-right: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; color: #fff; background: var(--surface); cursor: pointer; }
.file-meta { margin: 0; color: var(--muted); font-size: .72rem; }

.preview-panel { min-width: 0; background: #0c0c0c; }
.preview-toolbar {
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}

#sizeText.is-over { color: #ff778c; }
.device-switcher { display: flex; padding: 3px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.device-switcher button { min-height: 30px; padding: 5px 10px; border: 0; border-radius: 6px; color: var(--muted); background: transparent; cursor: pointer; font-size: .75rem; }
.device-switcher button:hover { color: #fff; }
.device-switcher button.is-active { color: #fff; background: rgba(255,255,255,.1); }

.preview-stage {
  overflow: auto;
  height: calc(100vh - 142px);
  padding: 28px;
  background-color: #0c0c0c;
  background-image: linear-gradient(45deg, rgba(255,255,255,.018) 25%, transparent 25%), linear-gradient(-45deg, rgba(255,255,255,.018) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, rgba(255,255,255,.018) 75%), linear-gradient(-45deg, transparent 75%, rgba(255,255,255,.018) 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

#previewFrame {
  display: block;
  width: 360px;
  min-height: 100%;
  margin: 0 auto;
  border: 0;
  border-radius: 12px;
  background: #151515;
  box-shadow: 0 0 0 1px rgba(255,255,255,.12);
  transition: width .2s ease;
}

.toast { position: fixed; z-index: 20; right: 18px; bottom: 18px; max-width: 340px; padding: 11px 14px; border: 1px solid var(--line); border-radius: 9px; color: #fff; background: #292929; opacity: 0; pointer-events: none; transform: translateY(6px); transition: opacity .18s ease, transform .18s ease; font-size: .82rem; }
.toast.is-visible { opacity: 1; transform: none; }

@media (max-width: 900px) {
  .topbar { position: static; align-items: flex-start; }
  .save-state { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .editor { max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .preview-stage { height: 760px; padding: 20px 12px; }
}

@media (max-width: 540px) {
  .topbar { padding: 13px 14px; }
  .topbar-kicker { display: none; }
  .topbar h1 { font-size: 1rem; }
  .download-button { min-height: 38px; padding: 8px 12px; font-size: .8rem; }
  .editor { padding: 14px; }
  .preview-toolbar { align-items: flex-start; padding: 12px 14px; }
  .device-switcher button { padding-inline: 8px; }
  .preview-stage { overflow-x: auto; justify-content: flex-start; }
}

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