.studio-game {
  --studio-navy: #092c44;
  --studio-midnight: #103951;
  --studio-amber: #ffe091;
  --edge: clamp(.65rem, 2vw, 1.4rem);
  --top: max(var(--edge), env(safe-area-inset-top));
  --bottom: max(var(--edge), env(safe-area-inset-bottom));
  --left: max(var(--edge), env(safe-area-inset-left));
  --right: max(var(--edge), env(safe-area-inset-right));
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: #d9eaf0;
}

:fullscreen .studio-game { height: 100%; }
:fullscreen::backdrop { background: #d9eaf0; }

.studio-layout,
.scene-panel,
.scene-surface {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-width: 0;
  margin: 0;
  padding: 0;
}

.studio-top {
  position: absolute;
  z-index: 6;
  inset: var(--top) var(--right) auto var(--left);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .55rem;
  pointer-events: none;
}

.studio-brand {
  display: flex;
  align-items: center;
  gap: .8rem;
  min-width: 0;
}

.studio-game .brand {
  flex: 0 0 auto;
  width: clamp(148px, 20vw, 246px);
  min-height: 44px;
  padding: .25rem .47rem;
  border: 1px solid #89aebe50;
  border-radius: .76rem;
  background: #fffdf5ed;
  box-shadow: 0 2px 10px #0c344014;
}

.studio-brand h1 {
  color: var(--studio-navy);
  text-shadow: 0 1px 2px #eefaff;
  font-size: clamp(1rem, 2.25vw, 1.87rem);
  font-weight: 930;
  letter-spacing: -.045em;
  line-height: 1.08;
}

.view-tools {
  flex: 0 0 auto;
  display: flex;
  gap: .36rem;
  pointer-events: auto;
}

.view-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .42rem;
  min-width: 44px;
  min-height: 44px;
  padding: .35rem .59rem;
  border: 1px solid #7e9eaf70;
  border-radius: .7rem;
  color: var(--studio-midnight);
  background: #f7fbf9ed;
  box-shadow: 0 2px 10px #0c344014;
  font-size: .75rem;
  font-weight: 820;
  line-height: 1.2;
}

.view-button:hover { background: #fff; border-color: #577788; }
.view-button[aria-pressed="true"] { background: #ffeec6; border-color: #bd9a51; }

.view-icon {
  position: relative;
  display: block;
  flex: 0 0 auto;
  width: .95rem;
  height: .95rem;
}

.sound-icon::before {
  content: "";
  position: absolute;
  inset: 8% 28% 8% 0;
  background: currentColor;
  clip-path: polygon(0 34%, 31% 34%, 76% 4%, 76% 96%, 31% 66%, 0 66%);
}

.sound-icon::after {
  content: "";
  position: absolute;
  inset: 11% 6% 11% 44%;
  border: 1.5px solid transparent;
  border-right-color: currentColor;
  border-radius: 50%;
}

.view-button[aria-pressed="true"] .sound-icon::after {
  inset: 44% -4% auto 5%;
  height: 2px;
  transform: rotate(-47deg);
  border: 0;
  border-radius: 2px;
  background: #9d2336;
}

.fullscreen-icon {
  background:
    linear-gradient(currentColor, currentColor) left top / 5px 1.5px,
    linear-gradient(currentColor, currentColor) left top / 1.5px 5px,
    linear-gradient(currentColor, currentColor) right top / 5px 1.5px,
    linear-gradient(currentColor, currentColor) right top / 1.5px 5px,
    linear-gradient(currentColor, currentColor) left bottom / 5px 1.5px,
    linear-gradient(currentColor, currentColor) left bottom / 1.5px 5px,
    linear-gradient(currentColor, currentColor) right bottom / 5px 1.5px,
    linear-gradient(currentColor, currentColor) right bottom / 1.5px 5px;
  background-repeat: no-repeat;
}

.scene-panel { overflow: hidden; }

#scene-title:focus-visible + .scene-surface::after {
  content: "";
  position: absolute;
  z-index: 6;
  inset: 2px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--navy-dark);
  pointer-events: none;
}

.scene-surface {
  isolation: isolate;
  overflow: hidden;
  background: #d9eaf0;
  user-select: none;
}

#scene-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.scene-error {
  position: absolute;
  z-index: 5;
  top: 50%;
  left: 50%;
  width: min(25rem, calc(100% - 1rem));
  translate: -50% -50%;
  padding: .9rem 1rem;
  border: 1px solid #b1cbd5;
  border-radius: 12px;
  color: var(--navy-dark);
  background: #f8fcff;
  box-shadow: 0 3px 15px #17394a19;
  font-size: .9rem;
  text-align: center;
}

