:root {
  --ink: #171816;
  --muted: #73766f;
  --line: #e5e6e1;
  --soft: #f5f5f1;
  --accent: #263e32;
  --white: #fff;
  --danger: #a23b3b;
  font-family: Inter, "Noto Sans JP", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #fafaf8;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; }
body.auth-required { overflow: hidden; }
button, input { font: inherit; }
button { cursor: pointer; }

.site-header {
  height: 76px; padding: 0 clamp(20px, 5vw, 72px); display: flex; align-items: center;
  justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(250,250,248,.92);
}
.brand { display: flex; gap: 12px; align-items: center; color: inherit; text-decoration: none; font-weight: 650; letter-spacing: -.02em; }
.brand-mark { width: 22px; height: 22px; border: 2px solid var(--ink); box-shadow: inset 0 0 0 4px #fafaf8, inset 0 0 0 6px var(--ink); }
.account-actions { display: flex; gap: 16px; align-items: center; }
.user-greeting { color: var(--muted); font-size: .88rem; }

main { width: min(1280px, calc(100% - 40px)); margin: 0 auto; }
.eyebrow { margin: 0 0 18px; color: #68766d; font-size: .68rem; font-weight: 750; letter-spacing: .18em; }

.studio { display: grid; grid-template-columns: minmax(320px, .82fr) minmax(420px, 1.18fr); align-items: start; margin-top: clamp(28px, 5vw, 64px); background: var(--white); border: 1px solid var(--line); }
.controls { padding: clamp(28px, 4.5vw, 60px); border-right: 1px solid var(--line); }
.section-heading { display: flex; gap: 18px; align-items: flex-start; margin-bottom: 24px; }
.section-heading h2 { margin: -3px 0 4px; font-family: Georgia, "Yu Mincho", serif; font-weight: 400; font-size: 1.55rem; }
.section-heading p { margin: 0; color: var(--muted); font-size: .8rem; }
.step { display: grid; place-items: center; flex: 0 0 auto; width: 30px; height: 30px; border: 1px solid #a7aaa3; border-radius: 50%; font-size: .65rem; }

.canvas-upload-guide { margin: -3px 0 0; color: var(--muted); font-size: .76rem; line-height: 1.7; }
.upload-icon { display: grid; place-items: center; width: 42px; height: 42px; margin-bottom: 5px; border: 1px solid var(--ink); border-radius: 50%; font-size: 1.4rem; font-weight: 300; }
.file-summary { min-height: 76px; padding: 15px 18px; align-items: center; justify-content: space-between; border: 1px solid var(--line); }
.file-summary > div { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.file-summary strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .84rem; }
.file-summary span { color: var(--muted); font-size: .72rem; }
.frame-heading { margin-top: 46px; }
.frame-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.frame-card { position: relative; display: flex; gap: 12px; min-height: 88px; padding: 13px; border: 1px solid var(--line); cursor: pointer; transition: .2s ease; }
.frame-card:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.frame-card input { position: absolute; opacity: 0; }
.frame-mini { position: relative; flex: 0 0 56px; height: 56px; background: #fff; border: 1px solid #d7d8d4; box-shadow: 0 2px 6px rgba(0,0,0,.04); }
.frame-mini::after { content: ""; position: absolute; background: #cbd0cd; left: var(--fx); top: var(--fy); width: var(--fw); height: var(--fh); }
.frame-copy { min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.frame-copy strong { font-size: .78rem; }
.frame-copy span { margin-top: 4px; color: var(--muted); font-size: .67rem; line-height: 1.4; }

.button { border: 0; min-height: 44px; padding: 0 20px; border-radius: 2px; font-weight: 650; font-size: .83rem; }
.button-primary { background: var(--accent); color: white; }
.button-primary:hover { background: #182a21; }
.button-secondary { background: transparent; border: 1px solid #bfc1bc; }
.button:disabled { opacity: .42; cursor: not-allowed; }
.text-button { padding: 3px 0; background: transparent; border: 0; color: #58675e; font-size: .78rem; text-decoration: underline; text-underline-offset: 3px; }
.generate-button { width: 100%; min-height: 56px; margin-top: 24px; display: flex; justify-content: center; align-items: center; gap: 14px; }
.status { min-height: 22px; margin: 12px 0 0; text-align: center; color: var(--muted); font-size: .78rem; }
.status.error, .form-error { color: var(--danger); }

.preview-column { position: sticky; top: 20px; min-width: 0; height: calc(100vh - 40px); padding: clamp(20px, 3vw, 40px); background: var(--soft); display: flex; flex-direction: column; overflow: hidden; }
.canvas-stage { width: min(100%, 48vh); margin: 0 auto; flex: 0 1 auto; }
.preview-label { display: flex; justify-content: space-between; margin-bottom: 12px; color: var(--muted); font-size: .64rem; letter-spacing: .14em; }
.preview-canvas { position: relative; width: 100%; aspect-ratio: 1; background: #fff; box-shadow: 0 22px 55px rgba(38, 43, 39, .11); overflow: hidden; }
.preview-canvas.is-dragging::after { content: "ここに写真をドロップ"; position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; border: 3px solid var(--accent); color: var(--accent); background: rgba(244, 247, 243, .9); font-size: clamp(.75rem, 2vw, 1rem); font-weight: 700; letter-spacing: .08em; pointer-events: none; }
.preview-photo-area { position: absolute; overflow: hidden; background: #eceeeb; }
.preview-photo-area img { width: 100%; height: 100%; display: block; }
.preview-placeholder { width: 100%; height: 100%; display: grid; place-items: center; color: #a3a7a1; font-size: clamp(.6rem, 1.2vw, .75rem); letter-spacing: .22em; background: linear-gradient(135deg, #eef0ed, #e2e5e1); }
.user-preview-layers { position: absolute; inset: 0; overflow: hidden; }
.user-preview-layer { position: absolute; margin: 0; padding: 0; cursor: grab; touch-action: none; user-select: none; -webkit-user-drag: none; }
.user-preview-layer:hover { outline: 1px dashed rgba(38, 62, 50, .65); outline-offset: 3px; }
.user-preview-layer.selected { outline: 2px solid var(--accent); outline-offset: 3px; }
.user-preview-layer.dragging { cursor: grabbing; }
.user-preview-layer:focus-visible { outline: 3px solid #5e806d; outline-offset: 4px; }
.user-preview-layer.text { white-space: pre; }
.user-preview-layer.image { object-position: center; }
.canvas-drop-zone { position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; border: 1px dashed #aeb4ad; background: rgba(253, 253, 251, .94); cursor: pointer; text-align: center; }
.canvas-drop-zone:hover { border-color: var(--accent); background: rgba(244, 247, 243, .96); }
.canvas-drop-zone strong { font-size: .94rem; }
.canvas-drop-zone > span:not(.upload-icon), .canvas-drop-zone small { color: var(--muted); font-size: .76rem; }
.canvas-photo-change { position: absolute; top: 12px; right: 12px; z-index: 5; min-height: 34px; padding: 0 12px; border: 1px solid rgba(38, 62, 50, .35); background: rgba(255, 255, 255, .9); color: var(--accent); font-size: .7rem; font-weight: 700; backdrop-filter: blur(4px); }
.canvas-photo-change:hover { background: #fff; border-color: var(--accent); }
.preview-note { margin: 16px 0 0; color: var(--muted); font-size: .7rem; text-align: center; }

.canvas-design-panel { min-height: 110px; margin-top: 18px; padding: clamp(16px, 2vw, 22px); border: 1px solid #dde1da; background: rgba(255, 255, 255, .9); flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.design-login-hint { padding: 16px; border: 1px dashed #c8cbc5; color: var(--muted); font-size: .76rem; line-height: 1.7; }
.design-editor { display: grid; gap: 12px; }
.design-toolbar { position: sticky; top: -16px; z-index: 3; display: grid; grid-template-columns: 1fr 1fr auto; gap: 7px; padding: 2px 0 8px; background: rgba(255, 255, 255, .97); }
.design-toolbar button { flex: 1; min-height: 38px; border: 1px solid #c9ccc6; background: white; color: var(--accent); font-size: .74rem; font-weight: 700; }
.design-toolbar button:disabled { opacity: .45; cursor: not-allowed; }
.design-toolbar #saveDesign { padding: 0 12px; background: var(--accent); border-color: var(--accent); color: #fff; }
.user-asset-picker { padding: 12px; border: 1px solid #cdd3cc; background: #f8faf7; }
.asset-picker-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-size: .73rem; }
.asset-picker-heading button { padding: 0 3px; border: 0; background: transparent; color: var(--muted); font-size: 1.1rem; }
.user-asset-upload { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.user-asset-upload input { min-width: 0; font-size: .7rem; }
.user-asset-upload .button { min-height: 38px; padding: 0 12px; }
.design-meta { margin: -3px 0 0; color: var(--muted); font-size: .68rem; }
.user-asset-count { display: block; margin-bottom: 5px; }
.user-asset-chip { display: inline-flex; align-items: center; gap: 3px; max-width: 100%; margin: 0 5px 5px 0; padding: 2px 4px 2px 2px; background: #e9eee9; }
.user-asset-chip .asset-choice { max-width: 180px; overflow: hidden; padding: 4px 6px; border: 0; background: transparent; color: var(--accent); text-overflow: ellipsis; white-space: nowrap; font-size: .68rem; }
.user-asset-chip button { padding: 0; border: 0; background: none; color: var(--danger); }
.user-layer-tabs { display: flex; gap: 6px; padding: 1px 0 5px; overflow-x: auto; scrollbar-width: thin; }
.user-layer-tab { flex: 0 0 auto; max-width: 180px; min-height: 34px; padding: 0 10px; overflow: hidden; border: 1px solid #d1d5cf; background: #f8f9f7; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; font-size: .68rem; }
.user-layer-tab.selected { border-color: var(--accent); background: #eaf0eb; color: var(--accent); font-weight: 700; }
.user-layer-inspector { min-width: 0; }
.user-layer-selection-hint { margin: 0; padding: 14px; border: 1px dashed #cfd2cc; color: var(--muted); text-align: center; font-size: .68rem; line-height: 1.6; }
.user-layer-empty { padding: 16px; border: 1px dashed #cfd2cc; color: var(--muted); text-align: center; font-size: .72rem; }
.user-layer-card { padding: 12px; border: 1px solid var(--line); background: #fbfcfa; transition: border-color .15s ease, box-shadow .15s ease; }
.user-layer-card.selected { border-color: #8ba092; box-shadow: inset 3px 0 0 var(--accent); }
.user-layer-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 0; }
.user-layer-card.selected .user-layer-header { margin-bottom: 11px; }
.user-layer-header strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .74rem; }
.user-layer-actions { display: flex; gap: 9px; }
.user-layer-actions button { padding: 0; border: 0; background: none; color: var(--accent); font-size: .68rem; }
.user-layer-actions .remove { color: var(--danger); }
.user-layer-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.user-layer-grid label { min-width: 0; display: grid; gap: 5px; color: #5b5e59; font-size: .65rem; }
.user-layer-grid input, .user-layer-grid select, .user-layer-grid textarea { width: 100%; min-width: 0; height: 36px; padding: 0 8px; border: 1px solid #ced1cb; background: white; font-size: .74rem; }
.user-layer-grid textarea { height: 58px; padding: 7px 8px; resize: vertical; }
.user-layer-grid .wide { grid-column: 1 / -1; }
.user-layer-grid .span-two { grid-column: span 2; }
.user-placement { display: grid; grid-template-columns: minmax(84px, auto) 1fr; gap: 10px; align-items: start; }
.user-placement-label { padding-top: 4px; color: #5b5e59; font-size: .65rem; }
.user-placement-controls { display: flex; align-items: center; gap: 8px; }
.placement-presets { display: grid; grid-template-columns: repeat(3, 32px); gap: 3px; }
.placement-button, .placement-axis-button { position: relative; width: 32px; height: 32px; padding: 0; border: 1px solid #cbd0c9; background: #fff; color: var(--accent); }
.placement-button:hover, .placement-axis-button:hover { border-color: var(--accent); background: #eef3ef; }
.placement-button:focus-visible, .placement-axis-button:focus-visible { outline: 2px solid #779080; outline-offset: 2px; }
.placement-button::before { content: ""; position: absolute; inset: 6px; border: 1px solid #aeb8b0; }
.placement-button::after { content: ""; position: absolute; left: var(--placement-x); top: var(--placement-y); width: 5px; height: 5px; border-radius: 50%; background: var(--accent); transform: translate(-50%, -50%); }
.placement-axes { display: grid; grid-template-columns: repeat(2, 32px); gap: 3px; }
.placement-axis-button { font-size: 1rem; line-height: 1; }
.inspector-section { border-top: 1px solid #e0e3de; }
.inspector-section:last-child { border-bottom: 1px solid #e0e3de; }
.inspector-section summary { padding: 9px 3px; color: var(--accent); cursor: pointer; font-size: .72rem; font-weight: 700; list-style-position: inside; }
.inspector-section .user-layer-grid { padding: 4px 3px 12px; }
.user-layer-toggle { display: flex !important; grid-template-columns: auto 1fr; align-items: center; padding-top: 17px; }
.user-layer-toggle input { width: 15px; height: 15px; }

.history-section { padding: clamp(72px, 10vw, 130px) 0; }
.history-section h2 { margin: 0; font-family: Georgia, "Yu Mincho", serif; font-weight: 400; font-size: clamp(1.8rem, 3vw, 2.8rem); }
.history-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 34px; }
.history-item { min-width: 0; padding: 20px; background: white; border: 1px solid var(--line); }
.history-item strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .82rem; }
.history-meta { margin: 7px 0 18px; color: var(--muted); font-size: .7rem; }
.history-item a { color: var(--accent); font-size: .77rem; font-weight: 650; text-underline-offset: 4px; }
.empty-history { color: var(--muted); font-size: .85rem; }

footer { width: min(1280px, calc(100% - 40px)); margin: 0 auto; padding: 28px 0 38px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; color: var(--muted); font-size: .72rem; }
.auth-dialog { width: min(440px, calc(100% - 32px)); padding: 42px; border: 0; box-shadow: 0 24px 80px rgba(0,0,0,.22); }
.auth-dialog::backdrop { background: rgba(20,22,20,.48); backdrop-filter: blur(3px); }
.auth-dialog h2 { margin: 0; font-family: Georgia, "Yu Mincho", serif; font-size: 2rem; font-weight: 400; }
.dialog-description { margin: 12px 0 26px; color: var(--muted); font-size: .82rem; line-height: 1.6; }
.dialog-close { position: absolute; right: 18px; top: 15px; background: none; border: 0; font-size: 1.5rem; font-weight: 200; }
.auth-dialog form { display: grid; gap: 16px; }
.auth-dialog label { display: grid; gap: 7px; color: #4b4d49; font-size: .75rem; }
.auth-dialog input { width: 100%; height: 46px; padding: 0 12px; border: 1px solid #cfd1cc; background: #fff; }
.auth-dialog input:focus { outline: 2px solid #b5c5ba; border-color: var(--accent); }
.form-error { min-height: 18px; margin: -3px 0 0; font-size: .74rem; }
.auth-switch { display: block; margin: 20px auto 0; }
.muted { color: var(--muted); font-size: .8rem; }

@media (max-width: 850px) {
  .studio { grid-template-columns: 1fr; }
  .controls { border-right: 0; border-bottom: 1px solid var(--line); }
  .preview-column { position: static; order: -1; height: auto; padding: clamp(26px, 8vw, 60px); overflow: visible; }
  .canvas-stage { width: 100%; }
  .preview-canvas { max-width: 560px; margin: 0 auto; }
  .canvas-design-panel { flex: none; max-height: none; overflow: visible; }
  .design-toolbar { top: 0; }
  .history-list { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .site-header { height: 64px; padding: 0 18px; }
  .brand { font-size: .86rem; }
  .brand-mark { width: 19px; height: 19px; }
  .user-greeting { display: none; }
  main, footer { width: calc(100% - 28px); }
  .controls { padding: 26px 20px; }
  .preview-column { padding: 28px 20px 36px; }
  .frame-list, .history-list { grid-template-columns: 1fr; }
  .frame-card { min-height: 78px; }
  .user-layer-grid { grid-template-columns: 1fr 1fr; }
  .canvas-design-panel { margin-top: 22px; padding: 16px 14px; }
  .user-placement { grid-template-columns: 1fr; gap: 6px; }
  .user-asset-upload { grid-template-columns: 1fr; }
  footer { flex-direction: column; gap: 7px; }
  .auth-dialog { padding: 36px 24px 28px; }
}
