/* ---------- Modal (C1–C5) ---------- */
.modal {
  border: 0; padding: 0; margin: auto;
  background: transparent; color: var(--text);
  max-width: min(560px, calc(100vw - 24px));
  width: 100%;
  max-height: calc(100dvh - 24px - var(--safe-top) - var(--safe-bottom));
}
.modal::backdrop { background: rgba(0,0,0,.5); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
.modal[open] { animation: pop .2s var(--ease); }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(6px); } to { opacity: 1; transform: none; } }
.modal-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  max-height: inherit;
  overflow: hidden;
}
.modal:has(.wide) { max-width: min(960px, calc(100vw - 24px)); }

/* ---------- First-run guide ---------- */
.welcome-dialog { max-width: min(470px, calc(100vw - 24px)); }
.welcome-card { border-radius: 26px; }
.welcome-hero { height: 132px; position: relative; overflow: hidden; display: grid; place-items: center; background: linear-gradient(135deg, #fff1eb, #fff9f5); }
.welcome-icon { width: 70px; height: 70px; display: grid; place-items: center; border-radius: 23px; color: #fff; background: linear-gradient(145deg, #ff7a42, #d95436); box-shadow: 0 12px 28px rgba(217,84,54,.3); transform: rotate(-8deg); z-index: 1; }
.welcome-icon span { font-size: 36px; line-height: 1; transform: rotate(8deg); }
.welcome-orbit { position: absolute; border: 1px solid rgba(217,84,54,.2); border-radius: 50%; }
.welcome-orbit-one { width: 190px; height: 190px; transform: rotate(25deg); }
.welcome-orbit-two { width: 280px; height: 90px; transform: rotate(-25deg); }
.welcome-content { padding: 24px 26px 20px; }
.welcome-kicker { color: var(--brand); font-size: 12px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.welcome-content h2 { margin: 5px 0 6px; font-size: 25px; line-height: 1.2; letter-spacing: -.03em; }
.welcome-intro { margin: 0 0 20px; color: var(--text-2); font-size: 14px; line-height: 1.5; }
.welcome-steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 13px; }
.welcome-steps li { display: flex; align-items: flex-start; gap: 11px; }
.welcome-step-icon { flex: 0 0 auto; color: var(--brand); font-weight: 700; font-size: 16px; line-height: 1.35; }
.welcome-steps b, .welcome-steps small { display: block; }
.welcome-steps b { font-size: 14px; }
.welcome-steps small { color: var(--text-2); font-size: 12.5px; line-height: 1.4; }
.welcome-actions { display: grid; gap: 8px; margin-top: 23px; }
.welcome-start { width: 100%; height: 45px; justify-content: space-between; padding-inline: 18px; background: var(--brand); }
.welcome-start span { font-size: 20px; line-height: 1; }
.welcome-skip { border-color: transparent; color: var(--text-2); }
.welcome-note { margin: 14px 0 0; text-align: center; color: var(--text-3); font-size: 11.5px; }
.welcome-note span { margin-right: 3px; }
@media (max-width: 560px) { .welcome-content { padding: 22px 20px 17px; } .welcome-content h2 { font-size: 23px; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 14px 12px 22px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { padding: 18px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal-foot {
  display: flex; align-items: center; gap: 8px; justify-content: flex-end;
  padding: 12px 16px 14px 22px; border-top: 1px solid var(--border);
}
.modal-foot .grow { flex: 1; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field .help { font-size: 12.5px; color: var(--text-3); }
.input-row { display: flex; gap: 6px; align-items: center; }
.input {
  width: 100%; height: 42px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--bg); outline: none;
  font-size: 16px; /* no iOS zoom */
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
.input-row .icon-btn { flex-shrink: 0; width: 42px; height: 42px; border: 1px solid var(--border-strong); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin: 6px 0 -4px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.switch-row .txt b { display: block; font-size: 14px; font-weight: 500; }
.switch-row .txt span { font-size: 12.5px; color: var(--text-3); }
.switch { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); transition: background .2s; }
.switch span::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s var(--ease);
}
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(18px); }
.test-result { font-size: 13px; min-height: 18px; }
.test-result.ok { color: var(--success); }
.test-result.err { color: var(--danger); overflow-wrap: anywhere; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.profile-card { border: 1px solid var(--border); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.profile-head { display: flex; align-items: center; gap: 8px; }
.profile-head h3 { margin: 0; font-size: 16px; }
.profile-status { color: var(--success); font-size: 12px; font-weight: 600; }
.profile-head .btn { margin-left: auto; }
.model-rows { display: flex; flex-direction: column; gap: 8px; }
.model-row { display: flex; align-items: center; gap: 8px; }
.model-row .model-id { min-width: 0; flex: 1; }
.model-switch { display: flex; align-items: center; gap: 5px; white-space: nowrap; font-size: 12px; color: var(--text-2); }
.model-switch input { accent-color: var(--success); }
@media (max-width: 560px) { .model-row { flex-wrap: wrap; } .model-row .model-id { flex-basis: 100%; } .model-row .btn { margin-left: auto; } }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

/* Viewer (HTML preview E5 / pasted text F5) */
.viewer-frame { width: 100%; height: min(70dvh, 720px); border: 0; background: #fff; display: block; }
.viewer-text {
  width: 100%; height: min(60dvh, 600px); border: 0; outline: none; resize: none;
  padding: 16px 22px; background: var(--bg); font: 14px/1.6 var(--mono); display: block;
}
