:root {
  color-scheme: dark;
  --cream: #fff1d7;
  --gold: #ffdfa2;
  --serif: Georgia, "Times New Roman", serif;
  font-family: "Avenir Next", Avenir, "Trebuchet MS", Arial, sans-serif;
  color: var(--cream);
  background: #241911;
}
* { box-sizing: border-box }
body { margin: 0; min-height: 100svh; display: grid; place-items: center }
.stage {
  /* Keep the strip of carpet in front of the gifts visible on wide screens. */
  --scene-width: min(100vw, 192svh);
  --scene-height: min(100svh, 66.666667vw);
  --ui-inset: clamp(12px, calc(var(--scene-height) * .03), 24px);
  --scene-margin: calc((100% - var(--scene-width)) / 2);
  position: relative; isolation: isolate; overflow: hidden;
  width: 100%; height: var(--scene-height);
}
.scene {
  position: relative; overflow: hidden; container-type: inline-size;
  width: var(--scene-width); height: 100%; margin-inline: auto;
  background: #35231c;
}
.stage.loading { visibility: hidden }
.scene::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(rgba(0, 0, 0, .1), rgba(0, 0, 0, .1)), url("assets/sofa.png"), url("assets/room-backdrop.png");
  background-position: center, center calc(50% + var(--sofa-offset, .625cqw)), center;
  background-size: 100% 100%, 100% auto, 100% auto; background-repeat: no-repeat;
}
#game { position: relative; display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; -webkit-tap-highlight-color: transparent }
#game:active { cursor: grabbing }
.scene::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to bottom, #190f0dcc, #25170f00 20%),
    linear-gradient(to top, #21120cdb, #29170e00 17%);
}
header, footer {
  position: absolute; z-index: 1;
  left: max(calc(var(--scene-margin) + var(--ui-inset)), env(safe-area-inset-left));
  right: max(calc(var(--scene-margin) + var(--ui-inset)), env(safe-area-inset-right));
  display: flex; align-items: center; justify-content: space-between;
  pointer-events: none; gap: 16px; text-shadow: 0 2px 4px #1e100c;
}
header { top: max(var(--ui-inset), env(safe-area-inset-top)) }
footer { bottom: max(var(--ui-inset), env(safe-area-inset-bottom)) }
h1, h2, p { margin: 0 }
.stat, #paws, nav, button { display: flex; align-items: center }
.hud {
  flex: 1; display: grid; align-items: center;
  grid-template-columns: minmax(0, 1fr) 1px minmax(0, 1fr); column-gap: 12px; white-space: nowrap;
}
.hud > :first-child { justify-self: end }
.score-stat { justify-self: start }
.hud-divider { width: 1px; height: 22px; background: var(--gold); opacity: .65 }
.stat { gap: 7px; line-height: 1.1 }
.label { display: block; color: #ffe4b8; font-size: 13px; font-weight: 650; margin-bottom: 3px }
.token { width: 30px; height: 30px }
.stat strong { font-size: 24px; font-variant-numeric: tabular-nums }
.score-stat { gap: 4px }
/* Reserve room for the full 40 / 40 after the icon. */
.score-readout { display: flex; align-items: baseline; gap: 4px; min-inline-size: 2.75em; font-size: 24px }
.stat small { font-size: 14px }
#paws { height: 30px; gap: 7px }
#paws canvas { width: 26px; height: 26px }
nav { gap: 6px }
button {
  appearance: none; border: 1px solid #ebcc9675; border-radius: 50%;
  background: #35221bbd; color: var(--cream); cursor: pointer; pointer-events: auto;
  justify-content: center; gap: 6px; font-family: inherit; font-size: 14px; font-weight: 650; line-height: 1.2;
}
button:hover { filter: brightness(1.22) }
button:active { transform: translateY(1px) }
button:focus-visible { outline: 3px solid #fff2b6; outline-offset: -4px }
#game:focus { outline: none }
.stage:has(#game:focus-visible) #state { text-decoration: underline; text-underline-offset: .2em }
nav button { width: 44px; height: 44px }
button canvas { width: 21px; height: 21px }
#state { color: var(--gold); font-size: clamp(13px, 2vw, 16px) }
#play, #again, #reload {
  background: #f5d6a3; color: #472d26; border-radius: 2em; min-height: 44px;
  padding: 0 17px; font-size: 14px; font-weight: 700; flex: none;
}
#back, #restart {
  width: 44px; height: 44px; min-height: 0; padding: 0; border-radius: 50%;
  color: #fff8ea;
  background: linear-gradient(145deg, #fff3df40, #a86e5126 50%, #3a282a59);
  border: 1px solid #ebcc9675;
  box-shadow: inset 0 1px 0 #ffffffa8, inset 0 -1px 1px #fff0d52e, 0 4px 14px #1d100e66;
  backdrop-filter: blur(2px) saturate(1.45);
  -webkit-backdrop-filter: blur(2px) saturate(1.45);
  text-shadow: 0 1px 4px #24130e;
}
.card-overlay { position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; background: #1b1315a6 }
header[hidden], footer[hidden], #preview[hidden], #overlay[hidden] { display: none }
#play:focus-visible, #again:focus-visible, #reload:focus-visible { outline-color: #472d26 }
#resultBack { margin: 6px auto 0; min-height: 40px; background: transparent; border: 0; border-radius: 6px }
.game-card {
  width: min(340px, calc(100% - 32px)); text-align: center; padding: 20px 28px 24px;
  border-radius: 16px;
  color: #fff8ea; background: linear-gradient(145deg, #ffffff40, #ffffff1a 50%, #ffffff0d);
  border: 1px solid #ebcc9675;
  box-shadow: inset 0 1px 0 #ffffffa8, inset 0 -1px 1px #fff0d52e, 0 8px 32px #170f0f80;
  backdrop-filter: blur(2px) saturate(1.45); -webkit-backdrop-filter: blur(2px) saturate(1.45);
  text-shadow: 0 1px 4px #24130e;
}
.result canvas { width: 76px; height: 76px }
.result:focus { outline: none }
.game-card :is(h1, h2) { font: italic bold 30px var(--serif); margin: 5px 0 }
.game-card p { margin-bottom: 16px }
#play, #again, #reload { margin: auto; border: 0 }
body.expanded { position: fixed; inset: 0 }
@media (max-height: 350px) {
  .result #resultBack { min-height: 32px; margin-top: 0 }
}
@media (max-width: 530px) and (orientation: portrait) {
  .scene::after { background: linear-gradient(to bottom, #190f0dd4, transparent 27%), linear-gradient(to top, #21120ce8, transparent 21%) }
}
@media (orientation: landscape) and (max-height: 500px) {
  .game-card { padding: 10px 24px 14px }
  .result canvas { width: 54px; height: 54px }
  .game-card :is(h1, h2) { font-size: 24px; margin: 0 }
  .game-card p { margin-bottom: 8px }
}

.viewport-notice { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 32px; background: #291b18; color: var(--cream); text-align: center; font-size: 22px; font-weight: 700 }
.viewport-notice[hidden] { display: none }
.loading-notice { position: fixed; inset: 0; display: grid; place-items: center; padding: 32px; background: #291b18; color: var(--cream); text-align: center; font-size: 18px }
.loading-notice[hidden] { display: none }
