* { box-sizing: border-box; }
body, p { margin: 0; }
[hidden] { display: none !important; }
button, input, summary { font: inherit; color: inherit; }
button, summary, input[type=color] { cursor: pointer; touch-action: manipulation; }
button, summary {
  min-height: 44px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  font-size: .875rem;
  font-weight: 640;
  white-space: nowrap;
}
button, summary { -webkit-user-select: none; user-select: none; }
button:hover:not(:disabled), summary:hover { background: var(--hover); }
button:disabled { opacity: .5; cursor: default; }
button[aria-pressed=true] {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--surface);
}
button[aria-pressed=true]:hover:not(:disabled), button.primary:hover:not(:disabled) { background: var(--primary-hover); }
button.primary, #workshop-submit, #workshop-copy {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--surface);
}
button.primary:hover:not(:disabled), #workshop-submit:hover:not(:disabled), #workshop-copy:hover:not(:disabled) { background: var(--primary-hover); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.studio-icons { position: absolute; width: 0; height: 0; overflow: hidden; }
.ui-icon {
  flex: none;
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#studio {
  --frame-inset: clamp(12px,1.65vw,27px);
  --dock-reserve: 138px;
  --view-controls-space: 154px;
  display: grid;
  grid-template-rows: auto minmax(0,1fr) auto;
  min-height: 0;
  height: 100vh;
  height: 100dvh;
  background: var(--paper);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
#studio:fullscreen, #studio.expanded { height: 100dvh; }
#studio.expanded { position: fixed; inset: 0; z-index: 3; }
.studio-bar {
  position: relative;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: max(10px,env(safe-area-inset-top)) var(--frame-inset) 11px;
}
.studio-identity, .studio-brand, .header-controls, .history, .joined {
  display: flex;
  align-items: center;
}
.studio-identity { min-width: 0; gap: 16px; }
.studio-brand {
  gap: 9px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
  font-size: .95rem;
  font-weight: 680;
  letter-spacing: -.025em;
}
.studio-context {
  display: grid;
  align-content: center;
  min-width: 0;
  padding-inline-start: 16px;
  border-inline-start: 1px solid var(--line);
}
.studio-context:not(:has(> :not([hidden]))) { display: none; }
#drawing-context {
  color: var(--ink);
  font-size: .875rem;
  font-weight: 670;
  overflow-wrap: anywhere;
}
#studio[data-joining-commons] #drawing-context { display: none; }
#studio[data-joining-commons] .stage { visibility: hidden; }
#studio[data-public-plot] #canvas-mode { display: none; }
#commons-presence {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: .75rem;
}
#commons-presence[data-live]::before {
  content: '';
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #478260;
}
#back-to-studio {
  justify-self: start;
  min-height: 28px;
  padding: 2px 0;
  border: 0;
  color: var(--primary);
  background: transparent;
  font-size: .8125rem;
  text-decoration: underline;
  text-underline-offset: .2em;
}
.header-controls { flex: none; gap: 6px; }
#canvas-mode, .more summary { background: transparent; border-color: transparent; }
#canvas-mode:hover, .more summary:hover, .more[open] summary { background: var(--hover); }
.more { position: relative; }
.more summary {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}
.more[open] summary .chevron { transform: rotate(225deg); }
.more summary::-webkit-details-marker { display: none; }
.more-actions {
  position: absolute;
  inset: calc(100% + 7px) 0 auto auto;
  display: grid;
  gap: 2px;
  min-width: 190px;
  max-height: calc(100dvh - 90px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-float);
}
.more-actions :is(button,a) {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--ink);
  font-size: .875rem;
  font-weight: 580;
  text-align: start;
  text-decoration: none;
}
.more-actions :is(button:not(:disabled),a):hover { background: var(--hover); }
.more-actions .account-link { border-top: 1px solid var(--line); border-start-start-radius: 0; border-start-end-radius: 0; }
.toolbar {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: auto auto minmax(94px,112px) minmax(106px,130px) auto;
  align-items: center;
  justify-self: center;
  max-width: 100%;
  gap: 4px;
  padding: 5px;
  margin: 10px 0 max(10px,env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-control);
}
.history {
  padding-inline-start: 4px;
  margin-inline-start: 2px;
  border-inline-start: 1px solid var(--line);
}
.history button {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  min-width: 44px;
  padding: 4px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: .6875rem;
  line-height: 1.15;
}
.history button:not(:disabled):hover { background: var(--hover); color: var(--ink); }
.joined button:focus-visible { position: relative; z-index: 1; }
.joined button:first-child { border-start-end-radius: 0; border-end-end-radius: 0; }
.joined button:last-child { border-start-start-radius: 0; border-end-start-radius: 0; margin-inline-start: -1px; }
#studio[data-visiting] .toolbar { display: none; }
#studio[data-visiting] .stage { margin-block-end: var(--frame-inset); }
.stage {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0,1fr);
  grid-template-rows: minmax(0,1fr);
  min-height: 0;
  margin-inline: var(--frame-inset);
  overflow: hidden;
  border: 1px solid #282b241f;
  border-radius: var(--radius-card);
  background: var(--stoneware);
}
.stage:has(.peer-tile:not([hidden])) { grid-template-columns: minmax(0,1fr) minmax(185px,32%); }
.editor-stage { min-width: 0; min-height: 0; position: relative; overflow: hidden; container-type: size; }
#viewport { position: relative; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
#viewport:focus-visible { outline-offset: -3px; }
#viewport[data-tool=orbit] { cursor: grab; }
#viewport[data-tool=orbit]:active { cursor: grabbing; }
#viewport canvas { display: block; width: 100%; height: 100%; }
#commons-cursors { position: absolute; inset: 0; pointer-events: none; }
#commons-cursors span {
  position: absolute;
  inset: 0 auto auto 0;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--surface);
  font-size: .75rem;
  white-space: nowrap;
}
.commons-share { display: grid; gap: 9px; padding: 16px 18px 20px; }
.commons-share p { color: var(--muted); }
.commons-share label { font-weight: 640; font-size: .875rem; }
.commons-share input { min-width: 0; min-height: 44px; padding: 8px 10px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-control); }
.commons-share button { justify-self: start; }
#commons-share-status:empty { display: none; }
#viewport:is([data-tool=sculpt],[data-tool=lift]) { cursor: grab; }
#viewport[data-tool=style] { cursor: pointer; }
#viewport[data-grabbing] { cursor: grabbing; }
#loop-cue {
  position: absolute;
  width: 24px;
  height: 24px;
  transform: translate(-50%,-50%);
  border: 2px dashed #fff1b6;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #553b43b8;
  pointer-events: none;
}
#loop-cue[data-state=snapped] {
  border-style: solid;
  background: #ffeab642;
}
#loop-cue[data-touch] { width: 36px; height: 36px; }
#seam-cue {
  position: absolute;
  width: 10px;
  height: 10px;
  transform: translate(-50%,-50%);
  border: 1.5px solid #fff1b6;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #553b43b8;
  pointer-events: none;
}
#seam-cue::before {
  content: '';
  position: absolute;
  inset: 50% auto auto 50%;
  width: 13px;
  border-top: 1.5px solid #fff1b6;
  transform: rotate(var(--seam-angle)) translateX(6px);
  transform-origin: left center;
}
#seam-cue[data-snapped] { background: #fff1b6; box-shadow: 0 0 0 3px #ffedaa55; }
.stage-status {
  position: absolute;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  top: 12px;
  left: 12px;
  right: 12px;
  pointer-events: none;
}
.stage-status button { pointer-events: auto; }
.editor-stage:has(#clear-room:not([hidden])) .stage-status { right: 116px; }
#workshop-plot, #visit-status:not(:empty), .canvas-note:not(:empty) {
  padding: 7px 11px;
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-control);
  font-size: .875rem;
  overflow-wrap: anywhere;
}
#workshop-back { pointer-events: auto; }
.peer-tile {
  display: grid;
  grid-template-rows: auto minmax(0,1fr);
  min-width: 0;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: var(--stoneware);
}
.peer-tile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--ink);
}
.peer-tile-head h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .875rem; font-weight: 700; }
#peer-presence { font-size: .8rem; white-space: nowrap; }
.peer-preview { min-width: 0; min-height: 0; overflow: hidden; }
.peer-preview canvas { display: block; width: 100%; height: 100%; }
.canvas-note {
  position: absolute;
  bottom: 14px;
  left: 50%;
  width: max-content;
  max-width: calc(100% - 24px);
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
}
#instruction:not(:empty) { bottom: 65px; }
#room-status:not(:empty) { bottom: 116px; }
#room-status button { margin-inline-start: 8px; color: var(--ink); pointer-events: auto; }
.orbit-controls {
  position: absolute;
  right: 13px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-control);
}
.orbit-controls > button {
  min-width: 54px;
  border-color: transparent;
}
#top-view[aria-pressed=true] { background: var(--primary-wash); color: var(--primary); }
.orbit-controls .joined button { min-width: 44px; font-size: 1.25rem; }
#view-return { background: var(--primary); color: var(--surface); }
#view-panel {
  left: auto;
  right: 0;
  width: min(320px,calc(100vw - 30px));
  max-height: min(465px,calc(100cqh - 76px));
}
.view-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
#view-hint { color: var(--muted); font-size: .875rem; }
#color-chip {
  flex: none;
  width: 14px;
  height: 14px;
  border: 1px solid #22282435;
  border-radius: 50%;
  background: var(--brush-color,#ba533b);
}
.dock-control { position: relative; min-width: 0; }
.dock-control > button {
  display: grid;
  align-content: center;
  width: 100%;
  min-height: 44px;
  padding: 3px 10px;
  gap: 2px;
  text-align: start;
  background: transparent;
  border-color: transparent;
}
.dock-control > button:is(:hover,:focus-visible):not(:disabled) { background: var(--subtle); }
.dock-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: .6875rem;
  font-weight: 550;
  line-height: 1.1;
}
.dock-label::after {
  content: '';
  width: 5px;
  height: 5px;
  border-right: 1.5px solid;
  border-bottom: 1.5px solid;
  transform: translateY(-1px) rotate(45deg);
}
.dock-value {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 680;
  line-height: 1.25;
}
#pattern-symbol { color: var(--primary); }
#pattern-shape-name { overflow: hidden; text-overflow: ellipsis; }
.draw-tools {
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: 2px;
  padding: 2px;
  border-radius: 11px;
  background: var(--subtle);
}
.draw-tools button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.draw-tools button, #tool-toggle {
  background: transparent;
  border-color: transparent;
}
.draw-tools button:hover:not(:disabled), #tool-toggle:hover:not(:disabled) { background: var(--hover); }
.draw-tools button[aria-pressed=true], .draw-tools button[aria-pressed=true]:hover {
  color: var(--clay);
  background: var(--surface);
  border-color: var(--line);
  box-shadow: var(--shadow-control);
}
.draw-tools button[data-suggested] { outline: 2px solid var(--clay); outline-offset: -3px; }
#tool-toggle { display: flex; align-items: center; justify-content: center; gap: 4px; text-align: center; }
#tool-toggle[data-active-tool] { color: var(--clay); background: var(--clay-wash); }
#studio:has(#color-panel[data-editing-stroke]) #instruction { display: none; }
.tool-menu-arrow { flex: none; margin-inline: 1px 2px; }
#tool-toggle[aria-expanded=true] .tool-menu-arrow { transform: rotate(225deg); }
.editor-stage:has(#first-creation:not([hidden])) :is(#share-clip,#instruction) { display: none; }
.dock-control > button[aria-expanded=true], #view-toggle[aria-expanded=true] { background: var(--primary-wash); color: var(--primary); }
.palette-title { margin: 12px 0 4px; font-size: .875rem; font-weight: 650; }
#stroke-edit-actions { display: flex; gap: 6px; }
#stroke-edit-actions button { padding-inline: 9px; }
.brush-width {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  margin-bottom: 8px;
  font-size: .875rem;
}
.brush-width label { font-weight: 650; }
.brush-width output { font-variant-numeric: tabular-nums; }
.brush-width input { grid-column: 1 / -1; width: 100%; min-height: 44px; margin: 0; accent-color: var(--primary); }
#brush-legacy:not([hidden]) { margin-top: 6px; font-size: .875rem; }
.tool-choices { display: grid; gap: 4px; }
.tool-choices button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 46px;
  text-align: start;
  white-space: normal;
  border-color: transparent;
  background: transparent;
}
.tool-choices button[aria-pressed=true] { border-color: var(--primary-edge); background: var(--primary-wash); color: var(--primary); }
.tool-choices button[aria-pressed=true]:hover { background: var(--hover); }
.tool-choices strong, .tool-choices small { display: block; }
.tool-choices small { color: var(--muted); font-weight: 450; font-size: .8rem; }
.tool-choices kbd { color: #55685b; font-size: .75rem; }
@media (pointer:coarse) { .tool-choices kbd { display: none; } }
.palette {
  display: grid;
  grid-template-columns: repeat(6,minmax(0,1fr));
  gap: 4px;
  margin-block: 8px 10px;
}
.palette .color-swatch {
  display: grid;
  place-items: center;
  padding: 4px;
  background: var(--surface);
}
.color-swatch::before {
  content: '';
  width: 100%;
  height: 100%;
  border: 1px solid #17282136;
  border-radius: 4px;
  background: var(--swatch);
}
.palette .color-swatch:is(:hover,[aria-pressed=true]) {
  border-color: var(--primary);
  background: var(--hover);
}
.palette .color-swatch[aria-pressed=true] { box-shadow: inset 0 0 0 2px var(--primary); }
.advanced-color summary { display: list-item; padding-block: 10px; }
#custom-color {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 7px;
  padding-top: 10px;
}
#custom-color label {
  display: grid;
  gap: 4px;
  font-size: .875rem;
  font-weight: 650;
}
#custom-color input {
  min-height: 44px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  padding: 6px;
  font-size: 1rem;
}
#custom-color label:nth-child(2) { flex: 1 1 80px; }
.chevron {
  width: 7px;
  height: 7px;
  margin: -3px 2px 0 1px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
}
.tile-icon {
  display: inline-grid;
  width: 16px;
  height: 16px;
  flex: none;
  place-items: center;
  color: var(--primary);
}
.tile-icon::before {
  content: '';
  width: 100%;
  height: 100%;
  background: currentColor;
  clip-path: polygon(50% 0,94% 25%,94% 75%,50% 100%,6% 75%,6% 25%);
}
.tile-icon[data-shape=square]::before { clip-path: inset(9% round 12%); }
.tile-icon[data-shape=triangles]::before { clip-path: polygon(50% 3%,97% 94%,3% 94%); }
.tile-icon[data-shape=open]::before { clip-path: inset(24% 4% round 12%); }
.dock-panel {
  position: absolute;
  z-index: 2;
  bottom: calc(100% + 14px);
  left: 0;
  width: 320px;
  max-width: calc(100vw - 16px);
  max-height: min(465px,calc(100dvh - var(--dock-reserve) - env(safe-area-inset-bottom) - env(safe-area-inset-top)));
  overscroll-behavior: contain;
  overflow: auto;
  padding: 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-float);
}
.panel-head { position: sticky; z-index: 1; top: -12px; margin: -12px -12px 8px; padding: 6px 12px; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.panel-head h2 { margin: 0; font-size: 1.02rem; font-weight: 680; letter-spacing: -.025em; }
:is(#pattern-panel fieldset,.brush-shape) { min-width: 0; margin: 8px 0 12px; padding: 0; border: 0; }
:is(#pattern-panel legend,.brush-shape legend) { margin-bottom: 6px; padding: 0; font-size: .875rem; font-weight: 650; }
.shape-options { display: grid; gap: 6px; grid-template-columns: repeat(3,minmax(0,1fr)); }
.shape-options label {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 7px;
  padding: 9px 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--paper);
  font-size: .875rem;
  font-weight: 630;
  cursor: pointer;
}
.shape-options label:hover { background: var(--hover); }
.shape-options label:has(input:checked) { color: var(--primary); border-color: var(--primary-edge); background: var(--primary-wash); }
.shape-options label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.shape-options input { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); }
.shape-options .tile-icon { width: 24px; height: 24px; }
.brush-shape .shape-options label { min-height: 44px; align-content: center; }
#pattern-legacy { margin-top: 7px; color: var(--muted); font-size: .875rem; }
.pattern-options { display: flex; flex-wrap: wrap; gap: 6px; }
.pattern-options button { flex: 1 1 auto; }
.graphics-error, #studio-loading {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%,-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 16px;
  border-radius: 10px;
  background: var(--paper);
}
.graphics-error h1 { margin: 0 0 10px; font-size: 1.2rem; }
.graphics-error p { margin-bottom: 8px; }
dialog {
  width: min(520px,calc(100% - 24px));
  max-height: calc(100dvh - 26px);
  border: 1px solid var(--line);
  border-radius: var(--radius-dialog);
  padding: 0;
  background: var(--surface);
  box-shadow: var(--shadow-float);
  color: var(--ink);
}
dialog::backdrop { background: var(--backdrop); }
.room-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
}
.room-dialog-head h2 { margin: 0; font-size: 1.22rem; font-weight: 680; letter-spacing: -.025em; }
.workshop-body { display: grid; gap: 12px; padding: 16px; }
.together-body { display: grid; gap: 12px; padding: 16px; }
.together-body p { color: var(--muted); font-size: .9rem; }
.together-body p:empty { display: none; }
.together-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.together-option { display: grid; align-content: start; flex: 1 1 190px; gap: 5px; min-width: 0; }
.together-option button { white-space: normal; }
#together-link-label, #plot-edit-link-label { display: grid; gap: 5px; font-size: .9rem; }
#plot-edit-restore { color: var(--clay); }
#plot-edit-help { overflow-wrap: anywhere; }
.together-body input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
}
#together-name-form { margin-top: 8px; }
#together-name-label { display: list-item; }
#together-leave { justify-self: start; }
.workshop-body p:empty { display: none; }
.workshop-row, .workshop-map-head, #workshop-resume { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.workshop-map-head { justify-content: space-between; margin-bottom: 10px; }
.workshop-body label { display: block; margin-bottom: 6px; font-weight: 650; }
.workshop-body input {
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  padding: 7px 10px;
  background: var(--surface);
}
.workshop-row input { flex: 1 1 135px; }
#workshop-invite { width: 100%; }
#workshop-form p, #plot-status, #roster-status { margin: 8px 0; font-size: .875rem; }
#workshop-plots { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(125px,100%),1fr)); gap: 7px; }
#workshop-plots button { display: grid; gap: 4px; white-space: normal; overflow-wrap: anywhere; text-align: left; }
#workshop-plots button[aria-current] { background: var(--primary-wash); opacity: 1; }
#workshop-plots span { font-weight: 450; font-size: .8rem; }
#workshop-open:is([data-sync=offline],[data-sync=error],[data-sync=conflict])::after { content: ' !'; }
#workshop-leave, #workshop-resume-link { color: var(--primary); padding-block: 6px; justify-self: start; }

