:root {
  color-scheme: light;
  --page: #f7f5ed;
  --paper: #fffdf7;
  --ink: #26382c;
  --muted: #536356;
  --stroke: #dcded1;
  --green: #3a5743;
  --hover: #ebeee1;
  --stage: #819073;
  --shadow: 0 20px 58px #2d392919, 0 3px 10px #2d39290b;
}

:root[data-theme="night"] {
  color-scheme: dark;
  --page: #18201d;
  --paper: #242e28;
  --ink: #eeefe0;
  --muted: #bdc7b9;
  --stroke: #405048;
  --green: #bed0ae;
  --hover: #34443a;
  --stage: #46564f;
  --shadow: 0 20px 58px #070e0a4a;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 0;
  color: var(--ink);
  background: var(--page);
  font: 1rem/1.5 "Geist", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; }
button { touch-action: manipulation; }
button, a, input { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }
a { color: inherit; text-underline-offset: .22em; }

.page {
  width: min(100% - 64px, 1040px);
  margin-inline: auto;
  padding: max(22px, env(safe-area-inset-top)) 0 max(22px, env(safe-area-inset-bottom));
}

.masthead, .toolbar, .page-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -.025em; }
.brand-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--green); color: var(--paper); }
canvas[data-icon] { width: 18px; height: 18px; flex: 0 0 auto; }
.brand-icon canvas { width: 22px; height: 22px; }

.control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font-size: .875rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.control:hover, .control[aria-pressed="true"], .control[aria-expanded="true"] { background: var(--hover); }
.theme { border-radius: 999px; padding-inline: 14px; }

.intro { max-width: 620px; margin: 22px auto 23px; text-align: center; }
h1 { margin: 0; font-family: "Noto Serif CJK SC", "Songti SC", SimSun, serif; font-size: clamp(2.6rem, 5.5vw, 4rem); font-weight: 900; line-height: 1.18; letter-spacing: -.06em; }
.intro p { margin: 9px 0 0; color: var(--muted); }
.touch-gesture { display: none; }

.frame { position: relative; padding: 9px; background: var(--paper); border: 1px solid var(--stroke); border-radius: 24px; box-shadow: var(--shadow); }
.stage {
  position: relative;
  display: grid;
  place-items: center;
  isolation: isolate;
  width: 100%;
  height: clamp(340px, 54vh, 620px);
  border-radius: 17px;
  overflow: hidden;
  background: center 53% / cover no-repeat var(--stage) url("./assets/couch.webp");
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.stage::after { content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none; box-shadow: inset 0 0 68px #21241424; transition: background .24s ease; }
[data-theme="night"] .stage::after { background: #14213791; mix-blend-mode: multiply; }
.stage[data-contact] { cursor: none; }
.stage:focus-visible { outline-offset: -4px; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; }
.stage-hint, .retry { position: relative; z-index: 1; }
.stage-hint { color: #25372b; background: #fffdf0ed; padding: 7px 12px; border-radius: 999px; }
.retry { margin-top: 10px; }
.toolbar { position: relative; padding: 12px 5px 3px 9px; }
.dog-picker, .coats, .tools { display: flex; align-items: center; }
.dog-picker { gap: 13px; min-width: 0; }
.picker-label { white-space: nowrap; font-size: .875rem; font-weight: 650; color: var(--muted); }
.coats { gap: 4px; flex-wrap: wrap; }
.coat {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 49px;
  gap: 2px;
  padding: 1px 3px 2px;
  border: 0;
  background: none;
  color: var(--muted);
  border-radius: 9px;
  font-size: .75rem;
  line-height: 1.2;
  cursor: pointer;
}
.coat:hover { background: var(--hover); }
.coat[aria-pressed="true"] { color: var(--ink); font-weight: 750; }
.swatch { width: 27px; height: 27px; border-radius: 50%; border: 1px solid #272b2633; background: var(--swatch); }
.coat[aria-pressed="true"] .swatch { box-shadow: 0 0 0 2px var(--paper), 0 0 0 3px var(--green); }
.tools { gap: 7px; flex-shrink: 0; }
.fit-panel {
  position: absolute;
  z-index: 3;
  right: 5px;
  bottom: calc(100% + 8px);
  width: min(248px, calc(100vw - 46px));
  padding: 14px 16px;
  border: 1px solid var(--stroke);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.fit-panel label { display: flex; align-items: center; justify-content: space-between; font-size: .875rem; }
.fit-panel output { color: var(--muted); font-variant-numeric: tabular-nums; }
.fit-panel input { display: block; width: 100%; margin: 2px 0 9px; height: 28px; accent-color: var(--green); }
.fit-panel input:last-child { margin-bottom: 0; }

.page-footer { margin: 15px 2px 0; font-size: .8125rem; color: var(--muted); }
.page-footer p { display: flex; align-items: center; gap: 7px; margin: 0; }
kbd { min-width: 1.6em; padding: 1px 5px; border-radius: 5px; border: 1px solid var(--stroke); background: var(--paper); text-align: center; font: inherit; }
.separator { border-left: 1px solid var(--stroke); height: 13px; margin-inline: 4px; }

.viewer:fullscreen, .viewer.is-expanded {
  display: grid;
  place-items: stretch;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: var(--page);
}
.viewer.is-expanded { position: fixed; z-index: 10; inset: 0; height: 100dvh; }
body.expanded { overflow: hidden; }
.viewer:fullscreen .frame, .viewer.is-expanded .frame { display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.viewer:fullscreen .stage, .viewer.is-expanded .stage { height: 100%; min-height: 0; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

@media (max-width: 760px) {
  .page { width: calc(100% - 36px); }
  .toolbar { padding-inline: 3px; gap: 7px; }
  .dog-picker { gap: 8px; }
  .picker-label { display: none; }
}

@media (max-width: 560px) {
  .page { width: calc(100% - 24px); padding-top: max(12px, env(safe-area-inset-top)); }
  .intro { margin: 19px 0 16px; }
  .intro p { font-size: .9375rem; }
  .frame { padding: 5px; border-radius: 17px; }
  .stage { height: clamp(270px, 47svh, 470px); border-radius: 12px; }
  .toolbar { flex-direction: column; align-items: stretch; padding-top: 8px; gap: 7px; }
  .coats { justify-content: space-evenly; gap: 0; width: 100%; }
  .dog-picker > .coats { flex: 1; }
  .coat { padding-inline: 0; min-width: 44px; }
  .tools { justify-content: center; gap: 6px; }
  .tools .control { flex: 1; }
  .fit-panel { bottom: 54px; left: 3px; right: auto; }
}

@media (pointer: coarse) {
  .desktop-gesture { display: none; }
  .touch-gesture { display: inline; }
  #shortcuts { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

@media (max-height: 480px) and (orientation: landscape) {
  .intro { margin-block: 10px; }
  .stage { height: 65svh; min-height: 190px; }
}

@media (prefers-reduced-motion: reduce) {
  .stage::after { transition: none; }
}
