:root {
  --ink: #313232;
  --ink-soft: #5b5d5e;
  --cyan: #0da3c8;
  --cyan-dark: #007bb5;
  --amber: #ffb000;
  --mist: #f6f8fc;
  --mist-2: #edf1f8;
  --white: #ffffff;
  --line: #dfe6f0;
  --danger: #d64545;
  --radius: 14px;
  --shadow-sm: 0 1px 3px rgba(0, 37, 54, 0.08);
  --shadow-md: 0 8px 28px rgba(0, 37, 54, 0.10);
  --shadow-lg: 0 20px 60px rgba(0, 37, 54, 0.18);
  --font-body: 'Open Sans', 'Segoe UI', Arial, sans-serif;
  --font-display: 'Oswald', 'Segoe UI', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--mist);
  color: var(--ink);
  background-image:
    radial-gradient(1200px 500px at 80% -10%, rgba(13, 163, 200, 0.09), transparent 60%),
    radial-gradient(900px 420px at -10% 110%, rgba(255, 176, 0, 0.07), transparent 60%);
  background-attachment: fixed;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
  background: var(--ink);
  color: var(--white);
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 2px 14px rgba(0, 37, 54, 0.25);
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark svg { display: block; border-radius: 8px; box-shadow: 0 0 0 2px rgba(13,163,200,0.35); }
.brand-text h1 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0;
  line-height: 1.1;
  white-space: nowrap;
}
.brand-text h1 span { color: var(--cyan); }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: #b9c3ce; letter-spacing: 0.02em; }
.pill {
  background: var(--amber);
  color: var(--ink);
  font-weight: 700;
  font-size: 11px;
  border-radius: 999px;
  padding: 2px 8px;
  line-height: 1.4;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--cyan), var(--cyan-dark));
  color: var(--white);
  padding: 15px 22px;
  box-shadow: 0 6px 18px rgba(13, 163, 200, 0.35);
}
.btn-primary:not(:disabled):hover { box-shadow: 0 10px 26px rgba(13, 163, 200, 0.45); transform: translateY(-1px); }
.btn-ghost {
  background: rgba(255,255,255,0.08);
  color: inherit;
  padding: 9px 14px;
  border: 1px solid rgba(127, 140, 150, 0.35);
}
.topbar .btn-ghost { color: var(--white); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,0.16); }
.panel .btn-ghost { background: var(--white); color: var(--ink); border-color: var(--line); }
.panel .btn-ghost:not(:disabled):hover { border-color: var(--cyan); color: var(--cyan-dark); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn-tiny { padding: 4px 10px; font-size: 12px; background: var(--mist-2); border-radius: 6px; color: var(--ink); }
.btn-tiny:hover { background: var(--line); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 24px;
  padding: 28px clamp(16px, 4vw, 40px) 48px;
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}
.panel {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(223, 230, 240, 0.7);
}
.input-panel { padding: 26px; position: sticky; top: 96px; }

.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.panel-head.second { margin-top: 26px; }
.panel-head h2 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin: 0;
}
.panel-head h2 em { font-style: normal; color: var(--ink-soft); font-weight: 400; text-transform: none; letter-spacing: 0; font-size: 13px; font-family: var(--font-body); }
.step-num {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--ink);
  color: var(--amber);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  border-radius: 8px;
  flex: none;
}

/* ---------- Dropzone ---------- */
.dropzone {
  border: 2px dashed var(--line);
  border-radius: 12px;
  background: var(--mist);
  min-height: 190px;
  display: flex;
  align-items: stretch;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  outline: none;
  overflow: hidden;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--cyan); background: #eefafd; }