@media (min-width: 741px) {
  #pattern-panel { inset-inline: auto 0; }
}
@media (max-width: 740px) {
  #studio { --frame-inset: 10px; }
  .toolbar { justify-self: stretch; margin-inline: var(--frame-inset); }
  .dock-control { position: static; }
  .dock-panel {
    inset: auto 0 calc(100% + 6px);
    width: auto;
    max-width: 400px;
    margin-inline: auto;
  }
  .orbit-controls .dock-panel {
    inset: auto 0 calc(100% + 6px) auto;
    width: min(320px,calc(100vw - var(--frame-inset) - 30px));
  }
  #color-panel[data-editing-stroke] { max-height: 33dvh; }
}
@media (max-width: 600px) {
  #studio { --frame-inset: 8px; --dock-reserve: 170px; --view-controls-space: 90px; }
  .studio-bar { padding-block: max(6px,env(safe-area-inset-top)) 6px; gap: 8px; }
  .studio-identity { gap: 7px; }
  .studio-identity:has(.studio-context > :not([hidden])) > .studio-brand { flex: none; }
  .studio-identity:has(.studio-context > :not([hidden])) .studio-name { display: none; }
  .studio-context { padding-inline-start: 0; border: 0; }
  .studio-brand .studio-mark { width: 28px; }
  .header-controls { gap: 2px; }
  .header-controls > button, .more summary { padding-inline: 8px; }
  .stage { margin-inline: 0; border-radius: 0; border-inline: 0; }
  .toolbar {
    grid-template-columns: minmax(0,.75fr) minmax(0,1fr) minmax(0,1.15fr) auto;
    gap: 2px;
    padding: 4px;
    margin-block: 5px max(5px,env(safe-area-inset-bottom));
  }
  .draw-tools { grid-column: 1 / -1; }
  .draw-tools button { padding-inline: 4px; }
  .dock-control > button { padding-inline: 6px; }
  .history { margin-inline-start: 0; padding-inline-start: 2px; }
  .orbit-controls { right: 8px; bottom: 8px; flex-direction: column; align-items: stretch; gap: 2px; }
  .orbit-controls > button { min-width: 53px; padding-inline: 6px; }
  #view-panel { max-height: min(465px,calc(100cqh - 117px)); }
  #view-return { white-space: normal; width: 66px; }
  #instruction:not(:empty) { bottom: 10px; left: 8px; max-width: calc(100% - 93px); transform: none; text-align: start; }
  #room-status:not(:empty) { bottom: 110px; }
}
@media (min-width: 500px) and (max-width: 600px) and (max-height: 480px) and (orientation: landscape) {
  #studio { --dock-reserve: 126px; --view-controls-space: 154px; }
  .toolbar { grid-template-columns: minmax(0,1fr) auto 70px 88px auto; }
  .draw-tools { grid-column: auto; }
  .draw-tools .ui-icon { width: 14px; }
  .draw-tools button { gap: 3px; }
  .orbit-controls { flex-direction: row; }
  #view-panel { max-height: min(465px,calc(100cqh - 68px)); }
  #view-return { width: auto; }
  #instruction:not(:empty) { max-width: calc(100% - 150px); }
}
@media (max-width: 660px) and (orientation: portrait) {
  .stage:has(.peer-tile:not([hidden])) {
    grid-template-columns: minmax(0,1fr);
    grid-template-rows: minmax(0,1fr) clamp(86px,23dvh,165px);
  }
  .peer-tile { border-left: 0; border-top: 1px solid var(--line); }
  .peer-tile-head { padding-block: 5px; }
}
@media (max-width: 360px) {
  .more summary .chevron { display: none; }
  #pattern-symbol { display: none; }
  .dock-value { gap: 3px; font-size: .8125rem; }
  .dock-control > button { padding-inline: 5px; }
  #color-chip { width: 11px; height: 11px; }
  .palette { column-gap: 3px; }
}

