:root {
  --bg: #f6f5fb;
  --panel: #ffffff;
  --text: #1c1b22;
  --muted: #6b6878;
  --line: #e4e1ee;
  --brand: #7c3aed;
  --brand2: #ec4899;
  --brand-soft: #f1eafe;
  --danger: #dc2626;
  --ok: #059669;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 10, 50, .04), 0 6px 24px rgba(20, 10, 50, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121118;
    --panel: #1c1a24;
    --text: #f1eff8;
    --muted: #a19cb3;
    --line: #2f2c3b;
    --brand-soft: #2a2140;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.7 "Noto Sans JP", system-ui, sans-serif;
}
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

.top { background: var(--panel); border-bottom: 1px solid var(--line); }
.top-inner { display: flex; align-items: center; gap: 14px; height: 56px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 900; font-size: 18px; color: var(--text); text-decoration: none; }
.tagline { color: var(--muted); font-size: 13px; }
@media (max-width: 560px) { .tagline { display: none; } }

.layout { display: grid; gap: 20px; padding-top: 20px; padding-bottom: 20px; align-items: start; }
@media (min-width: 960px) {
  .layout { grid-template-columns: 400px minmax(0, 1fr); }
  .form { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; }
}

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.result { display: grid; gap: 16px; min-width: 0; }
h1 { font-size: 20px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 0; }

.field { display: grid; gap: 6px; margin: 0 0 14px; border: 0; padding: 0; min-width: 0; }
.field > span, .field > legend { font-weight: 700; font-size: 13px; padding: 0; }
.field em { font-style: normal; color: var(--brand); font-size: 11px; margin-left: 4px; }
.field small, .size-note { color: var(--muted); font-size: 12px; line-height: 1.5; }
.grid2 { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

input:not([type=radio]):not([type=checkbox]):not([type=file]), select, textarea {
  width: 100%;
  font: inherit;
  font-size: 16px; /* iOSのズーム防止 */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
}
textarea { resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

.seg, .checks { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label, .checks label { position: relative; }
.seg input, .checks input { position: absolute; opacity: 0; inset: 0; }
.seg span, .checks span {
  display: inline-block; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg); cursor: pointer; font-size: 14px; user-select: none;
}
.seg input:checked + span, .checks input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.seg input:focus-visible + span, .checks input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.seg.small span { padding: 5px 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 700; font-size: 14px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); cursor: pointer; text-decoration: none; min-height: 42px;
}
.btn:hover { border-color: var(--brand); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand2)); color: #fff; border: 0; }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; padding: 14px; font-size: 16px; }
.spinner { display: none; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.5); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
.loading .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.row select { width: auto; max-width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.note { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.error { color: var(--danger); font-size: 14px; margin: 10px 0 0; }

.tabs { display: flex; gap: 6px; overflow-x: auto; }
.tab {
  font: inherit; font-weight: 700; padding: 9px 18px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); cursor: pointer; white-space: nowrap;
}
.tab[aria-selected=true] { background: var(--text); color: var(--bg); border-color: var(--text); }

.stage {
  margin-top: 10px; background: repeating-conic-gradient(var(--line) 0 25%, transparent 0 50%) 0 0 / 20px 20px;
  border-radius: 10px; display: grid; place-items: center; padding: 12px; overflow: hidden;
}
#canvas { display: block; max-width: 100%; max-height: 62vh; width: auto; height: auto; border-radius: 6px; box-shadow: 0 4px 20px rgba(0,0,0,.18); }

.counter { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.counter.over { color: var(--danger); font-weight: 700; }
.progress { height: 6px; background: var(--line); border-radius: 3px; margin-top: 12px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), var(--brand2)); }

details > summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; }
details > summary::after { content: "＋"; color: var(--muted); }
details[open] > summary { margin-bottom: 14px; }
details[open] > summary::after { content: "－"; }
summary::-webkit-details-marker { display: none; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; padding: 0; position: relative; }
.swatch[aria-pressed=true] { border-color: var(--text); box-shadow: 0 0 0 2px var(--panel) inset; }
.swatch .dot { position: absolute; right: 3px; bottom: 3px; width: 11px; height: 11px; border-radius: 50%; border: 1.5px solid #fff; }

.scene { display: grid; grid-template-columns: 28px 1fr 1fr 34px; gap: 8px; align-items: start; margin-bottom: 10px; }
.scene b { padding-top: 9px; color: var(--muted); font-size: 13px; text-align: center; }
.scene .del { min-height: 40px; padding: 0; }
@media (max-width: 560px) {
  .scene { grid-template-columns: 24px 1fr 34px; }
  .scene textarea:nth-of-type(2) { grid-column: 2; }
  .scene .del { grid-row: 1; grid-column: 3; }
}

.foot { color: var(--muted); font-size: 12px; padding-bottom: 32px; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 10;
}

/* AIの選択・APIキー */
.ai-options { display: grid; gap: 6px; }
.ai-opt { position: relative; display: block; cursor: pointer; }
.ai-opt input { position: absolute; opacity: 0; inset: 0; }
.ai-opt > span { display: grid; gap: 1px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.ai-opt b { font-size: 14px; }
.ai-opt small { color: var(--muted); font-size: 12px; line-height: 1.4; }
.ai-opt input:checked + span { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.ai-opt input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.keybox { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin: 0 0 14px; background: var(--bg); }
.keybox input, .keybox select { background: var(--panel) !important; }
.key-row { display: flex; gap: 6px; }
.key-row input { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, monospace; }
.key-row .btn { min-height: 0; padding: 6px 12px; }
.check-line { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; margin-bottom: 8px; cursor: pointer; }
.check-line input { margin-top: 5px; }
.check-line small { display: block; color: var(--muted); font-size: 12px; }
.small-btn { min-height: 0; padding: 5px 10px; font-size: 12px; }
.secure-note { font-size: 12.5px; line-height: 1.6; margin: 12px 0 8px; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--ok) 10%, transparent); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); }
.secure-note a { color: inherit; font-weight: 700; }
.guide { font-size: 13px; }
.guide summary { cursor: pointer; font-weight: 700; color: var(--brand); }
.guide ol, .guide ul { padding-left: 1.3em; margin: 8px 0; }
.guide li { margin: 4px 0; line-height: 1.6; }
.guide a, .security a, .foot a { color: var(--brand); }
code { font-family: ui-monospace, Consolas, monospace; font-size: .92em; background: var(--brand-soft); padding: 1px 5px; border-radius: 5px; word-break: break-all; }
.security h2 { margin-bottom: 8px; }
.security dt { font-weight: 700; margin-top: 12px; }
.security dd { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.security dd strong { color: var(--text); }
.error .btn { margin: 6px 6px 0 0; }
