@font-face {
  font-family: Comfortaa;
  src: url("/room-game-art/comfortaa.ttf") format("truetype");
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #302541;
  --muted: #675c72;
  --surface: #fffcf8;
  --paper: #f8f5ee;
  --line: #e5dce5;
  --accent: #5b4384;
  --accent-deep: #49336e;
  --accent-soft: #eee6f7;
  --sage: #3d6756;
  --brand-font: Comfortaa, system-ui, sans-serif;
  font: 16px/1.45 system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--ink); background: var(--paper); }
button, input { font: inherit; }
button { color: inherit; touch-action: manipulation; }
a { color: inherit; text-underline-offset: .22em; }
button, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
button:disabled { cursor: default; opacity: .45; }
button:not(:disabled), summary { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
.shell { width: min(100% - 56px, 1320px); margin-inline: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

.site-header { border-bottom: 1px solid #e9e0e4; background: #fcf8f1; }
.header-row { min-height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font: 700 1.18rem/1 var(--brand-font); letter-spacing: -.04em; }
.brand img { border-radius: 10px; }
.app-link { display: inline-flex; gap: 8px; align-items: center; min-height: 42px; font-size: .88rem; font-weight: 750; color: var(--accent-deep); text-decoration: none; }
.app-link:hover { text-decoration: underline; }

.page-title { min-height: 83px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.page-title h1 { font: 700 clamp(1.75rem, 3.6vw, 3rem)/1.12 var(--brand-font); letter-spacing: -.05em; }
.header-actions, .room-tools, .scene-exports, .selection-tools, .share-actions { display: flex; align-items: center; gap: 7px; }
.control { display: inline-flex; box-sizing: border-box; align-items: center; justify-content: center; min-height: 42px; padding: 0 13px; gap: 6px; border: 1px solid var(--line); border-radius: 11px; color: var(--accent-deep); background: var(--surface); font-size: .84rem; font-weight: 750; white-space: nowrap; }
.control:not(:disabled):hover, .control[aria-pressed="true"] { background: var(--accent-soft); border-color: #b6a3ce; }
.control.strong { color: #fff; background: var(--accent); border-color: var(--accent); }
.control.strong:not(:disabled):hover { background: var(--accent-deep); border-color: var(--accent-deep); }
.small-count:not(:empty) { min-width: 19px; height: 19px; padding-inline: 4px; display: grid; align-items: center; background: var(--accent-soft); border-radius: 20px; font-size: .69rem; }

.studio { display: grid; grid-template-columns: minmax(0, 1fr) minmax(288px, 330px); align-items: stretch; gap: 16px; }
.room-panel, .library { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; min-width: 0; box-shadow: 0 10px 32px #462a5110; }
.room-panel { display: flex; flex-direction: column; min-height: 0; padding: 12px; }
.room-top { min-height: 55px; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 0 4px 11px; }
.room-identity { display: flex; flex-direction: column; min-width: 0; align-items: flex-start; }
#room-name { min-width: 0; width: min(100%, 280px); max-width: 100%; padding: 2px 7px; border: 1px solid transparent; border-radius: 6px; color: var(--ink); background: transparent; font: 700 1.14rem/1.25 var(--brand-font); }
#room-name:hover, #room-name:focus { background: #faf1ed; border-color: var(--line); }
.saved { min-height: 1em; padding-left: 8px; color: var(--sage); font-size: .71rem; line-height: 1.2; }
.save-row { display: flex; align-items: center; gap: 6px; }
.save-row .text-button { min-height: 24px; font-size: .68rem; }
#delete-room .share-actions { margin-top: 14px; }
.icon-button { width: 42px; padding: 0; font-size: 1.22rem; line-height: 1; }
.stage-shell { position: relative; overflow: hidden; border-radius: 16px; border: 1px solid #eadcdb; background: #f9eee6; }
.stage-shell[data-wall="indigo"] { background: #eee8f6; }
#room-canvas { display: block; width: 100%; aspect-ratio: 88 / 63; height: auto; cursor: default; touch-action: none; user-select: none; }
#room-canvas[data-mode="place"] { cursor: crosshair; }
#room-canvas[data-mode="move"] { cursor: grab; }
#room-canvas[data-mode="drag"] { cursor: grabbing; }
#room-canvas:focus-visible { outline-offset: -4px; }
.resize-outline { position: absolute; pointer-events: none; border: 1px dashed #5b4384b3; border-radius: 6px; }
.resize-handle { position: absolute; display: grid; place-items: center; width: 44px; height: 44px; transform: translate(-50%, -50%); padding: 0; border: 0; background: transparent; touch-action: none; cursor: nwse-resize; }
.resize-handle:not(:disabled), .resize-handle:active { cursor: nwse-resize; }
.resize-handle span { display: grid; place-items: center; width: 30px; height: 30px; border: 2px solid #fffaf4; border-radius: 50%; background: var(--accent); box-shadow: 0 2px 7px #3c224d60; color: #fff; font: 750 1.05rem/1 system-ui, sans-serif; }
.resize-handle:hover span, .resize-handle:active span { background: var(--accent-deep); }
.stage-prompt, .load-error { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); width: max-content; max-width: calc(100% - 24px); text-align: center; background: #fffaf0f5; box-shadow: 0 2px 12px #563b651d; color: var(--accent-deep); border: 1px solid #e5d3e5; border-radius: 10px; padding: 7px 12px; font-size: .84rem; font-weight: 710; pointer-events: none; }
.load-error { top: 45%; }
.scene-actions { min-height: 61px; padding: 8px 4px 1px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#stage-help { color: var(--muted); font-size: .84rem; line-height: 1.35; }
.selection { display: grid; grid-template-columns: minmax(86px, auto) minmax(152px, 1fr) auto; align-items: center; gap: 12px; margin-top: 7px; padding: 8px 10px; border: 1px solid #e8dcee; border-radius: 12px; background: #f8f1fb; }
.selection strong { font-size: .87rem; }
.size-control { display: grid; grid-template-columns: auto minmax(34px, 1fr) 4.7em; align-items: center; gap: 9px; min-width: 0; color: var(--accent-deep); font-size: .82rem; font-weight: 700; }
#item-size { width: 100%; min-width: 0; height: 44px; margin: 0; accent-color: var(--accent); cursor: ew-resize; }
.size-value { display: flex; height: 36px; align-items: center; justify-content: end; gap: 2px; border: 1px solid #d9cbe7; border-radius: 8px; padding-right: 6px; background: var(--surface); font-variant-numeric: tabular-nums; }
#size-reading { appearance: textfield; width: 100%; min-width: 0; height: 100%; border: 0; border-radius: 8px; background: transparent; color: inherit; text-align: right; padding: 0; }
#size-reading::-webkit-inner-spin-button, #size-reading::-webkit-outer-spin-button { appearance: none; margin: 0; }
.selection-tools { flex-wrap: wrap; }
.selection-tools .control { min-width: 44px; min-height: 44px; padding-inline: 9px; }
.remove { color: #803c52; }

.library { display: flex; flex-direction: column; min-height: 0; }
.library-heading { padding: 15px 14px 9px 16px; display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.library-heading h2 { font: 700 1.18rem/1.15 var(--brand-font); }
.text-button { border: 0; background: transparent; min-height: 34px; padding: 0 4px; color: var(--accent-deep); font-weight: 730; font-size: .79rem; }
.text-button:hover { text-decoration: underline; }
.text-button span { padding-inline: 4px; }
.tabs { display: grid; grid-template-columns: 1fr 1.22fr 1fr; align-items: stretch; margin: 0 12px 11px; padding: 4px; gap: 2px; background: #f1eaf1; border-radius: 13px; }
.tabs button { border: 0; border-radius: 9px; min-height: 39px; padding: 5px 4px; background: transparent; color: var(--muted); font-weight: 740; font-size: .85rem; }
.tabs [aria-selected="true"] { background: #fffdf9; color: var(--accent-deep); box-shadow: 0 1px 5px #402b5a19, inset 0 -2px #a48bc0; }
.library-content { position: relative; min-height: 0; flex: 1; }
.inventory, .finishes { position: absolute; inset: 0; overflow: auto; overscroll-behavior: contain; scrollbar-color: #cabbcf transparent; scrollbar-width: thin; padding: 2px 12px 14px; }
.filters { display: flex; overflow: auto; overscroll-behavior-x: contain; padding: 0 12px 9px; gap: 4px; scrollbar-width: thin; }
.filters:not([hidden]) ~ .inventory { top: 43px; }
.filters .control { min-height: 34px; padding-inline: 8px; font-size: .76rem; }
.inventory { display: grid; align-content: start; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.asset-card { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; justify-content: center; min-height: 99px; padding: 7px 2px; border: 1px solid #eadce7; border-radius: 12px; background: #faf4eb; color: var(--ink); font-size: .73rem; font-weight: 690; line-height: 1.2; }
.asset-card[aria-pressed="true"], .asset-card:hover:not(:disabled) { border-color: var(--accent); background: #f0e5fa; }
.asset-card[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--accent); }
.asset-card img, .asset-card canvas { display: block; width: 63px; height: 62px; object-fit: contain; image-rendering: pixelated; }
.asset-card span { max-width: 100%; overflow-wrap: anywhere; }
.asset-card .asset-lock { color: var(--accent-deep); font-size: .67rem; font-weight: 800; }
.finishes { padding: 4px 16px 18px; }
.finishes > div + div { margin-top: 18px; }
.finishes h3 { margin-bottom: 9px; font-size: .87rem; }
.swatches { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.swatch { display: flex; min-height: 62px; padding: 7px 2px 5px; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: .71rem; font-weight: 700; line-height: 1.15; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.swatch::before { content: ""; width: 24px; height: 24px; border-radius: 7px; background: var(--sample); border: 1px solid #30254125; }
.swatch[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }

.app-panel { display: grid; grid-template-columns: 100px minmax(0, 1fr) auto; align-items: center; gap: 18px; margin-top: 20px; padding: 17px 20px; border: 1px solid #e3d8e9; border-radius: 20px; background: #f1e9f5; }
.app-preview { display: grid; place-items: center; min-height: 88px; background: #f8f0ed; border: 1px solid #e9dcea; border-radius: 14px; }
.app-preview img { width: 72px; height: 72px; object-fit: contain; image-rendering: pixelated; }
.app-copy h2 { font: 700 clamp(1.05rem, 2vw, 1.32rem)/1.3 var(--brand-font); }
.app-copy p { max-width: 55ch; color: var(--muted); font-size: .84rem; margin-top: 5px; }
.app-copy .offer { color: var(--accent-deep); font-size: .77rem; font-weight: 720; }
.stores { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.stores a { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 12px; color: white; font-size: .81rem; font-weight: 750; text-decoration: none; background: var(--accent); border-radius: 10px; }
.stores a:hover { background: var(--accent-deep); }
.about-links { display: flex; flex-wrap: wrap; gap: 8px 20px; padding: 12px 4px 0; color: var(--muted); font-size: .83rem; }
.guide { display: inline-flex; align-items: center; min-height: 42px; }
.video-demo summary { min-height: 42px; display: list-item; align-content: center; }
.video-demo video { display: block; width: min(16rem, 100%); height: auto; border-radius: 12px; margin: 6px 0 12px; }
.footer { display: flex; gap: 14px; padding-block: 14px 30px; color: var(--muted); font-size: .8rem; }

dialog { position: fixed; color: var(--ink); background: var(--surface); width: min(620px, 100% - 32px); max-height: min(88dvh, 760px); padding: 18px; border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 20px 80px #3025413b; }
dialog::backdrop { background: #3627497c; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.dialog-head h2 { font: 700 1.35rem/1.25 var(--brand-font); }
.close-dialog { width: 40px; padding: 0; font-size: 1.31rem; }
dialog h3 { margin: 15px 0 8px; font-size: .91rem; }
.dialog-note { margin-top: 12px; color: var(--muted); font-size: .82rem; }
.room-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.room-card { min-width: 0; padding: 6px; border: 1px solid var(--line); border-radius: 11px; background: #f9f1f3; text-align: start; font-size: .8rem; font-weight: 720; }
.room-card[aria-current="true"], .room-card:hover:not(:disabled) { border-color: var(--accent); }
.room-card canvas { display: block; width: 100%; height: auto; border-radius: 7px; margin-bottom: 5px; }
.room-card span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.challenge-list { display: grid; gap: 9px; }
.challenge-card { display: grid; gap: 8px; border: 1px solid var(--line); border-radius: 12px; padding: 11px; background: #fbf5f2; }
.challenge-card h3 { margin: 0; }
.daily-room { background: #f3edf8; border-color: #d9c7e7; }
.daily-room time { color: var(--muted); font-size: .77rem; }
.daily-room .challenge-reward button:only-child { margin-inline-start: auto; }
.challenge-card ul { margin: 0; padding: 0; list-style: none; font-size: .83rem; }
.challenge-card li { display: flex; align-items: center; gap: 7px; min-height: 24px; color: var(--muted); }
.challenge-card li[data-done="true"] { color: var(--sage); }
.challenge-reward { display: flex; align-items: center; justify-content: space-between; gap: 7px; font-size: .8rem; }
.challenge-reward.with-photo-link { flex-wrap: wrap; }
.challenge-reward strong { color: var(--accent-deep); }
.placed-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.placed-list button { white-space: normal; text-align: start; justify-content: flex-start; }
#app-dialog { width: min(480px, 100% - 24px); }
#app-dialog .close-dialog { display: flex; min-height: 40px; margin: 0 0 8px auto; }
#app-dialog .app-panel { grid-template-columns: 64px minmax(0, 1fr); margin-top: 0; padding: 0; border: 0; background: none; gap: 12px; }
#app-dialog .app-preview { min-height: 64px; }
#app-dialog .app-preview img { width: 54px; height: 54px; }
#app-dialog .stores { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-column: 1 / -1; margin-top: 4px; }
#app-dialog .stores a { padding-inline: 6px; }
#share-dialog { width: min(520px, 100% - 32px); }
#share-dialog .dialog-note { margin-bottom: 12px; }
.share-preview { display: block; width: auto; height: auto; max-width: 100%; max-height: min(47dvh, 380px); margin: 0 auto; border: 1px solid var(--line); border-radius: 12px; }
.share-url { display: block; width: 100%; min-height: 44px; padding: 7px; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 9px; margin-block: 8px 10px; }
.share-actions { flex-wrap: wrap; }
.share-actions span { flex-basis: 100%; color: var(--sage); font-size: .83rem; }

@media (min-width: 851px) {
  #room-canvas {
    width: min(100%, calc(1.396825 * clamp(340px, 100dvh - 285px, 654px)));
    margin-inline: auto;
  }
}

@media (max-width: 850px) {
  .shell { width: min(100% - 32px, 720px); }
  .studio { grid-template-columns: 1fr; gap: 11px; }
  .room-panel { padding: 8px; }
  .library { min-height: 330px; }
  .inventory, .finishes { position: static; max-height: 310px; }
  .inventory { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .finishes { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .finishes > div + div { margin-top: 0; }
  .app-panel { grid-template-columns: 74px minmax(0, 1fr); gap: 12px; }
  .stores { grid-column: 2; }
  .app-preview { min-height: 74px; }
  .app-preview img { width: 59px; height: 59px; }
  .selection { grid-template-columns: minmax(0, 1fr) auto; column-gap: 10px; }
  .size-control { grid-row: 2; grid-column: 1 / -1; }
  .selection-tools { justify-content: flex-end; gap: 4px; }
}

@media (max-width: 510px) {
  .shell { width: calc(100% - 24px); }
  .header-row { min-height: 48px; }
  .brand { font-size: 1.03rem; gap: 7px; }
  .brand img { width: 31px; height: 31px; }
  .app-link { font-size: .75rem; }
  .page-title { min-height: 56px; gap: 6px; }
  .page-title h1 { font-size: clamp(1.25rem, 6vw, 1.75rem); }
  .header-actions { gap: 4px; }
  .header-actions .control { min-height: 38px; padding-inline: 8px; font-size: .73rem; }
  .room-top { min-height: 43px; padding: 0 2px 5px; gap: 5px; }
  #room-name { font-size: .96rem; padding-inline: 4px; }
  .saved { font-size: .61rem; padding-left: 5px; }
  .room-tools { gap: 4px; }
  .room-tools .control { min-height: 38px; }
  .icon-button { width: 38px; }
  .grid-button { padding-inline: 7px; }
  .room-panel, .library { border-radius: 16px; }
  .stage-shell { border-radius: 11px; }
  .stage-prompt { top: 6px; padding: 3px 7px; font-size: .69rem; }
  .scene-actions { align-items: center; min-height: 45px; padding: 4px 1px 0; gap: 5px; }
  #stage-help { font-size: .72rem; }
  .scene-exports .control { min-height: 38px; padding-inline: 7px; font-size: .73rem; }
  .scene-exports { gap: 4px; }
  .selection { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .selection-tools { justify-content: flex-start; }
  .selection-tools .control { padding-inline: 8px; }
  .library { min-height: 296px; }
  .library-heading { padding-top: 7px; padding-bottom: 4px; }
  .library-heading h2 { font-size: 1rem; }
  .tabs { margin-bottom: 8px; }
  .inventory { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .asset-card { min-height: 85px; font-size: .68rem; }
  .asset-card img, .asset-card canvas { width: 55px; height: 53px; }
  .app-panel { grid-template-columns: 50px minmax(0, 1fr); padding: 11px; gap: 8px; }
  .app-preview { min-height: 54px; }
  .app-preview img { width: 44px; height: 44px; }
  .app-copy p { font-size: .77rem; }
  .app-copy .offer { font-size: .73rem; }
}

@media (max-width: 348px) {
  .page-title h1 { font-size: 1.17rem; }
  .header-actions .control { padding-inline: 6px; }
  .selection-tools .control { padding-inline: 5px; font-size: .79rem; }
  .inventory { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .room-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: no-preference) {
  .control, .asset-card, .stores a { transition: background-color .14s ease, border-color .14s ease; }
}