.scene-object {
  position: absolute;
  z-index: 1;
  top: var(--y, 50%);
  left: var(--x, 50%);
  display: grid;
  place-items: center;
  width: max(44px, var(--w, 12%));
  height: max(44px, var(--h, 12%));
  translate: -50% -50%;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 13px;
  color: #183c51;
  background: transparent;
  touch-action: manipulation;
  transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
}

.scene-object::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid transparent;
  border-radius: 11px;
  pointer-events: none;
}

.scene-object:hover:not(:disabled, [aria-disabled="true"]) {
  z-index: 2;
  border-color: #fff6c4;
  background: #ffedba30;
  box-shadow: 0 0 0 2px #81571b7d;
}

.scene-object:focus-visible {
  z-index: 3;
  border-color: transparent;
  outline: 3px solid #fff;
  outline-offset: 2px;
  box-shadow: 0 0 0 8px var(--navy-dark);
}

.scene-object:is([aria-pressed="true"], [data-selected="true"])::after {
  border: 2px solid #ffe08d;
  box-shadow: 0 0 0 1px #624a1685;
}

.scene-object[data-drop-ready="true"] {
  border-style: dashed;
  border-color: #fff0aa;
  background: #ffe88a37;
  box-shadow: 0 0 0 2px #62511b60;
}

.scene-object[data-draggable="true"] { cursor: grab; touch-action: none; }
.scene-object[data-draggable="true"]:active { cursor: grabbing; }
.scene-object:disabled { pointer-events: none; }

.scene-object .object-label {
  position: absolute;
  z-index: 1;
  top: var(--label-y, auto);
  bottom: var(--label-bottom, -.25rem);
  left: var(--label-x, 50%);
  translate: -50% 60%;
  padding: .26rem .45rem;
  border: 1px solid #153b5590;
  border-radius: 5px;
  color: #fff;
  background: #10364dea;
  box-shadow: 0 2px 6px #15384d29;
  font-size: clamp(.7rem, 1.32vw, .83rem);
  font-weight: 800;
  line-height: 1.16;
  white-space: nowrap;
  pointer-events: auto;
}

.scene-object[aria-disabled="true"] .object-label { pointer-events: none; }

.scene-object[data-object="tap"] {
  --label-y: -.6rem;
  --label-bottom: auto;
}

.scene-object:is(:focus-visible, [aria-pressed="true"], [data-selected="true"], [data-drop-ready="true"]) .object-label {
  border-color: #e2b958;
  color: #432f11;
  background: #ffedb4;
}

.scene-object:is([data-object^="plate-"], [data-object="dish"], [data-object="rinse"]) {
  border-radius: 50%;
  touch-action: none;
}

.scene-object:is([data-object^="plate-"], [data-object="dish"], [data-object="rinse"])::after { border-radius: 50%; }

.scene-object[data-object^="plate-"] .object-label {
  min-width: 1.25rem;
  padding: .19rem .36rem;
  border-radius: 6px;
  font-size: clamp(.65rem, 1.15vw, .75rem);
}

.scene-object[data-object="dish"] .object-label { display: none; }
.scene-object[data-object="dish"]:focus-visible .object-label { display: block; }

.scene-object[data-object="rinse"] {
  border-style: dashed;
  border-color: #fff7ca;
  box-shadow: 0 0 0 2px #4c63874d;
}

.scene-object[data-object="rinse"]:is(:disabled, [aria-disabled="true"]) { visibility: hidden; }

.scene-object[data-object="replay"] .object-label {
  border-color: #d9ad55;
  color: #432f11;
  background: #ffedb4;
}

#work-zone {
  position: absolute;
  z-index: 1;
  top: var(--y, 71%);
  left: var(--x, 42%);
  width: var(--w, 24%);
  height: var(--h, 19%);
  translate: -50% -50%;
  border: 2px dashed #fce5a5;
  border-radius: 50%;
  background: #ffe9a333;
  box-shadow: 0 0 0 2px #6c572953;
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s ease;
}

.scene-surface:is([data-drag-object^="plate-"], [data-drag-object="dish"][data-under-tap="true"]) #work-zone { opacity: 1; }

.studio-hud {
  position: absolute;
  z-index: 4;
  top: calc(var(--top) + 3.3rem);
  right: var(--right);
  display: grid;
  gap: .42rem;
  width: min(16.15rem, calc(100% - var(--left) - var(--right)));
  padding: .56rem .63rem;
  border: 1px solid #244b60;
  border-radius: .76rem;
  min-width: 0;
  color: #f5fbfd;
  background: linear-gradient(144deg, #123d57f3 0%, #092c44fa 80%);
  box-shadow: 0 4px 12px #17394a2b;
  pointer-events: none;
}

.studio-hud > h2:not(.sr-only) {
  font-size: .82rem;
  font-weight: 780;
}

.hud-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .36rem;
  margin: 0;
}