.coach-tip {
  position: absolute;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: min(330px, calc(100% - 24px));
  padding: 5px 5px 5px 13px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--clay);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-float);
  color: var(--ink);
  font-size: .9rem;
}
.coach-tip button {
  flex: 0 0 44px;
  border-color: transparent;
  padding: 0;
  background: transparent;
  font-size: 1.18rem;
}
.first-creation {
  position: absolute;
  bottom: 12px;
  left: 12px;
  width: min(302px,calc(100% - var(--view-controls-space)));
  max-height: calc(100% - 65px);
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-float);
  color: var(--ink);
  font-size: .875rem;
  touch-action: pan-y;
}
.first-creation summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-size: .8125rem;
  list-style: none;
}
.first-creation summary::-webkit-details-marker { display: none; }
.first-creation summary:focus-visible { outline-offset: -3px; }
.first-creation details[open] .chevron { transform: rotate(225deg); }
#creation-count {
  margin-inline-start: auto;
  color: var(--muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.creation-meter { display: flex; gap: 3px; }
.creation-meter i { width: 10px; height: 4px; border-radius: 4px; background: var(--line); }
.creation-meter i[data-complete] { background: var(--clay); }
#creation-next:not(:empty) { padding: 0 10px 9px; overflow-wrap: anywhere; }
#creation-next:empty { display: none; }
.creation-steps { display: grid; gap: 7px; margin: 0; padding: 0 10px 8px; list-style: none; }
.creation-steps li { display: flex; align-items: center; gap: 8px; }
.creation-steps li[aria-current] { font-weight: 650; }
.creation-steps li > span {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--clay-wash);
  font-size: .75rem;
}
#creation-hide, #creation-replay { margin: 0 10px 8px; }
#creation-replay { background: var(--primary); border-color: var(--primary); color: var(--surface); }
#creation-replay:hover:not(:disabled) { background: var(--primary-hover); }
.studio-help-actions { display: grid; gap: 8px; padding: 12px 16px; }
.studio-help-actions button { text-align: start; }
#creation-target {
  position: absolute;
  width: 36px;
  height: 36px;
  transform: translate(-50%,-50%);
  border: 2px solid #fff1b6;
  border-radius: 50%;
  box-shadow: 0 0 0 2px #514052c9;
  pointer-events: none;
}
@media (max-width: 360px) {
  .first-creation { left: 8px; width: calc(100% - 86px); }
  .first-creation summary { gap: 5px; padding-inline: 8px; }
}

