:root {
  color-scheme: light;
  --ink: #3a2915;
  --muted: #7b6241;
  --paper: #fffdf4;
  --line: #f0c77a;
  --orange: #f28c28;
  --orange-dark: #bd6419;
  --orange-soft: #ffe8ad;
  --page-bg: #fff7dc;
  --grid-line: #f4dfad;
  --button-bg: #fffaf0;
  --shadow: 0 18px 48px rgba(128, 82, 22, .14);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--page-bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Yu Gothic UI", "Hiragino Sans", "Meiryo", sans-serif;
  background:
    linear-gradient(rgba(244, 223, 173, .72) 1px, transparent 1px),
    linear-gradient(90deg, rgba(244, 223, 173, .72) 1px, transparent 1px),
    var(--page-bg);
  background-size: 24px 24px;
}
button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(242, 140, 40, .34); outline-offset: 2px; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

.app-shell { width: min(1540px, 100%); margin: 0 auto; padding: 26px 30px 42px; }
.app-header { display: flex; align-items: end; justify-content: space-between; gap: 32px; padding: 2px 4px 20px; }
.eyebrow, .step-label { margin: 0 0 5px; color: var(--orange); font-size: 11px; font-weight: 900; letter-spacing: .15em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(25px, 3vw, 39px); line-height: 1; letter-spacing: -.05em; }
h1 span { color: var(--orange); font-weight: 800; }
.header-copy { margin-bottom: 2px; color: var(--muted); font-size: 14px; }


