:root {
  color-scheme: light;
  --paper: #f7f5ef;
  --card: #fffefa;
  --ink: #252823;
  --muted: #565e53;
  --olive: #3e5542;
  --olive-dark: #2d4130;
  --sage: #e5eadf;
  --line: #deded3;
  --soft: #f4f4ec;
  font-family: system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-size: 16px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; }
button, summary { font: inherit; touch-action: manipulation; }
button { cursor: pointer; color: inherit; }
button:disabled { cursor: default; }
button:focus-visible, summary:focus-visible { outline: 2px solid var(--olive); outline-offset: 4px; }
h1, h2, p { margin: 0; }
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.wrap { max-width: 1216px; margin-inline: auto; padding-inline: max(1.5rem, env(safe-area-inset-left)) max(1.5rem, env(safe-area-inset-right)); }
.masthead { border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.masthead-inner { min-height: 73px; display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.brand { display: flex; align-items: center; gap: .7rem; font-family: Georgia, serif; font-size: 1.32rem; letter-spacing: -.035em; white-space: nowrap; }
.mark { width: 23px; height: 23px; padding: 1px; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; transform: rotate(-9deg); }
.mark i { background: var(--olive); border-radius: 1px; }
.mark i:nth-child(2) { background: #91a08a; }
.mark i:nth-child(3) { background: #b8a88c; }
.privacy { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); font-size: .78rem; }
.privacy .icon { width: 1rem; height: 1rem; }

main { padding-bottom: calc(3rem + env(safe-area-inset-bottom)); }
.intro { padding: 3.3rem 0 2.05rem; }
.intro h1 { font: 400 clamp(2.7rem, 6vw, 5.2rem)/.99 Georgia, serif; letter-spacing: -.065em; }
.intro p { margin-top: 1.12rem; font-size: 1.01rem; line-height: 1.55; color: var(--muted); }
.studio { display: grid; grid-template-columns: minmax(270px, 350px) minmax(0, 1fr); gap: 1.2rem; align-items: start; }
.inputs { display: grid; gap: 1.2rem; min-width: 0; }
.source, .preview { border: 1px solid var(--line); border-radius: 16px; background: var(--card); }
.source { padding: 1.2rem; }
.source-heading { display: flex; gap: .65rem; align-items: flex-start; }
.source-icon { display: grid; place-items: center; width: 36px; height: 36px; background: var(--sage); color: var(--olive); border-radius: 9px; flex: none; }
h2 { font-size: 1rem; font-weight: 650; letter-spacing: -.02em; }
.source-heading p { color: var(--muted); font-size: .82rem; margin-top: .2rem; line-height: 1.4; }
.drop { display: grid; width: 100%; min-height: 103px; place-content: center; justify-items: center; gap: .23rem; margin-top: .95rem; padding: .65rem; background: var(--soft); border: 1px dashed #a0aa98; border-radius: 10px; color: var(--olive-dark); font-size: .91rem; font-weight: 650; }
.drop:active, .drop.dragging { background: var(--sage); border-color: var(--olive); }
.plus { font-size: 1.42rem; line-height: 1.1; font-weight: 400; }
.drop-help { font-size: .77rem; font-weight: 400; color: var(--muted); }
.master-selected { display: flex; align-items: center; gap: .75rem; margin-top: .9rem; color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }
.master-selected canvas { border-radius: 6px; width: 42px; height: 42px; flex: none; }
.master-selected:not([hidden]) + .drop { min-height: 59px; }
.master-selected:not([hidden]) + .drop .plus { display: none; }
.requirement { margin-top: .9rem; }
.tile-count { font-size: .84rem; font-weight: 650; }
progress { display: block; width: 100%; height: 6px; margin-top: .5rem; border: none; border-radius: 99px; overflow: hidden; background: var(--sage); accent-color: var(--olive); }
progress::-webkit-progress-bar { background: var(--sage); }
progress::-webkit-progress-value { background: var(--olive); }
progress::-moz-progress-bar { background: var(--olive); }
.hint, .notice { color: var(--muted); font-size: .77rem; line-height: 1.45; margin-top: .5rem; }
.notice[data-error] { color: #8d342b; }
details { margin-top: .8rem; border-top: 1px solid var(--line); }
summary { min-height: 42px; padding-top: .68rem; font-size: .82rem; color: var(--olive-dark); cursor: pointer; }
#tile-list { display: grid; gap: .35rem; padding: 0; margin: 0; max-height: 240px; overflow: auto; overscroll-behavior: contain; list-style: none; }
#tile-list li { min-height: 44px; display: flex; align-items: center; gap: .4rem; font-size: .74rem; }
#tile-list canvas { width: 35px; height: 35px; border-radius: 5px; flex: none; }
#tile-list span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.remove { width: 44px; height: 44px; margin-left: auto; border: 0; background: transparent; flex: none; font-size: 1.25rem; border-radius: 7px; }
.remove:active { background: var(--sage); }

.preview { padding: 1.1rem; min-width: 0; }
.preview-header, .preview-footer { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.preview-header { min-height: 44px; margin-bottom: .8rem; }
.preview-header h2 { font-size: 1.07rem; }
.preview-stage { min-height: 438px; border-radius: 10px; background: #eeeee4; display: grid; place-items: center; padding: 1.25rem; }
.preview-stage > canvas { display: block; width: auto; height: auto; max-width: 100%; max-height: 570px; object-fit: contain; box-shadow: 0 2px 14px #22251e22; }
.empty-preview { text-align: center; padding: .5rem; }
.empty-preview p { margin: 1.05rem 0 .4rem; font-family: Georgia, serif; font-size: 1.48rem; letter-spacing: -.032em; }
.empty-preview > span { display: block; max-width: 290px; color: var(--muted); font-size: .86rem; line-height: 1.5; }
.sample-grid { position: relative; width: 142px; height: 105px; margin: auto; overflow: hidden; background: radial-gradient(ellipse at 66% 33%, #ede0b7 0 12%, transparent 14%), linear-gradient(149deg, transparent 48%, #75866b 49%, #a5a98b 66%, transparent 67%), linear-gradient(35deg, #78866b 20%, #d4c6a4 65%, #ece1c5 85%); border: 4px solid var(--card); border-radius: 7px; transform: rotate(-5deg); box-shadow: 0 7px 15px #333d252d; }
.sample-grid span { position: absolute; inset: 0; background: repeating-linear-gradient(0deg, #f5f4eb60 0 1px, transparent 1px 10px), repeating-linear-gradient(90deg, #f5f4eb60 0 1px, transparent 1px 11px); }
.preview-footer { min-height: 52px; padding-top: .85rem; }
#preview-status { color: var(--muted); font-size: .81rem; line-height: 1.4; }
.download { flex: none; min-height: 44px; padding: .55rem .75rem; display: inline-flex; align-items: center; justify-content: center; gap: .37rem; border: 1px solid transparent; border-radius: 8px; background: var(--olive); color: white; font-size: .82rem; font-weight: 650; }
.download:disabled { background: var(--sage); color: #535d51; }
.download:not(:disabled):active { background: var(--olive-dark); }
.download .icon { width: 1.05rem; height: 1.05rem; }
.segmented { display: flex; gap: 2px; background: var(--soft); padding: 2px; border: 1px solid var(--line); border-radius: 9px; }
.segmented button { min-height: 38px; border: 1px solid transparent; background: transparent; padding: .25rem .64rem; border-radius: 7px; font-size: .77rem; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--card); color: var(--ink); border-color: var(--line); font-weight: 650; }

@media (hover: hover) and (pointer: fine) {
  .drop:hover, .remove:hover { background: var(--sage); }
  .download:not(:disabled):hover { background: var(--olive-dark); }
  .segmented button:hover { color: var(--ink); }
}
@media (max-width: 780px) {
  .studio { grid-template-columns: 1fr; }
  .inputs { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .intro { padding: 2.5rem 0 1.5rem; }
  .preview-stage { min-height: 350px; }
}
@media (max-width: 520px) {
  .wrap { padding-inline: max(1rem, env(safe-area-inset-left)) max(1rem, env(safe-area-inset-right)); }
  .masthead-inner { min-height: 60px; }
  .brand { font-size: 1.12rem; gap: .5rem; }
  .mark { width: 19px; height: 19px; }
  .privacy { font-size: .67rem; gap: .16rem; }
  .intro { padding: 2rem 0 1.3rem; }
  .intro p { margin-top: .7rem; font-size: .93rem; }
  .inputs { grid-template-columns: 1fr; gap: .8rem; }
  .studio { gap: .8rem; }
  .source, .preview { padding: .88rem; }
  .drop { min-height: 64px; margin-top: .65rem; }
  .drop .plus { display: none; }
  .drop-help { display: none; }
  .preview-stage { min-height: 260px; padding: .65rem; }
  .preview-footer { flex-wrap: wrap; }
}

.layout-size { margin-top: .2rem; color: var(--muted); font-size: .77rem; }
.blend { display: grid; grid-template-columns: auto minmax(0, 1fr) 2.8em; align-items: center; gap: .65rem; margin-top: .65rem; min-height: 44px; font-size: .82rem; color: var(--muted); }
.blend input { width: 100%; min-width: 0; height: 44px; margin: 0; accent-color: var(--olive); }
.blend input:focus-visible { outline: 2px solid var(--olive); outline-offset: 2px; }
.blend output { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 520px) {
  .blend { grid-template-columns: auto 2.8em; justify-content: space-between; gap: 0 .5rem; }
  .blend input { grid-row: 2; grid-column: 1 / -1; }
}