.dropzone.dragover {
  border-color: var(--cyan);
  background: #e4f7fb;
  box-shadow: inset 0 0 0 4px rgba(13,163,200,0.12);
}
.dz-empty { align-self: center; text-align: center; padding: 28px 20px; color: var(--ink-soft); }
.dz-icon { color: var(--cyan); margin-bottom: 10px; }
.dz-title { margin: 0 0 4px; font-weight: 700; color: var(--ink); font-size: 15px; }
.dz-sub { margin: 0; font-size: 12.5px; }
.dz-preview { width: 100%; display: flex; flex-direction: column; }
.dz-preview img {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  background:
    linear-gradient(45deg, #eef1f6 25%, transparent 25%, transparent 75%, #eef1f6 75%),
    linear-gradient(45deg, #eef1f6 25%, #fbfcfe 25%, #fbfcfe 75%, #eef1f6 75%);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
}
.dz-meta {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; background: var(--white); border-top: 1px solid var(--line);
}
.dz-filename { font-size: 12.5px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Notes ---------- */
.notes {
  width: 100%;
  resize: vertical;
  min-height: 90px;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--mist);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.notes:focus { outline: none; border-color: var(--cyan); background: var(--white); box-shadow: 0 0 0 4px rgba(13,163,200,0.12); }

.btn-generate { width: 100%; justify-content: center; margin-top: 22px; font-size: 15.5px; letter-spacing: 0.01em; }
.btn-generate .btn-label, .btn-generate .btn-loading { display: inline-flex; align-items: center; gap: 9px; }
.spinner {
  width: 17px; height: 17px;
  border: 2.5px solid rgba(255,255,255,0.35);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hint { font-size: 12px; color: var(--ink-soft); line-height: 1.6; margin: 14px 2px 0; }

.error-box {
  margin-top: 16px;
  display: flex; align-items: flex-start; gap: 9px;
  background: #fdeeee;
  border: 1px solid #f2c7c7;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.5;
  padding: 12px 14px;
  border-radius: 10px;
}
.error-box svg { flex: none; margin-top: 1px; }

/* ---------- Output panel ---------- */
.output-panel { display: flex; flex-direction: column; min-height: calc(100vh - 160px); overflow: hidden; }
.output-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--white);
  flex-wrap: wrap;
  border-radius: var(--radius) var(--radius) 0 0;
}
.tabs { display: flex; gap: 4px; background: var(--mist-2); padding: 4px; border-radius: 10px; }
.tab {
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 13px;
  font-weight: 500;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  padding: 7px 18px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.tab.active { background: var(--ink); color: var(--white); box-shadow: var(--shadow-sm); }
.toolbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.device-toggle { display: flex; background: var(--mist-2); border-radius: 9px; padding: 3px; }
.dev-btn {
  border: 0; background: transparent; color: var(--ink-soft);
  padding: 6px 12px; border-radius: 7px; cursor: pointer; display: inline-flex;
  transition: background 0.15s ease, color 0.15s ease;
}
.dev-btn.active { background: var(--cyan); color: var(--white); }

.output-stage {
  flex: 1;
  position: relative;
  background:
    linear-gradient(rgba(246,248,252,0.92), rgba(246,248,252,0.92)),
    repeating-linear-gradient(0deg, transparent, transparent 23px, #dde4ef 23px, #dde4ef 24px),
    repeating-linear-gradient(90deg, transparent, transparent 23px, #dde4ef 23px, #dde4ef 24px);
  border-radius: 0 0 var(--radius) var(--radius);
  display: flex;
  overflow: hidden;
}

/* empty state */
.stage-empty {
  margin: auto; text-align: center; color: var(--ink-soft);
  padding: 40px 24px; animation: fadeUp 0.4s ease;
}
.stage-empty p { margin: 6px 0 0; font-size: 15px; font-weight: 600; color: var(--ink); }
.stage-empty .stage-empty-sub { font-weight: 400; font-size: 13px; color: var(--ink-soft); }
.skeleton-mail {
  width: 200px; margin: 0 auto 22px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  box-shadow: var(--shadow-md);
}
.sk { border-radius: 5px; background: var(--mist-2); }
.sk-logo { width: 60px; height: 12px; margin-bottom: 10px; background: var(--cyan); opacity: 0.55; }
.sk-hero { height: 56px; margin-bottom: 10px; background: var(--ink); opacity: 0.85; position: relative; }
.sk-hero::after {
  content: ''; position: absolute; left: 25%; right: 25%; top: 40%; height: 9px;
  background: var(--amber); border-radius: 4px;
}
.sk-cols { display: flex; gap: 8px; margin-bottom: 10px; }
.sk-col { flex: 1; height: 46px; }
.sk-foot { height: 20px; background: var(--ink); opacity: 0.15; }

/* loading state */
.stage-loading { margin: auto; text-align: center; animation: fadeUp 0.3s ease; }
.stage-loading p { font-size: 14.5px; font-weight: 600; color: var(--ink); margin-top: 22px; }
.pulse-ring {
  width: 84px; height: 84px; margin: 0 auto;
  border-radius: 50%;
  border: 3px solid rgba(13,163,200,0.25);
  display: flex; align-items: center; justify-content: center;
  animation: ringPulse 1.6s ease-in-out infinite;
}
.pulse-core {
  width: 46px; height: 46px; border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), var(--amber));
  animation: corePulse 1.6s ease-in-out infinite;
}
@keyframes ringPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); border-color: rgba(13,163,200,0.55); } }
@keyframes corePulse { 0%,100% { transform: scale(1); } 50% { transform: scale(0.82); } }