.workspace { display: grid; grid-template-columns: minmax(520px, 2.1fr) minmax(300px, .9fr); gap: 16px; align-items: stretch; }
.card { min-width: 0; border: 1px solid var(--line); border-radius: 22px; background: rgba(255,253,244,.95); box-shadow: var(--shadow); }
.control-panel { display: flex; min-height: 540px; flex-direction: column; overflow: hidden; }
.control-panel-content { padding: 22px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-heading h2 { margin: 0; font-size: 18px; letter-spacing: -.03em; }
.step-label.mint { color: #397c70; }
.step-label.coral { color: #da5c55; }
.step-label.amber { color: #ab7411; }
.round-button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 50%; background: white; cursor: pointer; font-size: 21px; line-height: 1; }
.round-button:hover { border-color: var(--orange); color: var(--orange); }

.desktop-tabs, .mobile-tabs { display: grid; gap: 0; }
.desktop-tabs { grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); background: #fffaf0; }
.mobile-tabs { display: none; }
.switch-tab { min-height: 48px; padding: 10px 12px; border: 0; border-bottom: 3px solid transparent; color: var(--muted); background: transparent; cursor: pointer; font-size: 13px; font-weight: 900; }
.switch-tab:hover { color: var(--orange-dark); background: #fff3cf; }
.switch-tab[aria-selected="true"] { border-bottom-color: var(--orange); color: var(--orange-dark); background: var(--orange-soft); }
.model-select-wrap { display: grid; gap: 8px; margin-top: 20px; color: var(--muted); font-size: 12px; font-weight: 900; }
.model-select-wrap select { border-color: #e5ad55; background: var(--button-bg); color: var(--ink); font-weight: 800; }
.model-select-wrap optgroup { color: var(--orange-dark); font-weight: 900; }
.model-select-wrap option { color: var(--ink); font-weight: 700; }
.model-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 20px 0 16px; }
.model-button { position: relative; min-height: 94px; padding: 10px 7px 8px; border: 1px solid var(--line); border-radius: 15px; background: #faf8f4; cursor: pointer; transition: .18s ease; }
.model-button:hover { transform: translateY(-2px); border-color: #ccbbaa; }
.model-button.active { border: 2px solid var(--orange); background: var(--orange-soft); box-shadow: 0 7px 20px rgba(233,117,66,.13); }
.model-button:disabled { cursor: not-allowed; opacity: .62; }
.model-button img { display: block; width: 48px; height: 48px; margin: 0 auto 4px; object-fit: contain; }
.model-button span { display: block; overflow: hidden; font-size: 11px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.model-button.active::after { content: "✓"; position: absolute; top: 6px; right: 6px; display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; color: white; background: var(--orange); font-size: 11px; }
.text-button { width: 100%; padding: 9px; border: 0; border-radius: 10px; color: #6e625a; background: #f1ede6; cursor: pointer; font-size: 12px; font-weight: 800; }
.text-button:hover { background: #e9e3db; }
.micro-copy { margin: 11px 0 0; color: #8b847d; font-size: 11px; line-height: 1.6; }

.viewer-card { position: relative; display: flex; flex-direction: column; height: clamp(540px, calc(100vh - 205px), 670px); min-height: 540px; overflow: hidden; background: var(--viewer-bg, #ffffff); }
.status-chip { max-width: 48%; padding: 7px 11px; overflow: hidden; border: 1px solid rgba(50,85,78,.13); border-radius: 999px; color: #557169; background: rgba(255,255,255,.74); font-size: 11px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; backdrop-filter: blur(6px); }
.status-chip.error { color: #a63f39; background: #fff0ee; }
.viewer { flex: 1; min-height: 0; }
.viewer canvas { display: block; width: 100% !important; height: 100% !important; cursor: grab; }
.viewer canvas:active { cursor: grabbing; }
.viewer-toolbar { position: absolute; left: 50%; bottom: 54px; z-index: 5; display: flex; align-items: center; gap: 7px; max-width: calc(100% - 26px); padding: 8px; border: 1px solid rgba(35,64,59,.12); border-radius: 16px; background: rgba(255,255,255,.88); box-shadow: 0 10px 25px rgba(51,68,61,.14); transform: translateX(-50%); backdrop-filter: blur(12px); }
.icon-button { display: grid; place-items: center; width: 39px; height: 39px; padding: 7px; border: 1px solid transparent; border-radius: 10px; background: transparent; cursor: pointer; }
.icon-button:hover, .icon-button[aria-pressed="true"], .icon-button[aria-expanded="true"] { border-color: #e5ad55; background: #ffe8ad; }
.icon-button img { width: 100%; height: 100%; object-fit: contain; }
.toolbar-divider { width: 1px; height: 27px; margin: 0 2px; background: #d9dedb; }
.background-wrap { position: relative; }
.background-button { padding: 8px; }
.background-swatch { display: block; width: 21px; height: 21px; border: 2px solid #b9b9b9; border-radius: 6px; background: #ffffff; box-shadow: inset 0 0 0 1px rgba(255,255,255,.75); }
.background-panel { position: absolute; left: -92px; bottom: 52px; width: 238px; padding: 15px; border: 1px solid var(--line); border-radius: 15px; background: white; box-shadow: 0 14px 35px rgba(45,39,32,.19); }
.background-panel p { margin: 0 0 12px; font-size: 13px; }
.background-panel p span { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; font-weight: 400; }
.background-panel label { display: grid; grid-template-columns: 1fr 56px; align-items: center; gap: 8px; color: #5f5853; font-size: 12px; font-weight: 800; }
.background-panel input[type="color"] { width: 56px; height: 31px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.background-presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-top: 10px; }
.background-presets button { min-height: 30px; padding: 4px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: #fffaf0; cursor: pointer; font-size: 10px; font-weight: 800; }
.background-presets button:hover { background: var(--orange-soft); }
.palette-wrap { position: relative; }
.palette-panel { position: absolute; right: -116px; bottom: 52px; width: min(330px, calc(100vw - 28px)); padding: 15px; border: 1px solid var(--line); border-radius: 15px; background: white; box-shadow: 0 14px 35px rgba(45,39,32,.19); }
.palette-panel[hidden] { display: none !important; }
.palette-panel p { margin: 0 0 12px; font-size: 13px; }
.palette-panel p span { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; font-weight: 400; }
.palette-panel label.slot-color-row { display: grid; grid-template-columns: 12px 1fr 56px; align-items: center; gap: 8px; margin-top: 10px; color: #5f5853; font-size: 12px; font-weight: 800; }
.palette-panel input[type="color"] { width: 56px; height: 31px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.mask-slot-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.mask-slot-tabs button { min-height: 31px; border: 1px solid var(--line); border-radius: 8px; color: #665e58; background: #fffaf3; cursor: pointer; font-size: 10px; font-weight: 900; }
.mask-slot-tabs button.active { color: #fff; border-color: var(--orange-dark); background: var(--orange); }
.slot-pattern-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 9px; }
.slot-pattern-actions .button { min-height: 33px; padding: 5px; font-size: 11px; }
.file-button { position: relative; overflow: hidden; display: inline-grid; place-items: center; cursor: pointer; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.palette-hint { margin: 10px 0 6px !important; color: var(--muted); font-size: 10px !important; line-height: 1.45; }
.mask-pattern-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; max-height: 158px; overflow: auto; padding: 2px; }
.mask-pattern-choice { display: grid; gap: 3px; min-width: 0; padding: 4px; border: 2px solid transparent; border-radius: 11px; color: #665e58; background: #fff8ed; cursor: pointer; font-size: 9px; font-weight: 800; }
.mask-pattern-choice img { width: 100%; aspect-ratio: 1; border-radius: 7px; object-fit: cover; }
.mask-pattern-choice span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mask-pattern-choice.active { border-color: #e9ad36; background: #fff0c7; }
.mask-button { height: 37px; padding: 0 10px; border: 1px solid #d8d7d4; border-radius: 10px; background: #fafafa; cursor: pointer; font-size: 11px; font-weight: 900; white-space: nowrap; }
.mask-button.blue[aria-pressed="true"] { border-color: #2678e0; color: white; background: #2678e0; }
.mask-button.black[aria-pressed="true"] { border-color: #202020; color: white; background: #202020; }
.mask-button.magenta[aria-pressed="true"] { border-color: #c84f87; color: white; background: #c84f87; }
.mask-button.red[aria-pressed="true"] { border-color: #d94343; color: white; background: #d94343; }
.viewer-note { position: absolute; right: 18px; bottom: 14px; left: 18px; margin: 0; color: #65756f; font-size: 11px; text-align: center; }

.upload-zone { display: grid; place-items: center; min-height: 162px; margin-top: 19px; padding: 18px; border: 2px dashed #e5ad55; border-radius: 17px; background: #fffaf0; cursor: pointer; transition: .18s ease; text-align: center; }
.upload-zone:hover { border-color: var(--orange); background: var(--orange-soft); }
.upload-zone input { position: absolute; left: 0; width: 1px !important; min-height: 1px; height: 1px; padding: 0; overflow: hidden; opacity: 0; }
.upload-zone strong { margin-top: 7px; font-size: 14px; }
.upload-zone small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.upload-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; color: white; background: var(--orange); font-size: 25px; }
.button { min-height: 40px; padding: 9px 15px; border: 1px solid transparent; border-radius: 11px; cursor: pointer; font-weight: 900; }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button.primary { color: white; background: var(--orange); }
.button.primary:hover { background: var(--orange-dark); }
.button.secondary { border-color: var(--line); background: white; }
.button.secondary:hover { background: #f6f2ec; }
.button.wide { width: 100%; margin-top: 10px; font-size: 12px; }
.material-box { margin-top: 24px; padding-top: 19px; border-top: 1px solid var(--line); }
.material-box label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 900; }
select, input[type="text"], input[type="number"], input[type="file"] { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid #d9d2ca; border-radius: 10px; background: white; }

.app-dialog { width: min(1120px, calc(100% - 28px)); max-height: calc(100vh - 32px); padding: 0; overflow: auto; border: 0; border-radius: 22px; background: var(--paper); box-shadow: 0 25px 80px rgba(31,27,22,.28); }
.app-dialog::backdrop { background: rgba(38,34,31,.53); backdrop-filter: blur(3px); }
.dialog-shell { padding: 26px; }
.dialog-heading { display: flex; justify-content: space-between; gap: 20px; }
.dialog-heading h2 { margin: 0; font-size: 23px; }
.dialog-close { width: 38px; height: 38px; border: 0; border-radius: 50%; background: #eee9e3; cursor: pointer; font-size: 22px; }
.dialog-lead { margin: 11px 0 20px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.correction-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 14px; }
.canvas-card { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 15px; background: #f9f7f3; }
.canvas-label { display: flex; justify-content: space-between; margin-bottom: 9px; color: var(--muted); font-size: 11px; }
.canvas-label b { color: var(--ink); font-size: 13px; }
.canvas-card canvas { display: block; width: 100%; height: auto; max-height: 52vh; border-radius: 10px; background: #eee; touch-action: none; }
.corner-legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 8px; color: var(--muted); font-size: 10px; }
.size-row { display: grid; grid-template-columns: 1fr 1fr auto auto; align-items: end; gap: 10px; margin-top: 15px; }
.size-row label, .model-form-grid label { color: #5d5752; font-size: 12px; font-weight: 800; }
.size-row label > span, .input-unit { display: flex; align-items: center; gap: 7px; margin-top: 5px; }
.size-row input { width: 100%; }
.form-message { min-height: 18px; margin: 10px 0 0; color: #317063; font-size: 12px; }
.form-message.error { color: #b23e36; }

.model-dialog { width: min(780px, calc(100% - 28px)); }
.model-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.model-form-grid label > input, .model-form-grid label > select { margin-top: 6px; }
.model-form-grid small { color: var(--muted); font-weight: 400; }
.model-form-grid .check-row { display: flex; align-items: center; gap: 9px; min-height: 42px; }
.check-row input { width: 17px; height: 17px; }
.mask-guide { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 20px; padding: 13px; border-radius: 12px; background: #f5f2ec; color: #615b55; font-size: 11px; }
.mask-guide span { display: flex; align-items: center; gap: 5px; }
.mask-dot { display: inline-block; width: 11px; height: 11px; border: 1px solid rgba(0,0,0,.14); border-radius: 50%; }
.mask-dot.red { background: #e52323; }.mask-dot.blue { background: #2678e0; }.mask-dot.black { background: #181818; }.mask-dot.magenta { background: #e400a8; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }

.account-card { position: fixed; right: 18px; bottom: 16px; z-index: 30; width: min(330px, calc(100vw - 36px)); padding: 15px 16px 14px; border: 1px solid rgba(216, 196, 180, .95); border-radius: 17px; color: #554b44; background: rgba(255, 250, 244, .96); box-shadow: 0 13px 34px rgba(52, 42, 33, .18); backdrop-filter: blur(10px); }
.account-card-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.account-badge { color: #c45e32; font-size: 10px; font-weight: 900; letter-spacing: .14em; }
.usage-label { color: #796c62; font-size: 11px; font-weight: 800; }
.account-copy { margin: 8px 0 11px; color: #61574f; font-size: 11px; line-height: 1.7; }
.account-login-button, .google-login-button { width: 100%; min-height: 40px; border: 0; border-radius: 10px; color: white; background: #4385e1; cursor: pointer; font-weight: 900; }
.account-login-button:hover, .google-login-button:hover { background: #3473cb; }
.account-login-button.logged-in { color: #37675d; background: #e5f2ed; }
.member-area { margin-top: 12px; padding-top: 11px; border-top: 1px solid #eaded3; }
.member-greeting { margin: 0 0 7px; color: #3d6f64; font-size: 12px; font-weight: 900; }
.member-area .button.wide { margin-top: 0; }
.member-note { margin: 6px 0 10px; color: #8a7a70; font-size: 10px; }
.fanbox-plans { display: grid; gap: 4px; color: #6b5a51; font-size: 10px; line-height: 1.45; }
.fanbox-plans b { color: #ad5a36; font-size: 11px; }
.account-message { min-height: 15px; margin: 8px 0 0; color: #ad5a36; font-size: 10px; line-height: 1.5; }
.account-message.success { color: #367467; }
.auth-dialog { width: min(430px, calc(100% - 28px)); }
.google-login-button { margin-top: 4px; }
.auth-dialog .dialog-actions { margin-top: 14px; }
.app-icon-nav { position: fixed; z-index: 28; right: 18px; top: 50%; display: grid; gap: 8px; transform: translateY(-50%); }
.app-nav-button { display: grid; place-items: center; gap: 2px; width: 52px; min-height: 52px; padding: 5px; border: 1px solid rgba(216, 196, 180, .95); border-radius: 14px; color: #735d51; background: rgba(255,250,244,.96); box-shadow: 0 6px 15px rgba(52,42,33,.11); cursor: pointer; text-decoration: none; font-size: 9px; font-weight: 800; }
.app-nav-button img { width: 27px; height: 27px; object-fit: contain; }
.app-nav-button.active, .app-nav-button:hover { border-color: #e3a43c; background: #fff0c3; }

@media (max-width: 1100px) {
  .app-shell { padding: 20px; }
  .workspace { grid-template-columns: minmax(430px, 1.65fr) minmax(270px, .9fr); }
  .upload-zone { min-height: 135px; margin-top: 0; }
  .material-box { margin-top: 20px; }
}

@media (max-width: 760px) {
  .app-shell { padding: 14px 12px 30px; }
  .app-header { align-items: start; padding-bottom: 15px; }
  .header-copy { display: none; }
  .workspace { display: flex; flex-direction: column; }
  .mobile-tabs { display: grid; grid-template-columns: repeat(3, 1fr); order: 1; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: #fffdf4; }
  .mobile-tabs .switch-tab { min-height: 44px; padding: 7px 4px; font-size: 11px; }
  .control-panel { order: 2; min-height: 0; border-radius: 18px; }
  .viewer-card { order: 3; height: auto; min-height: 570px; }
  .control-panel-content { padding: 18px; }
  .desktop-tabs { display: none; }
  .workspace[data-mobile-tab="preview"] .control-panel { display: none; }
  .workspace:not([data-mobile-tab="preview"]) .viewer-card { display: none; }
  .control-panel .upload-zone { margin-top: 18px; }
  .material-box { padding-top: 18px; border-top: 1px solid var(--line); }
  .viewer-toolbar { gap: 3px; padding: 6px; }
  .icon-button { width: 35px; height: 35px; padding: 6px; }
  .mask-button { padding: 0 6px; font-size: 9px; }
  .palette-panel { right: -90px; width: min(330px, calc(100vw - 20px)); }
  .background-panel { left: -110px; width: 230px; }
  .correction-grid, .model-form-grid { grid-template-columns: 1fr; }
  .size-row { grid-template-columns: 1fr 1fr; }
  .dialog-shell { padding: 19px; }
  .account-card { position: static; width: auto; margin: 12px 12px 20px; }
  .app-icon-nav { position: sticky; right: auto; top: auto; bottom: 0; grid-template-columns: repeat(4, 1fr); width: 100%; padding: 7px 12px calc(7px + env(safe-area-inset-bottom)); transform: none; background: rgba(255,250,244,.95); box-shadow: 0 -5px 18px rgba(52,42,33,.10); }
  .app-nav-button { width: auto; min-height: 51px; border-radius: 12px; box-shadow: none; }
}

@media (max-width: 430px) {
  h1 { font-size: 24px; }
  .control-panel-content { padding: 18px; }
  .viewer-card { min-height: 520px; }
  .viewer { min-height: 510px; }
  .viewer-toolbar { bottom: 48px; }
  .icon-button:nth-child(3), .icon-button:nth-child(4) { display: none; }
  .size-row { grid-template-columns: 1fr; }
}

html.embed-mode body { min-height: 0; }
html.embed-mode .app-header { display: none; }
html.embed-mode .app-shell { width: 100%; padding: 0; }
html.embed-mode .workspace { gap: 10px; }
html.embed-mode .card { border-radius: 14px; box-shadow: none; }
html.embed-mode .account-card { right: 10px; bottom: 10px; }
