@font-face {
  font-family: "Workshop UI";
  src: url("assets/fonts/SegUIVar.ttf") format("truetype");
  font-display: swap;
}

:root {
  color-scheme: dark;
  --ink: #f6f8ff;
  --muted: #91a0ba;
  --canvas: #ffffff;
  --shell: #0d1525;
  --panel: #121d31;
  --panel-raised: #18253c;
  --line: #293953;
  --violet: #8b72ff;
  --violet-pressed: #7459f2;
  --green: #65dfa7;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html { background: var(--shell); }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--shell);
  color: var(--ink);
  font-family: "Workshop UI", -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px calc(106px + var(--safe-bottom));
}

.app-header,
.panel-heading,
.template-row,
.action-dock {
  display: flex;
  align-items: center;
}

.app-header {
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

h1, h2, p { margin: 0; }
h1 { font-size: clamp(27px, 7vw, 38px); letter-spacing: -0.04em; }
h2 { font-size: 22px; letter-spacing: -0.025em; }

.eyebrow {
  margin-bottom: 4px;
  color: var(--green);
  font-size: 11px;
  font-weight: 720;
  letter-spacing: 0.16em;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 520px) minmax(320px, 1fr);
  gap: 22px;
  align-items: start;
}

.preview-column,
.editor-panel {
  min-width: 0;
}

.template-row {
  align-items: end;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.compact-field:first-child { flex: 0 0 42%; }
.template-name-field { flex: 1; }

.template-actions {
  display: flex;
  flex: 1 0 100%;
  gap: 8px;
}

.mini-button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid #354764;
  border-radius: 10px;
  background: #18253c;
  color: #edf2ff;
  font-weight: 700;
}

.mini-button.danger { color: #ffbdc5; border-color: #75404b; }
.file-field input { padding: 8px 10px; }
.file-field input::file-selector-button {
  margin-right: 10px;
  padding: 7px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--violet);
  color: white;
  font: inherit;
  font-weight: 700;
}

.canvas-frame {
  position: relative;
  display: flex;
  justify-content: center;
  overflow: hidden;
  padding: 13px 13px 13px 42px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: #0a1120;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

canvas {
  display: block;
  width: min(100%, 410px);
  height: auto;
  aspect-ratio: 750 / 1334;
  background: var(--canvas);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
}

.canvas-rail {
  position: absolute;
  inset: 13px auto 13px 9px;
  display: flex;
  width: 25px;
  align-items: center;
  justify-content: space-between;
  color: #72819b;
  font-size: 9px;
  letter-spacing: 0.08em;
  writing-mode: vertical-rl;
}

.canvas-rail strong { color: #b8c4d8; font-size: 10px; }

.loading-cover {
  position: absolute;
  inset: 13px 13px 13px 42px;
  display: grid;
  place-items: center;
  background: rgba(13, 21, 37, 0.88);
  color: #cbd5e7;
  font-size: 14px;
  transition: opacity 180ms ease;
}

.loading-cover.hidden { opacity: 0; pointer-events: none; }

.editor-panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
}

.panel-heading {
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--line);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 13px;
  padding-top: 16px;
}

.field { display: grid; gap: 7px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field > span { color: #d7deeb; font-size: 13px; font-weight: 670; }
.field small { color: var(--muted); font-size: 11px; }

input, textarea, select {
  width: 100%;
  min-height: 46px;
  border: 1px solid #354764;
  border-radius: 12px;
  outline: 0;
  background: #0d1729;
  color: #fff;
  font-size: 16px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input, select { padding: 0 13px; }
textarea { resize: vertical; padding: 12px 13px; line-height: 1.42; }

input:focus, textarea:focus, select:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 3px rgba(139, 114, 255, 0.17);
}

.hidden { display: none !important; }

.quiet-button,
.secondary-action,
.primary-action {
  min-height: 43px;
  border-radius: 12px;
  font-weight: 720;
  cursor: pointer;
}

.quiet-button {
  padding: 0 13px;
  border: 1px solid var(--line);
  background: var(--panel-raised);
  color: #dbe4f4;
}

.privacy-note {
  margin-top: 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.action-dock {
  position: fixed;
  z-index: 20;
  right: max(16px, calc((100vw - 1120px) / 2 + 18px));
  bottom: calc(12px + var(--safe-bottom));
  gap: 10px;
  padding: 9px;
  border: 1px solid rgba(107, 126, 157, 0.34);
  border-radius: 18px;
  background: rgba(13, 21, 37, 0.92);
  box-shadow: 0 16px 46px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.secondary-action,
.primary-action { border: 0; padding: 0 20px; }
.secondary-action { background: #273650; color: #fff; }
.primary-action { background: var(--violet); color: #fff; }
.primary-action:active { background: var(--violet-pressed); }

dialog {
  width: min(390px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  color: var(--ink);
}

dialog::backdrop { background: rgba(2, 8, 18, 0.76); backdrop-filter: blur(7px); }
.dialog-card { padding: 23px; }
.dialog-card h2 { margin-bottom: 13px; }
.dialog-card ol { margin: 0 0 20px; padding-left: 22px; color: #ccd5e5; line-height: 1.8; }
.dialog-card .primary-action { width: 100%; }

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: calc(85px + var(--safe-bottom));
  max-width: calc(100% - 36px);
  padding: 11px 16px;
  border-radius: 999px;
  background: #ecf2ff;
  color: #101827;
  font-size: 13px;
  font-weight: 720;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

@media (max-width: 790px) {
  .app-shell { padding-inline: 12px; }
  .workspace { grid-template-columns: 1fr; gap: 14px; }
  .app-header { margin-bottom: 13px; }
  .app-header .quiet-button { min-height: 39px; }
  .template-row { display: grid; grid-template-columns: 1fr; }
  .canvas-frame { border-radius: 18px; }
  .editor-panel { border-radius: 18px; padding: 15px; }
  .action-dock { right: 12px; left: 12px; justify-content: stretch; }
  .action-dock button { flex: 1; }
}

@media (max-width: 430px) {
  .app-shell { padding-top: max(12px, env(safe-area-inset-top)); }
  .app-header h1 { font-size: 29px; }
  .canvas-frame { padding: 9px 9px 9px 34px; }
  .canvas-rail { inset: 9px auto 9px 6px; }
  .loading-cover { inset: 9px 9px 9px 34px; }
  .field-grid { gap: 11px; }
  .panel-heading { align-items: flex-end; }
  .panel-heading .quiet-button { padding-inline: 10px; font-size: 12px; }
}

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