/* preview view */
.view { position: absolute; inset: 0; display: flex; }
.view-preview { padding: 24px; justify-content: center; overflow: auto; }
.iframe-shell {
  background: var(--white);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  height: 100%;
  border: 1px solid var(--line);
  flex: none;
}
.iframe-shell.desktop { width: min(100%, 900px); }
.iframe-shell.mobile { width: 383px; border-radius: 26px; border: 6px solid var(--ink); }
.iframe-shell iframe { width: 100%; height: 100%; border: 0; display: block; background: var(--white); }

/* code view */
.view-code { background: #232526; border-radius: 0 0 var(--radius) var(--radius); }
.view-code pre {
  margin: 0; padding: 22px 24px;
  overflow: auto; width: 100%;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.65;
  color: #d7e3ea;
  tab-size: 2;
}

/* ---------- History drawer ---------- */
.drawer-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 37, 54, 0.45);
  backdrop-filter: blur(2px);
  animation: fadeIn 0.2s ease;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 70;
  width: min(400px, 92vw);
  background: var(--white);
  box-shadow: -18px 0 50px rgba(0, 37, 54, 0.25);
  transform: translateX(105%);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--ink);
  color: var(--white);
}
.drawer-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.drawer-head .btn-ghost { border-color: rgba(255,255,255,0.25); }
.history-list { flex: 1; overflow-y: auto; padding: 16px; }
.history-empty { color: var(--ink-soft); font-size: 13.5px; text-align: center; padding: 40px 12px; line-height: 1.6; }
.history-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
  background: var(--white);
}
.history-item:hover { border-color: var(--cyan); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.history-item.active { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(13,163,200,0.15); }
.history-item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.history-id { font-family: var(--font-mono); font-size: 12px; color: var(--cyan-dark); font-weight: 500; }
.history-date { font-size: 12px; color: var(--ink-soft); }
.history-notes {
  margin: 8px 0 10px; font-size: 13px; color: var(--ink); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.history-actions { display: flex; gap: 8px; }
.history-actions .btn-tiny.danger { background: #fdeeee; color: var(--danger); }
.history-actions .btn-tiny.danger:hover { background: #f8dcdc; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--ink);
  color: var(--white);
  font-size: 13.5px;
  font-weight: 600;
  padding: 12px 22px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  z-index: 90;
  animation: toastIn 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  border-left: 4px solid var(--amber);
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .input-panel { position: static; }
  .output-panel { min-height: 78vh; }
  .brand-text p { display: none; }
}
@media (max-width: 560px) {
  .topbar { padding: 14px 16px; }
  #history-toggle span:not(.pill) { display: none; }
  .view-preview { padding: 12px; }
  .iframe-shell.mobile { width: 100%; border-width: 4px; }
  .output-toolbar { padding: 12px; }
}