#room-remix { margin-top: 8px; width: 100%; }
#clear-room {
  position: absolute;
  top: 12px;
  right: 12px;
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-control);
}
#clear-room:hover:not(:disabled) { color: var(--clay); background: var(--clay-wash); }
#peer-presence { padding: 1px 6px; border-radius: 7px; }
.peer-tile[data-drawing] #peer-presence { background: #f6df9b; color: #5d371a; }

#replay-dialog {
  width: min(680px,calc(100% - 24px));
  max-height: calc(100dvh - max(24px,env(safe-area-inset-top) + env(safe-area-inset-bottom)));
}
#replay-dialog[open] { display: flex; flex-direction: column; overflow: hidden; }
#replay-dialog > :is(.room-dialog-head,.replay-session,.replay-footer) { flex: none; }
.replay-session {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 18px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
#replay-session-label { font-weight: 650; overflow-wrap: anywhere; }
#replay-session-detail, #replay-library-note, #replay-session-list small, #replay-post-limit { color: var(--muted); font-size: .875rem; }
.replay-library { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 12px 14px; }
#replay-session-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
#replay-session-list button {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  text-align: start;
  white-space: normal;
}
#replay-session-list button[aria-current=true] { background: var(--primary-wash); border-color: var(--primary-edge); }
#replay-session-list button span { display: grid; gap: 2px; }
#replay-session-list small { font-weight: 450; }
#replay-session-list .session-duration { flex: none; font-variant-numeric: tabular-nums; }
#replay-library-note:not(:empty) { margin-top: 8px; }
.replay-body { padding: 14px 18px; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.replay-frame { position: relative; }
#replay-view {
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius-card);
  background: var(--paper);
  cursor: grab;
  touch-action: none;
}
#replay-view:active { cursor: grabbing; }
#replay-view canvas { display: block; width: 100%; height: 100%; }
.replay-zoom { position: absolute; bottom: 8px; right: 8px; }
.replay-zoom button { min-width: 44px; }
#replay-camera-hint, #replay-note, #replay-status { font-size: .875rem; color: var(--muted); }
#replay-camera-hint { margin-block: 6px 10px; }
#replay-play { background: var(--primary-wash); border-color: transparent; color: var(--primary); }
#replay-play:hover:not(:disabled) { border-color: var(--primary-edge); }
.replay-transport, .replay-trim-controls {
  display: grid;
  grid-template-columns: auto minmax(0,1fr) auto;
  gap: 8px;
  align-items: center;
}
.replay-transport input, .replay-trim-controls input { width: 100%; margin: 0; min-height: 44px; accent-color: var(--primary); }
.replay-transport output, .replay-speed output, .replay-trim-controls output { font-size: .875rem; font-variant-numeric: tabular-nums; }
.replay-speed { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 8px; }
.replay-speed label { font-size: .875rem; font-weight: 640; }
.replay-speed-select { position: relative; }
#replay-speed {
  appearance: none;
  min-height: 44px;
  min-width: 78px;
  padding: 6px 25px 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.replay-speed-select .chevron { position: absolute; top: 50%; right: 9px; pointer-events: none; }
