:root {
  --blue: #1e6bf1;
  --blue-dark: #0b3aa8;
  --orange: #ff8a1e;
  --orange-dark: #f4680a;
  --navy: #0d1b3e;
  --ink: #14213d;
  --muted: #6b7794;
  --bg: #eef2fb;
  --card: #ffffff;
  --line: #e3e8f4;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(20, 40, 90, 0.10);
  --grad: linear-gradient(120deg, var(--blue), var(--orange));
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background:
    radial-gradient(1200px 600px at 10% -10%, #dbe6ff 0%, transparent 55%),
    radial-gradient(1000px 500px at 100% 0%, #ffe6cf 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: #d33; font-size: 13px; margin: 8px 0 0; }

/* buttons */
.btn {
  border: none; cursor: pointer; border-radius: 12px; font-weight: 600;
  padding: 11px 16px; font-size: 14px; transition: .15s ease; font-family: inherit;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 8px 18px rgba(30,107,241,.28); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-outline { background: #fff; color: var(--blue-dark); border: 1.5px solid var(--line); }
.btn-outline:hover { border-color: var(--blue); }
.btn-ghost { background: rgba(255,255,255,.5); color: var(--ink); }
.btn-ghost:hover { background: #fff; }
.btn-block { width: 100%; display: block; }
.big { padding: 15px; font-size: 16px; margin-top: 14px; }

/* login */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  background: var(--card); border-radius: 22px; padding: 38px 30px; width: 100%; max-width: 380px;
  text-align: center; box-shadow: var(--shadow); border: 1px solid var(--line);
}
.login-logo { width: 76px; height: 76px; border-radius: 18px; box-shadow: var(--shadow); }
.login-card h1 { margin: 16px 0 4px; font-size: 22px; }
.pw-wrap { position: relative; margin: 18px 0 12px; }
.pw-eye {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  border: none; background: none; color: var(--blue); font-size: 12px; cursor: pointer; font-weight: 600;
}
input, textarea, select {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--ink); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(30,107,241,.12); }
textarea { resize: vertical; }

/* app */
.app { max-width: 1200px; margin: 0 auto; padding: 16px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(255,255,255,.7); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 16px; padding: 10px 14px; box-shadow: var(--shadow);
  position: sticky; top: 10px; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; }
.brand img { width: 34px; height: 34px; border-radius: 9px; }
.brand b { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip { background: var(--grad); color: #fff; padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 700; }

/* mode select */
.mode-select { text-align: center; padding: 40px 0; }
.mode-select h2 { font-size: 26px; margin-bottom: 24px; }
.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; max-width: 720px; margin: 0 auto; }
.mode-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 30px 24px;
  cursor: pointer; text-align: center; transition: .18s ease; box-shadow: var(--shadow);
}
.mode-card:hover { transform: translateY(-4px); border-color: var(--blue); }
.mode-card.miki { background: linear-gradient(160deg, #fff, #f2f7ff); }
.mode-icon { font-size: 42px; margin-bottom: 8px; }
.mode-card h3 { margin: 6px 0; font-size: 20px; }
.mode-card p { color: var(--muted); font-size: 13.5px; margin: 0; }

/* generator layout */
.generator { display: grid; grid-template-columns: 400px 1fr; gap: 18px; margin-top: 16px; align-items: start; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h2 { font-size: 18px; margin: 0; }
.tag, .results-grid .tag { background: #eef3ff; color: var(--blue-dark); padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.field-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin: 12px 0 6px; }
.row { display: flex; }
.row.gap { gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.field { flex: 1; min-width: 90px; }
.field.grow { flex: 2; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.preset { background: #eef3ff; border: 1px solid var(--line); color: var(--blue-dark); border-radius: 8px; padding: 5px 9px; font-size: 12px; cursor: pointer; }
.preset:hover { border-color: var(--blue); }

/* logo section */
.logo-section { margin-top: 8px; }
.logo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.logo-opt {
  background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 8px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--muted);
}
.logo-opt img { width: 100%; height: 46px; object-fit: contain; }
.logo-opt .none-box { width: 100%; height: 46px; display: grid; place-items: center; font-size: 22px; color: #bbb; }
.logo-opt.selected { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(30,107,241,.12); }
.logo-controls { align-items: end; }

/* saved */
.saved { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 14px; }
.saved h3 { font-size: 15px; margin: 0 0 10px; }
.saved-list { display: flex; flex-direction: column; gap: 8px; max-height: 220px; overflow: auto; }
.saved-item { background: #f7f9ff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12.5px; }
.saved-item p { margin: 0 0 6px; color: var(--ink); display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.saved-actions { display: flex; gap: 6px; }
.saved-actions button { font-size: 11px; padding: 4px 8px; border-radius: 7px; border: none; cursor: pointer; }
.mini-load { background: var(--blue); color: #fff; }
.mini-del { background: #ffe3e3; color: #c22; }

/* results */
.results-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.empty-state { grid-column: 1/-1; text-align: center; color: var(--muted); padding: 60px 0; border: 2px dashed var(--line); border-radius: 14px; }
.result-card { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: #fbfcff; }
.result-card img { width: 100%; display: block; background: #fff; }
.result-actions { display: flex; gap: 6px; padding: 8px; }
.result-actions button { flex: 1; font-size: 12.5px; padding: 8px; border-radius: 9px; border: none; cursor: pointer; font-weight: 600; }
.act-dl { background: var(--grad); color: #fff; }
.act-reply { background: #eef3ff; color: var(--blue-dark); }

/* modals */
.modal { position: fixed; inset: 0; background: rgba(13,27,62,.5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: #fff; border-radius: 18px; padding: 22px; width: 100%; max-width: 460px; box-shadow: var(--shadow); max-height: 90vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { margin: 0; }
.modal-close { border: none; background: #f0f2f8; width: 32px; height: 32px; border-radius: 50%; font-size: 20px; cursor: pointer; color: var(--muted); }
.provider-opts { display: flex; flex-direction: column; gap: 10px; margin: 12px 0 18px; }
.provider-opt { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer; }
.provider-opt input { width: auto; }
.reply-preview { width: 100%; border-radius: 12px; margin-bottom: 12px; border: 1px solid var(--line); }

/* loader + toast */
.loader { position: fixed; inset: 0; background: rgba(255,255,255,.72); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 60; }
.spinner { width: 54px; height: 54px; border: 5px solid #d7e0f7; border-top-color: var(--blue); border-radius: 50%; animation: spin 1s linear infinite; }
.loader p { margin-top: 14px; font-weight: 600; color: var(--blue-dark); }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 12px 20px; border-radius: 12px; font-size: 14px; z-index: 70; box-shadow: var(--shadow); }

@media (max-width: 860px) {
  .generator { grid-template-columns: 1fr; }
  .top-actions .btn { padding: 9px 11px; font-size: 13px; }
  .brand span { display: none; }
}