.hud-metrics > div {
  display: grid;
  align-content: center;
  grid-template-rows: auto auto;
  min-width: 0;
  gap: .08rem;
  padding: .31rem .44rem;
  border: 1px solid #4f7c8b80;
  border-radius: .42rem;
  background: #eaf9ff0d;
}

.hud-metrics dt {
  color: #c9e1ec;
  font-size: .69rem;
  font-weight: 720;
  line-height: 1.14;
}

.hud-metrics dd {
  margin: 0;
  color: #fff7d9;
  font-size: clamp(.96rem, 1.65vw, 1.27rem);
  font-weight: 850;
  line-height: 1.18;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.hud-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: .12rem .4rem;
  padding-inline: .08rem;
  color: #e0f0f7;
  font-size: .72rem;
  font-weight: 760;
  line-height: 1.24;
}

.hud-progress {
  white-space: nowrap;
}

.tap-indicator {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  white-space: nowrap;
}

.tap-indicator::before {
  content: "";
  width: .45rem;
  height: .45rem;
  border-radius: 50%;
  background: #9eb6c4;
  box-shadow: 0 0 0 2px #a9cdd627;
}

.tap-indicator[data-running="true"]::before {
  background: #a2e9ff;
  box-shadow: 0 0 0 2px #79c7e569;
}

.studio-guide {
  position: absolute;
  z-index: 4;
  bottom: var(--bottom);
  left: var(--left);
  width: min(23.2rem, calc(100% - var(--left) - var(--right)));
  padding: .65rem .84rem .67rem;
  border: 1px solid #37556a;
  border-inline-start: 3px solid #e9bc56;
  border-radius: .78rem;
  color: #eef6f9;
  background: #092c44f5;
  box-shadow: 0 4px 12px #17394a2b;
  pointer-events: none;
}

.hud-instruction :is(h2, h3) {
  color: var(--studio-amber);
  font-size: clamp(.93rem, 1.5vw, 1.13rem);
  font-weight: 860;
  line-height: 1.2;
}

.hud-instruction p, .studio-guide #comparison {
  margin-block-start: .23rem;
  color: #e3f0f5;
  font-size: clamp(.77rem, 1.2vw, .87rem);
  line-height: 1.34;
}

.studio-guide #comparison { color: #ffebba; }

.audio-credits {
  position: absolute;
  z-index: 4;
  right: var(--right);
  bottom: var(--bottom);
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: .27rem .56rem;
  border-radius: .5rem;
  color: #1d4256;
  background: #f4fbf7ed;
  font-size: .67rem;
  font-weight: 740;
  line-height: 1.2;
  text-underline-offset: 2px;
}

.audio-credits:hover { background: #fff; }

#rinse-meter {
  display: block;
  width: 100%;
  height: .43rem;
  margin-block-start: .42rem;
  accent-color: #efbc55;
}

@media (max-width: 720px) {
  .studio-brand { display: grid; gap: .29rem; }
  .studio-brand h1 { font-size: clamp(1.03rem, 3vw, 1.38rem); }
  .studio-hud { top: calc(var(--top) + 4.8rem); }
  .studio-guide { bottom: calc(var(--bottom) + 2.05rem); }
}

@media (max-width: 520px) {
  .view-button :is(#sound-label, #fullscreen-label) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .studio-hud { left: var(--left); width: auto; }
  .studio-guide { right: var(--right); width: auto; }
  .audio-credits { min-height: 26px; }
}

@media (max-height: 435px) and (orientation: landscape) {
  .studio-game { --edge: .44rem; }
  .studio-brand { display: flex; }
  .studio-hud { top: calc(var(--top) + 2.95rem); left: auto; width: min(12.9rem, 31vw); }
  .studio-guide { bottom: var(--bottom); width: min(19rem, 43vw); padding: .42rem .58rem; }
  .hud-metrics > div { padding: .24rem .3rem; }
  .hud-metrics dt, .hud-status { font-size: .62rem; }
}

@media (max-width: 560px) {
  .scene-object .object-label { padding-inline: .31rem; }
  .scene-object .object-label[data-short] { font-size: 0; }
  .scene-object .object-label[data-short]::before {
    content: attr(data-short);
    font-size: .64rem;
    line-height: 1.1;
  }
}