#replay-length { margin-inline-start: auto; color: var(--muted); }
#replay-trim { margin-top: 8px; }
#replay-trim summary { width: fit-content; }
.replay-trim-controls { margin-top: 6px; }
.replay-trim-controls button { grid-column: 1 / -1; justify-self: start; }
#replay-note { margin-top: 8px; grid-column: 1 / -1; }
.replay-footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  background: var(--paper);
}
#replay-status:empty, .replay-actions:not(:has(> :not([hidden]))) { display: none; }
#replay-post-limit { flex-basis: 100%; }
#replay-progress { width: 100%; accent-color: var(--primary); }
.replay-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.replay-public { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.replay-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--primary);
  font-size: .875rem;
  font-weight: 640;
  text-decoration: none;
}
.replay-link:hover { background: var(--hover); }
.replay-public { width: 100%; justify-content: space-between; }
:is(#replay-post-form,#replay-signin) { display: grid; gap: 5px; width: 100%; }
:is(#replay-post-form,#replay-signin) p, #replay-post-form label { font-size: .875rem; }
#replay-post-form label { font-weight: 640; }
#replay-post-form label span { font-weight: 450; }
#replay-post-form input {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  font-size: 1rem;
}
:is(#replay-post-form,#replay-signin) .replay-actions { margin-top: 4px; }
.replay-footer:has(:is(#replay-post-form,#replay-signin):not([hidden])) > .replay-actions { display: none; }
@media (pointer: coarse) and (max-width: 900px) {
  #replay-dialog {
    inset: var(--replay-viewport-top,0px) 0 auto;
    width: 100%;
    max-width: 100%;
    height: var(--replay-viewport-height,100dvh);
    max-height: var(--replay-viewport-height,100dvh);
    margin: 0;
    border: 0;
    border-radius: 0;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  #replay-dialog .replay-footer { margin-top: auto; }
  #replay-dialog :is(.replay-body,.replay-library) { flex: 1; }
}
@media (max-width: 400px) {
  .replay-transport output { grid-column: 1 / -1; justify-self: end; }
  .replay-transport { grid-template-columns: auto minmax(0,1fr); row-gap: 0; }
}
@media (max-height: 550px) and (orientation: landscape) {
  .replay-body { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); align-items: start; gap: 12px; }
  .replay-transport output { grid-column: 1 / -1; justify-self: start; }
  .replay-footer:has(:is(#replay-post-form,#replay-signin):not([hidden])) { max-height: 60dvh; overflow: auto; }
}
