:root {
  --bg: #f5f6f4; --panel: #ffffff; --ink: #1d2320; --muted: #66706b; --line: #e2e5e1;
  --green: #1a7f37; --green-h: #22973f; --green-d: #14662c; --amber: #a15c00; --amber-bg: #fff6e6; --red: #b42318;
  --stage: #2b2f2d; --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-size: 15px; line-height: 1.5; }
a { color: var(--green); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.logo { font-weight: 700; font-size: 19px; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.logo-mark { color: var(--green); }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 13px; max-width: 620px; }
.nav { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; font-size: 14px; }
.nav a { color: var(--ink); text-decoration: none; white-space: nowrap; }
.nav a:hover { color: var(--green); }
.lang-wrap { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 2px 4px 2px 10px; }
.lang { border: 0; background: transparent; padding: 4px 6px; cursor: pointer; font: inherit; width: auto; }
.lang:focus { outline: none; }
.lang-wrap:focus-within { border-color: var(--green); }
html:lang(ja) { font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, system-ui, sans-serif; }
html:lang(hi) { font-family: "Nirmala UI", "Noto Sans Devanagari", "Mangal", system-ui, sans-serif; }
html:lang(ar) { font-family: "Segoe UI", "Noto Sans Arabic", Tahoma, system-ui, sans-serif; }

/* layout */
.app { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 16px; padding: 16px 20px; max-width: 1500px; margin: 0 auto; }
.workspace { display: flex; flex-direction: column; min-width: 0; }
.stage-wrap { position: relative; height: calc(100vh - 260px); height: calc(100dvh - 260px); min-height: 460px; background: var(--stage); border-radius: var(--radius); overflow: hidden; touch-action: none; }
.stage-wrap.drag { outline: 3px dashed var(--green); outline-offset: -8px; }
#stage { position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: block; width: 100%; height: 100%; cursor: crosshair; }
.empty { position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: #dfe5e1; text-align: center; padding: 24px; }
.empty .muted { color: #aab4ae; }
.empty-icon { color: #8fa197; }
.empty-title { font-size: 20px; font-weight: 600; margin: 0; }
.busy { position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: flex; align-items: center; justify-content: center; gap: 12px; background: rgba(20, 24, 22, 0.55); color: #fff; font-weight: 600; }
.spinner { width: 26px; height: 26px; border: 3px solid rgba(255,255,255,0.35); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.status { min-height: 22px; margin: 8px 2px 0; font-size: 14px; }
.status.ok { color: var(--green); } .status.err { color: var(--red); }
.badge { margin: 2px; color: var(--muted); font-size: 13px; }

/* panel */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 16px 16px; max-height: calc(100vh - 190px); overflow-y: auto; position: sticky; top: 12px; }
.step { padding: 14px 0; border-bottom: 1px solid var(--line); }
.step:last-of-type { border-bottom: 0; }
.step h2 { font-size: 15px; margin: 0 0 10px; }
.field { display: block; margin: 10px 0; }
.label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
select, input[type=number] { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); width: 100%; }
input[type=range] { width: 100%; accent-color: var(--green); }
input[type=checkbox], input[type=radio] { accent-color: var(--green); }
.full { width: 100%; }
.row { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.row.wrap { flex-wrap: wrap; }
.num { width: 80px !important; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.radio, .check { display: flex; gap: 8px; align-items: flex-start; margin: 6px 0; cursor: pointer; font-size: 14px; }
.subbox { background: #f7f9f7; border: 1px solid var(--line); border-radius: 8px; padding: 4px 12px 10px; margin-top: 8px; }
progress { width: 100%; height: 8px; accent-color: var(--green); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: 14px; border-radius: 8px; padding: 8px 14px; cursor: pointer; border: 1px solid transparent; text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--green); color: #fff; font-weight: 600; padding: 10px 22px; }
.btn-primary:hover { background: var(--green-h); }
.btn-secondary { background: #fff; color: var(--green-d); border-color: var(--green); font-weight: 600; }
.btn-secondary:hover:not(:disabled) { background: #eef7f0; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); padding: 6px 10px; font-size: 13px; }
.btn-ghost:hover:not(:disabled) { border-color: var(--green); }
.btn-cta { background: var(--green); color: #fff; font-weight: 700; font-size: 16px; padding: 13px 16px; margin-top: 10px; box-shadow: 0 2px 0 var(--green-d); }
.btn-cta:hover { background: var(--green-h); }
.btn-cta:active { background: var(--green-d); transform: translateY(1px); box-shadow: none; }

.swatches { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#swatches { display: contents; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 2px solid #d0d5d1; cursor: pointer; padding: 0; }
.swatch.on { outline: 3px solid var(--green); outline-offset: 2px; }
#colorPick { width: 36px; height: 32px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: #fff; cursor: pointer; }

.seg { display: flex; flex-direction: column; gap: 4px; }
.seg label { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }

.spec .facts { margin: 10px 0 6px; padding-inline-start: 18px; font-size: 13px; }
.spec .facts li { margin: 2px 0; }
.warn { background: var(--amber-bg); border: 1px solid #f3d9a8; color: #5c3b00; border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 8px 0; }
.links a { white-space: nowrap; }
.note { font-size: 13px; margin: 6px 0; }
.note.ok { color: var(--green); } .note.err { color: var(--red); } .note.warn-text { color: var(--amber); }
.tips summary { cursor: pointer; font-size: 14px; color: var(--green-d); }
.tips ul { padding-inline-start: 18px; font-size: 13px; margin: 6px 0 0; }
.preview-box { display: flex; flex-direction: column; align-items: center; gap: 6px; background: repeating-conic-gradient(#eee 0 25%, #fafafa 0 50%) 0 0 / 16px 16px; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.preview-box .label { align-self: flex-start; }
#preview { max-width: 100%; box-shadow: 0 1px 4px rgba(0,0,0,0.25); background: #fff; }

.foot { text-align: center; padding: 24px 20px 40px; }
.foot nav a { color: var(--ink); }

/* content pages */
.page { max-width: 860px; margin: 0 auto; padding: 24px 20px 40px; }
.page h1 { font-size: 28px; line-height: 1.25; margin: 8px 0 12px; letter-spacing: -0.01em; }
.page h2 { font-size: 19px; margin: 28px 0 8px; }
.spec-table { border-collapse: collapse; width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.spec-table th, .spec-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 14px; }
.spec-table th { width: 34%; color: var(--muted); font-weight: 600; background: #fafbfa; }
.cta-row { margin: 22px 0; }
.size-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; padding: 0; list-style: none; }
.size-list a { display: block; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; text-decoration: none; color: var(--ink); }
.size-list a:hover { border-color: var(--green); }
.size-list b { display: block; }
.size-list span { color: var(--muted); font-size: 13px; }
.diagram { display: block; margin: 16px auto; width: 100%; max-width: 380px; }

/* ---------- ads ----------
   Reserved heights stop the page from jumping when an ad loads (CLS).
   Unfilled ads collapse (.ad--empty). Placeholders only show with ?ads=preview. */
.ad { display: block; margin: 28px auto 36px; max-width: 100%; text-align: center; overflow: hidden; }
.ad-label { display: block; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: #8a938e; margin-bottom: 4px; }
.ad--horiz { min-height: 124px; }
.ad--rect { min-height: 284px; margin-top: 20px; }
.ad--rail { min-height: 624px; margin: 0; position: sticky; top: 12px; }
.ad--empty { display: none !important; }
.ad-direct { display: inline-block; line-height: 0; }
.ad-direct img { max-width: 100%; height: auto; border-radius: 4px; }
.page-rail { display: none; }
@media (min-width: 1200px) {
  .has-rail .page-wrap { display: grid; grid-template-columns: minmax(0, 860px) 300px; gap: 32px; justify-content: center; padding: 0 20px; }
  .has-rail .page-wrap .page { margin: 0; padding-left: 0; padding-right: 0; }
  .has-rail .page-rail { display: block; padding-top: 32px; }
}
.ad--preview { display: none; }
.ads-preview .ad--preview { display: block; }
.ad-ph { display: flex; align-items: center; justify-content: center; background: #eceeeb; border: 1px dashed #c3c9c4; color: #8a938e; font-size: 12px; border-radius: 6px; }
.ad--horiz .ad-ph { height: 100px; } .ad--rect .ad-ph { height: 260px; } .ad--rail .ad-ph { height: 600px; }
@media (max-width: 960px) { .ad--desktop { display: none !important; } }
.rail { display: none; }
/* the third column only exists when there is something to show in it */
@media (min-width: 1400px) {
  .has-rail .app { grid-template-columns: minmax(0, 1fr) 390px 300px; max-width: 1780px; }
  .has-rail .rail { display: block; }
}

/* ---------- content section (SEO + context for ads) ---------- */
.content { max-width: 1100px; margin: 24px auto 0; padding: 8px 20px 24px; }
.content h2 { font-size: 20px; margin: 28px 0 10px; }
.content-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 40px; }
.steps, .checks { padding-inline-start: 20px; margin: 0; }
.steps li, .checks li { margin: 6px 0; }
.checks { list-style: none; padding-inline-start: 0; }
.checks li::before { content: "✓"; color: var(--green); font-weight: 700; margin-inline-end: 8px; }

/* ---------- notices & result dialog ---------- */
.notice { background: var(--amber-bg); border-bottom: 1px solid #f3d9a8; color: #5c3b00; padding: 10px 20px; font-size: 14px; text-align: center; }
.modal { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: rgba(15, 18, 16, 0.6); padding: 16px; }
.modal-box { background: #fff; border-radius: 12px; padding: 18px; max-width: 420px; width: 100%; max-height: 92vh; overflow: auto; text-align: center; }
.modal-box h3 { margin: 0 0 12px; }
.modal-box img { max-width: 100%; max-height: 55vh; box-shadow: 0 1px 6px rgba(0,0,0,0.25); -webkit-touch-callout: default; }
.modal-btns { justify-content: center; margin-top: 12px; }

/* always-visible action bar */
body { padding-bottom: 84px; }
.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px calc(10px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.08); }
.ab-info { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.ab-info b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ab-info span { font-size: 13px; color: var(--muted); text-align: start; }
.ab-btns { display: flex; gap: 10px; flex-shrink: 0; }
.actionbar .btn { padding: 12px 20px; font-size: 15px; }
.actionbar .btn-cta { margin: 0; font-size: 16px; padding: 12px 26px; }
.btn-cta:disabled { background: #9aa5a0; box-shadow: none; }

/* responsive */
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; padding: 10px; }
  .stage-wrap { height: 60vh; height: 60dvh; min-height: 340px; }
  body { padding-bottom: 76px; }
  .actionbar { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .ab-info { display: none; }
  .ab-btns { flex: 1; }
  .actionbar .btn, .actionbar .btn-cta { flex: 1; padding: 12px 6px; font-size: 14px; line-height: 1.25; }
  .actionbar .btn-secondary { flex: 0 0 36%; }
  .ab-paper { display: none; }
  .panel { position: static; max-height: none; }
  .tagline { display: none; }
  .content-grid { grid-template-columns: 1fr; }
  .content { padding: 4px 14px 16px; }
  .ad-top, .ad-bottom { width: calc(100% - 20px); }
}
