:root {
  color-scheme: light;
  --ink: #151515;
  --muted: #6d6962;
  --paper: #fffef9;
  --canvas: #e7e5df;
  --accent: #ff5b2d;
  --accent-dark: #d9431c;
  --line: #cdc8bf;
  --ok: #16865a;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; color: var(--ink); background: radial-gradient(circle at 100% 0, #ffe2d7 0, transparent 30rem), var(--canvas); padding-bottom: 112px; }
.topbar { max-width: 1120px; margin: auto; padding: 24px 18px 18px; display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.brand { display: flex; gap: 11px; align-items: flex-start; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; background: var(--ink); color: var(--accent); font-size: 19px; box-shadow: 3px 3px 0 var(--accent); }
.eyebrow { font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; margin: 0 0 7px; color: var(--muted); }
h1 { font-size: clamp(25px, 7vw, 42px); line-height: 1.02; letter-spacing: -.045em; margin: 0; }
h2 { font-size: 22px; letter-spacing: -.03em; margin: 0; }
.status-pill { border: 1px solid var(--line); background: rgba(255,254,249,.8); border-radius: 999px; padding: 10px 12px; display: flex; align-items: center; gap: 7px; font-weight: 750; white-space: nowrap; cursor: pointer; }
.status-pill span:first-child { width: 9px; height: 9px; border-radius: 50%; background: #aaa; }
.status-pill.online span:first-child { background: var(--ok); }
.status-pill.offline span:first-child { background: var(--accent); }
main { display: grid; gap: 16px; padding: 0 12px; max-width: 1120px; margin: auto; }
.editor, .preview-card { background: rgba(255,254,249,.92); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: 0 3px 0 rgba(23,23,23,.06); }
.section-top { padding: 19px 18px 16px; display: flex; align-items: end; justify-content: space-between; gap: 12px; }
.x5-badge, .preview-heading > span { font: 700 12px ui-monospace, monospace; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 6px 8px; background: var(--paper); white-space: nowrap; }
.tabs { display: grid; grid-template-columns: repeat(2,1fr); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 6px; gap: 5px; }
.tab { min-height: 46px; border: 0; background: transparent; border-radius: 12px; font-weight: 750; font-size: 15px; cursor: pointer; }
.tab span { margin-right: 6px; font-family: ui-monospace, monospace; }
.tab.active { background: var(--ink); color: white; }
form { padding: 18px; }
.mode-panel { display: none; }
.mode-panel.active { display: block; }
label { display: grid; gap: 8px; font-weight: 720; font-size: 14px; }
textarea, input, select { font: inherit; color: inherit; }
textarea, input:not([type=range]):not([type=checkbox]):not([type=hidden]), select { width: 100%; border: 1px solid var(--line); background: var(--paper); border-radius: 12px; padding: 13px; min-height: 48px; }
textarea { resize: vertical; font-size: 17px; line-height: 1.45; }
textarea:focus, input:focus, select:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }

.text-editor { border: 1px solid var(--line); background: var(--paper); border-radius: 13px; overflow: hidden; box-shadow: inset 0 1px 0 white; }
.editor-toolbar { min-height: 47px; padding: 6px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 4px; background: #f2f0eb; }
.format-button { width: 35px; height: 34px; border: 0; border-radius: 8px; background: transparent; color: var(--ink); font-size: 18px; cursor: pointer; }
.format-button:hover, .format-button.active { background: var(--ink); color: white; }
.right-align { text-align: right; padding-right: 8px; }
.toolbar-divider { height: 24px; width: 1px; background: var(--line); margin: 0 3px; }
.editor-count { margin-left: auto; color: var(--muted); font: 700 11px ui-monospace, monospace; padding: 0 7px; }
.text-editor textarea { border: 0; border-radius: 0; background: transparent; box-shadow: none; min-height: 190px; }
.text-editor textarea:focus { outline: 0; }
.field-meta { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; margin: 7px 2px 18px; }
.control-grid { display: grid; grid-template-columns: 1fr; gap: 15px; }
.control-grid label:not(.check) output { justify-self: end; color: var(--muted); font: 700 12px ui-monospace, monospace; }
.check { display: flex; align-items: center; gap: 10px; min-height: 48px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 13px; background: var(--paper); }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
input[type=range] { width: 100%; accent-color: var(--accent); }
.file-drop { border: 2px dashed var(--line); border-radius: 14px; padding: 32px 18px; text-align: center; place-items: center; background: linear-gradient(135deg, #fffef9, #fff1eb); cursor: pointer; }
.upload-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--ink); color: white; font-size: 20px; }
.file-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-name { text-align: center; margin: 10px 0 20px; color: var(--ink); font-size: 14px; overflow-wrap: anywhere; }
.hint, .preview-note { color: var(--muted); font-size: 13px; line-height: 1.45; }
.advanced { border-top: 1px solid var(--line); margin: 22px -18px -18px; padding: 0 18px; }
.advanced summary { cursor: pointer; font-weight: 750; padding: 18px 0; display: flex; justify-content: space-between; }
.advanced summary span { color: var(--muted); font-size: 12px; font-weight: 600; }
.advanced-grid { padding-bottom: 4px; }
.preview-card { padding: 18px; }
.preview-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 16px; }
.paper-shell { background: repeating-linear-gradient(135deg, #d9d5cb 0 8px, #d4d0c6 8px 16px); border-radius: 12px; padding: 18px 10px; display: grid; place-items: start center; min-height: 300px; max-height: 58vh; overflow: auto; }
.paper-shell img { width: min(100%,384px); height: auto; display: none; image-rendering: pixelated; box-shadow: 0 7px 20px rgba(0,0,0,.16); }
.paper-shell p { align-self: center; color: var(--muted); text-align: center; }
.preview-note { margin: 14px 0 0; }
.action-bar { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; background: rgba(255,254,249,.94); border-top: 1px solid var(--line); padding: 12px max(14px,env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(14px,env(safe-area-inset-left)); display: flex; align-items: center; gap: 12px; backdrop-filter: blur(14px); }
.action-copy { display: grid; min-width: 0; flex: 1; }
.action-copy strong, .action-copy span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.action-copy strong { font-size: 15px; }
.action-copy span { font-size: 12px; color: var(--muted); margin-top: 2px; }
.action-bar button { border: 0; border-radius: 13px; background: var(--accent); color: white; font: 800 16px/1 inherit; padding: 15px 17px; box-shadow: 0 3px 0 var(--accent-dark); cursor: pointer; white-space: nowrap; }
.action-bar button:hover { background: var(--accent-dark); }
.action-bar button:disabled { cursor: not-allowed; background: #b4afa6; box-shadow: none; }
.toast { position: fixed; z-index: 30; left: 50%; bottom: 98px; transform: translate(-50%,14px); width: min(420px,calc(100% - 28px)); background: var(--ink); color: white; border-radius: 12px; padding: 13px 16px; text-align: center; font-weight: 650; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; }
.toast.show { opacity: 1; transform: translate(-50%,0); }

@media (min-width: 680px) {
  .control-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .topbar { padding: 34px 24px 22px; }
  main { padding: 0 24px; }
  .action-bar { left: 50%; right: auto; bottom: 20px; transform: translateX(-50%); width: min(700px,calc(100% - 32px)); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 12px 40px rgba(0,0,0,.14); }
  .toast { bottom: 112px; }
}
@media (min-width: 940px) {
  main { grid-template-columns: minmax(0,1fr) 430px; align-items: start; }
  .preview-card { position: sticky; top: 20px; }
  .paper-shell { max-height: 65vh; }
  .topbar { padding-top: 45px; }
  .editor form { padding: 24px; }
  .section-top { padding: 24px 24px 18px; }
  .advanced { margin-left: -24px; margin-right: -24px; margin-bottom: -24px; padding-left: 24px; padding-right: 24px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
