:root {
  color-scheme: light;
  --ink: #2d3640;
  --gold: #d4b15e;
  --paper: #fffdf8;
  --desk: #a87443;
  --ui-top: calc(12px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px)));
  --ui-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --ui-left: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
  --ui-right: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

html { touch-action: manipulation; }

html.is-signing,
html.is-signing body {
  overflow: hidden;
  overscroll-behavior: none;
}

.is-signing .queue { touch-action: none; }

body {
  height: var(--visible-height, 100%);
  min-height: 100%;
  min-height: var(--visible-height, 100vh);
  min-height: 100dvh;
  background:
    radial-gradient(circle at 50% 0, #f7f4ef, #d9d3c8 70%);
  color: var(--ink);
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

button, input { font: inherit; color: inherit; }

.app {
  width: 100%;
  min-width: 0;
  max-width: 480px;
  min-height: 100%;
  min-height: var(--visible-height, 100vh);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  height: var(--visible-height, 100vh);
  max-height: 860px;
  height: min(860px, 100dvh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #efeae2;
  box-shadow: 0 18px 50px rgba(60, 40, 20, 0.16);
  user-select: none;
  -webkit-user-select: none;
}

.hud {
  position: absolute;
  z-index: 6;
  top: var(--ui-top);
  left: calc(14px + var(--ui-left));
  right: calc(14px + var(--ui-right));
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.count-box {
  pointer-events: auto;
  display: flex;
  align-items: center;
}

.clock, .count {
  pointer-events: auto;
  display: flex;
  align-items: baseline;
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--ink);
  font-weight: 700;
  font-size: 32px;
  letter-spacing: -0.04em;
  line-height: 1;
}

.clock svg {
  width: 22px;
  height: 22px;
  align-self: center;
  margin-right: 4px;
}

.clock small, .count small {
  font-size: 13px;
  font-weight: 600;
  margin-left: 2px;
  letter-spacing: 0;
}

.clock.urgent { color: #d2453a; }

.time-hint {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 6px;
  color: rgba(60, 52, 44, 0.6);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  white-space: nowrap;
}

.clock:disabled .time-hint { display: none; }

.time-box {
  position: relative;
  pointer-events: auto;
  display: flex;
  align-items: center;
}

.time-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 8;
  width: 196px;
  padding: 12px;
  background: #fffdf8;
  border-radius: 16px;
  box-shadow: 0 10px 24px rgba(60, 30, 10, 0.16);
}

.time-panel[hidden],
.end-now[hidden],
.pick-line[hidden] { display: none; }

.time-panel > * + * { margin-top: 8px; }

.time-field {
  display: block;
  font-size: 13px;
  color: #3a342c;
}

.time-field input {
  display: block;
  width: 100%;
  height: 36px;
  margin-top: 4px;
  border: 1px solid rgba(58, 52, 44, 0.2);
  border-radius: 10px;
  padding: 0 8px;
  background: #fff;
}

.time-apply,
.time-free,
.end-now {
  width: 100%;
  height: 36px;
  border-radius: 999px;
  cursor: pointer;
}

.time-apply {
  border: 0;
  background: #2f343a;
  color: #fff;
}

.time-free,
.end-now {
  border: 1px solid rgba(47, 52, 58, 0.35);
  background: #fffdf8;
  color: #2f343a;
}

.end-now {
  position: absolute;
  right: 14px;
  bottom: calc(100% + 12px);
  z-index: 7;
  width: auto;
  height: 44px;
  margin: 0;
  padding: 0 18px;
  font-size: 17px;
  font-weight: 650;
}

.queue {
  position: relative;
  flex: 0 0 auto;
  min-width: 0;
  height: 240px;
  height: clamp(210px, 34vh, 280px);
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: calc(var(--ui-top) + 40px) 12px 16px;
  -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(#f7f4ef, #e7e1d7 80%, #d9d0c4);
  overflow-x: auto;
  overflow-y: hidden;
}

.queue:not(.is-play) .fan:first-child { margin-left: auto; }
.queue:not(.is-play) .fan:last-child { margin-right: auto; }
.queue:not(.is-play) { cursor: grab; scrollbar-width: none; }
.queue:not(.is-play)::-webkit-scrollbar { display: none; }
.queue:not(.is-play).is-dragging { cursor: grabbing; scroll-behavior: auto; }
.queue:not(.is-play) .avatar { pointer-events: none; }

.queue.is-play {
  --front: 112px;
  display: block;
  height: 280px;
  height: clamp(268px, 38vh, 300px);
  padding: calc(var(--ui-top) + 44px) 0 0;
  overflow: hidden;
}

.queue::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 18px;
  background: linear-gradient(transparent, rgba(80, 55, 30, 0.08));
}

.fan {
  position: relative;
  width: 72px;
  flex: 0 0 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.queue.is-play .fan {
  position: absolute;
  left: var(--x);
  bottom: var(--y);
  width: var(--size);
  flex: none;
  z-index: var(--z);
  transition: left 0.38s ease, bottom 0.38s ease, width 0.38s ease;
}

.queue.is-play .fan[data-slot="0"] { --size: var(--front); --x: calc(50% - var(--front) / 2); --y: 0px; --z: 5; }
.queue.is-play .fan[data-slot="1"] { --size: 96px; --x: calc(50% - var(--front) / 2 - 30px); --y: 68px; --z: 4; }
.queue.is-play .fan[data-slot="2"] { --size: 84px; --x: calc(50% - var(--front) / 2 - 56px); --y: 114px; --z: 3; }
.queue.is-play .fan[data-slot="3"] { --size: 72px; --x: calc(50% - var(--front) / 2 - 78px); --y: 152px; --z: 2; }

.fan + .fan { margin-left: 10px; }

.queue.is-play .fan + .fan { margin-left: 0; }

.fan-name { margin-top: 6px; }

.queue.is-play .fan-name { margin-top: 4px; }

.fan-inner {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 100%;
}

.fan-inner.leaving {
  opacity: 0;
  transform: translateY(-16px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.avatar {
  display: block;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 18%;
  border: 3px solid #fff;
  background: #e6dfd4;
  box-shadow: 0 8px 14px rgba(40, 24, 10, 0.16);
}

.queue.is-play .fan.is-front .avatar {
  box-shadow: 0 0 0 3px #e4c56d, 0 8px 14px rgba(40, 24, 10, 0.18);
}

.avatar-fallback {
  display: grid;
  place-items: center;
  color: #3c342c;
  font-weight: 700;
}

.queue.is-play .fan:not(.is-front) .fan-name { display: none; }

.fan-name {
  max-width: 100%;
  font-size: 12px;
  line-height: 1.2;
  text-align: center;
  color: #3c342c;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bubble {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  width: max-content;
  max-width: 132px;
  background: #fff;
  color: #3c342c;
  border-radius: 14px;
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 6px 16px rgba(40, 24, 10, 0.1);
}

.bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 10px;
  height: 10px;
  background: #fff;
  transform: translateX(-50%) rotate(45deg);
}

.queue.is-play .bubble {
  left: auto;
  right: calc(100% + 8px);
  bottom: 6px;
  transform: none;
}

.queue.is-play .bubble::after {
  left: auto;
  right: -5px;
  bottom: 12px;
  transform: rotate(45deg);
}

.floater {
  position: absolute;
  z-index: 7;
  left: 64%;
  bottom: 72px;
  color: #fff;
  background: #2f6b45;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 14px;
  font-weight: 700;
  animation: float-up 0.7s ease forwards;
  pointer-events: none;
}

.desk {
  position: relative;
  flex: 1;
  min-height: 0;
  background-color: #c4a574;
  background-image: url("../assets/desk-wood.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

.ready, .play {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 16px 18px;
  padding-bottom: calc(18px + var(--ui-bottom));
}

.ready > * + *,
.groups > * + * { margin-top: 14px; }

.groups > * + * { margin-top: 8px; }

.groups {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
}

.chip-row {
  display: flex;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
  padding: 2px 2px 4px;
  scrollbar-width: none;
}

.chip-row::-webkit-scrollbar { display: none; }

.chip + .chip { margin-left: 8px; }

.chip {
  flex: 0 0 auto;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 252, 247, 0.88);
  color: #3a342c;
  padding: 7px 11px;
  font-size: 12px;
  cursor: pointer;
}

.chip.on {
  background: #2f343a;
  color: #fff;
}

.chip.picked {
  box-shadow: inset 0 0 0 2px #2f343a;
}

.chip.on.picked { box-shadow: none; }

.pick-line {
  display: flex;
  align-items: center;
  margin: 0;
  color: #3a342c;
  font-size: 12px;
  line-height: 1.4;
}

.pick-line span {
  flex: 1;
  min-width: 0;
  overflow-wrap: break-word;
}

.pick-line button {
  flex: none;
  white-space: nowrap;
  margin-left: 8px;
  border: 0;
  background: transparent;
  color: #6a5a48;
  padding: 0;
  cursor: pointer;
}

.start {
  width: 86%;
  max-width: 300px;
  height: 64px;
  border: 0;
  border-radius: 2px;
  background: #3e454c;
  color: #fff;
  font-size: 22px;
  letter-spacing: 0.18em;
  cursor: pointer;
}

.start:hover { background: #32383e; }
.start:active { transform: translateY(1px); }

.sound {
  display: grid;
  align-items: center;
  justify-items: end;
  width: 43px;
  height: 43px;
  margin-left: 4px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.sound svg {
  width: 32px;
  height: 32px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sound .sound-off { display: none; }

.sound[aria-checked="false"] .sound-on { display: none; }

.sound[aria-checked="false"] .sound-off { display: block; }

.best {
  margin: 0;
  color: rgba(72, 48, 22, 0.72);
  font-size: 13px;
}

.play { position: relative; justify-content: flex-start; padding-top: 12px; }

.play > * + * { margin-top: 8px; }

.nameplate {
  max-width: 390px;
  background: rgba(255, 252, 247, 0.9);
  color: #3c342c;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  text-align: center;
  box-shadow: 0 4px 10px rgba(60, 30, 10, 0.08);
}

.pens {
  display: flex;
  flex: none;
  justify-content: center;
  padding: 2px 0;
}
.tool-area { position: relative; z-index: 3; flex: none; }
.eraser-size-panel {
  position: absolute;
  z-index: 12;
  top: calc(100% + 10px);
  left: 50%;
  width: 190px;
  transform: translateX(-50%);
  padding: 12px 14px;
  border-radius: 12px;
  background: #fffdf8;
  box-shadow: 0 8px 24px rgba(40, 24, 10, .24);
}
.eraser-size-panel label { display: flex; justify-content: space-between; font-size: 12px; }
.eraser-size-panel input { display: block; width: 100%; margin: 8px 0 0; }

.pen + .pen { margin-left: 8px; }

.pen {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  background: var(--c);
  padding: 0;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.18);
}

.pen.on { outline: 2px solid #fff; outline-offset: 2px; }
.pen.eraser {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fffdf8;
  color: #40362e;
}
.pen.eraser svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.paper-wrap {
  width: 92%;
  max-width: 390px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.paper {
  width: 100%;
  flex: 1;
  height: auto;
  background: var(--paper);
  box-shadow:
    inset 0 0 0 2px #f4e6bf,
    inset 0 0 0 8px #e4c56d,
    2px 10px 16px rgba(56, 34, 15, 0.25);
  display: flex;
  flex-direction: column;
  min-height: 0;
  touch-action: none;
}

.canvas-box {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 10px;
}

canvas {
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  display: block;
}

.ghost {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  place-items: center;
  color: rgba(140, 120, 80, 0.55);
  letter-spacing: 0.2em;
  pointer-events: none;
}

.handle {
  flex: none;
  z-index: 1;
  min-height: 44px;
  margin-top: 4px;
  padding: 0 16px;
  border: 0;
  background: transparent;
  color: #fffaf2;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.16em;
  cursor: pointer;
  touch-action: manipulation;
  text-shadow: 0 1px 2px rgba(48, 28, 10, 0.45);
}

.handle:disabled { opacity: .55; cursor: default; }

.paper-wrap.out {
  transform: translateY(-78%) rotate(-7deg);
  opacity: 0;
  transition: transform 0.34s ease, opacity 0.34s ease;
}

.paper-wrap.in { animation: paper-in 0.34s ease; }

.end {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 8;
  background: #f5efdf;
  display: flex;
  justify-content: center;
  padding: 18px 14px calc(16px + var(--ui-bottom));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.end-card {
  width: 100%;
  max-width: 420px;
  background: transparent;
  padding: 0 0 8px;
  text-align: center;
}

.end-kicker {
  margin: 0;
  letter-spacing: 0.18em;
  font-size: 12px;
  color: #a18446;
}

.end-card h2 {
  margin: 8px 0 0;
  font-family: Didot, "Bodoni MT", "Songti SC", "Noto Serif SC", serif;
  font-weight: 500;
  font-size: 32px;
  letter-spacing: 0.12em;
}

.end-score {
  margin: 8px 0 0;
  font-size: 42px;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.end-best, .end-note {
  margin: 4px 0 0;
  color: #6d645c;
  font-size: 14px;
}

.signed-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-gap: 28px 12px;
  gap: 28px 12px;
  margin: 16px 0 18px;
}

.signed-item {
  position: relative;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
}

.signed-sheet {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: calc(86.96% + 12px);
  border: 0;
  cursor: pointer;
  background: #fffefa;
  box-shadow:
    0 0 0 5px #cdb05d,
    2px 8px 14px rgba(56, 34, 15, 0.12);
  overflow: hidden;
}

.signed-ink {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: calc(100% - 12px);
  display: block;
  object-fit: contain;
}

.signed-face {
  width: 64px;
  height: 64px;
  margin-top: -12px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 18%;
  border: 3px solid #fff;
  background: #efe8dc;
  box-shadow: 0 2px 8px rgba(40, 24, 10, 0.22);
  position: relative;
  z-index: 1;
}

.signed-fallback {
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #6d645c;
}

.signed-name {
  margin: 6px 0 0;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: #5c564e;
}

.again { width: 100%; letter-spacing: 0.14em; }

.end-footer {
  color: #3b424a;
}

.feedback {
  margin: 18px 0 0;
  font-size: 13px;
}

.feedback a, .feedback span {
  color: #8a7352;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.result-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

.result-actions button, .result-preview button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 14px;
  cursor: pointer;
}

.result-actions svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.result-actions button:disabled, .result-preview button:disabled {
  opacity: .45;
  cursor: default;
}

.result-preview {
  position: absolute;
  inset: 0;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--ui-top) 14px calc(12px + var(--ui-bottom));
  background: rgba(25, 29, 34, .64);
}

.result-preview-card {
  width: 100%;
  max-width: 440px;
  max-height: 100%;
  overflow: auto;
  padding: 0 14px 10px;
  border-radius: 16px;
  background: #f5efdf;
  color: #3b424a;
  text-align: center;
}

.result-preview header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.result-preview h2 { margin: 0; font-size: 16px; }
#resultClose { font-size: 24px; }

.result-image-scroll {
  max-height: 57vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(139, 110, 59, 0.45) transparent;
}

.result-image-scroll::-webkit-scrollbar { width: 6px; }
.result-image-scroll::-webkit-scrollbar-track { background: transparent; }
.result-image-scroll::-webkit-scrollbar-thumb { background: rgba(139, 110, 59, 0.45); border-radius: 3px; }

#resultImage {
  display: block;
  width: auto;
  max-width: 100%;
  margin: 0 auto;
  object-fit: contain;
}

#resultStatus { margin: 0; font-size: 13px; }
#resultStatus:empty { display: none; }

footer {
  height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #6d645c;
  font-size: 11px;
  text-align: center;
  padding: 0 12px;
}

footer strong {
  font-family: Didot, "Bodoni MT", "Songti SC", "Noto Serif SC", serif;
  font-size: 14px;
  letter-spacing: 0.16em;
  font-weight: 500;
  color: #3c342c;
}

[hidden] { display: none !important; }

@keyframes idle {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@keyframes blink {
  0%, 88%, 100% { transform: scaleY(1); }
  94% { transform: scaleY(0.08); }
}

@keyframes paper-in {
  from { transform: translateY(36px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes float-up {
  to { transform: translateY(-28px); opacity: 0; }
}

@media (max-width: 520px) {
  .stage {
    height: var(--visible-height, 100vh);
    height: 100dvh;
    max-height: none;
    box-shadow: none;
  }
}

@media (max-width: 767px) {
  .play {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    height: auto;
    padding: 12px 12px calc(8px + var(--ui-bottom));
  }

  .play .paper-wrap { width: 100%; max-width: 440px; }
  #ink { position: absolute; top: 0; left: 0; }

  .stage.compact-play .queue.is-play {
    --front: 76px;
    height: 156px;
    min-height: calc(var(--ui-top) + 132px);
  }

  .stage.compact-play .queue.is-play .fan[data-slot="0"] { --x: calc(50% - 24px); --y: 4px; }
  .stage.compact-play .queue.is-play .fan[data-slot="1"] { --size: 48px; --x: calc(50% - 64px); --y: 24px; }
  .stage.compact-play .queue.is-play .fan[data-slot="2"] { --size: 44px; --x: calc(50% - 98px); --y: 26px; }
  .stage.compact-play .queue.is-play .fan[data-slot="3"] { --size: 40px; --x: calc(50% - 128px); --y: 28px; }
  .stage.compact-play .queue.is-play .bubble { display: none; }

  .stage.compact-play .play { padding-top: 8px; }
  .stage.compact-play .play > * + * { margin-top: 6px; }
  .stage.compact-play .end-now { right: 10px; padding: 0 10px; font-size: 14px; }
}

@media (min-width: 768px) {
  .app { max-width: 900px; }

  .stage {
    height: 100vh;
    max-height: 1180px;
    height: min(1180px, 100dvh);
  }

  .hud {
    left: calc(22px + var(--ui-left));
    right: calc(22px + var(--ui-right));
  }

  .clock, .count { font-size: 40px; }

  .clock svg { width: 28px; height: 28px; }

  .clock small, .count small { font-size: 16px; }

  .time-hint { font-size: 14px; }

  .queue {
    height: 280px;
    height: clamp(250px, 30vh, 340px);
    padding: calc(var(--ui-top) + 52px) 20px 18px;
  }

  .fan + .fan { margin-left: 16px; }

  .queue.is-play {
    --front: 156px;
    height: 360px;
    height: clamp(340px, 36vh, 400px);
    padding-top: calc(var(--ui-top) + 56px);
  }

  .queue.is-play .fan[data-slot="1"] { --size: 136px; --x: calc(50% - var(--front) / 2 - 36px); --y: 84px; }
  .queue.is-play .fan[data-slot="2"] { --size: 116px; --x: calc(50% - var(--front) / 2 - 68px); --y: 142px; }
  .queue.is-play .fan[data-slot="3"] { --size: 100px; --x: calc(50% - var(--front) / 2 - 96px); --y: 190px; }

  .fan { width: 96px; flex-basis: 96px; }

  .fan-name { margin-top: 8px; font-size: 15px; }

  .bubble { max-width: 180px; font-size: 15px; padding: 8px 12px; }

  .groups { max-width: 680px; }

  .chip { padding: 10px 16px; font-size: 15px; }

  .start { width: 72%; max-width: 460px; height: 76px; font-size: 26px; }

  .sound { width: 45px; height: 45px; }
  .sound svg { width: 35px; height: 35px; }

  .best { font-size: 15px; }

  .nameplate { max-width: 620px; font-size: 16px; padding: 10px 18px; }

  .pen + .pen { margin-left: 12px; }

  .pen, .pen.eraser { width: 30px; height: 30px; }
  .pen.eraser svg { width: 21px; height: 21px; }

  .play {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    height: auto;
    padding: 14px 24px calc(24px + var(--ui-bottom));
  }

  #ink { position: absolute; top: 0; left: 0; }

  .paper-wrap { width: 86%; max-width: 640px; flex: 0 1 auto; }

  .paper {
    flex: 0 1 auto;
    height: 360px;
    height: clamp(300px, 35vh, 460px);
  }

  .handle { font-size: 16px; min-height: 52px; padding: 0 28px; }

  .end-card { max-width: 720px; }

  .end-card h2 { font-size: 40px; }

  .end-score { font-size: 52px; }

  .signed-row {
    grid-template-columns: 1fr 1fr 1fr;
    grid-gap: 32px 18px;
    gap: 32px 18px;
  }

  .signed-face { width: 78px; height: 78px; margin-top: -12px; }
}

@media (min-width: 768px) and (max-height: 820px) {
  .queue { height: 210px; padding-top: 48px; }

  .queue.is-play {
    --front: 124px;
    height: 286px;
    padding-top: 40px;
  }

  .queue.is-play .fan[data-slot="1"] { --size: 108px; --x: calc(50% - var(--front) / 2 - 28px); --y: 58px; }
  .queue.is-play .fan[data-slot="2"] { --size: 94px; --x: calc(50% - var(--front) / 2 - 52px); --y: 100px; }
  .queue.is-play .fan[data-slot="3"] { --size: 82px; --x: calc(50% - var(--front) / 2 - 74px); --y: 136px; }

  .start { height: 60px; font-size: 22px; }
}

@media (min-width: 768px) and (orientation: landscape) {
  .app { max-width: 1080px; }

  .queue.is-play {
    --front: 100px;
    height: calc(172px + var(--ui-top));
    padding-top: calc(16px + var(--ui-top));
  }

  .queue.is-play .fan[data-slot="1"] { --size: 84px; --x: calc(50% - var(--front) / 2 - 26px); --y: 34px; }
  .queue.is-play .fan[data-slot="2"] { --size: 72px; --x: calc(50% - var(--front) / 2 - 46px); --y: 62px; }
  .queue.is-play .fan[data-slot="3"] { --size: 62px; --x: calc(50% - var(--front) / 2 - 62px); --y: 84px; }
  .queue.is-play .bubble { display: none; }

  .play { padding-top: 10px; padding-bottom: calc(40px + var(--ui-bottom)); }
  .play > * + * { margin-top: 6px; }

  .nameplate { max-width: 46%; }

  .tool-area {
    position: absolute;
    top: 14px;
    left: calc(7% + 20px);
  }

  .play > .paper-wrap { margin-top: 10px; }
  .paper-wrap { width: 86%; max-width: 860px; flex: 1 1 auto; max-height: 480px; }
  .paper { flex: 1 1 auto; height: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

.uploads {
  width: 100%;
  max-width: 400px;
  max-height: min(38vh, 280px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.upload-button {
  display: inline-block;
  padding: 11px 20px;
  border-radius: 999px;
  background: #fffdf8;
  color: #3a342c;
  font-weight: 700;
  cursor: pointer;
}
.upload-list {
  width: 100%;
  overflow-y: auto;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: #888 transparent;
}
.upload-list::-webkit-scrollbar { width: 8px; }
.upload-list::-webkit-scrollbar-track { background: transparent; }
.upload-list::-webkit-scrollbar-thumb { background: #888; border-radius: 999px; }
.upload-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0;
  padding: 5px 9px;
  border-radius: 12px;
  background: rgba(255,253,248,.88);
}
.upload-item img { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; }
.upload-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-name-input { flex: 1; min-width: 0; padding: 5px 7px; border: 1px solid #ad977d; border-radius: 6px; background: #fff; }
.upload-item button { flex: none; border: 0; background: transparent; color: #9b453d; cursor: pointer; }
.upload-hint { margin: 0; color: #42382c; text-align: center; font-size: 13px; }
.start:disabled { opacity: .45; cursor: not-allowed; }

.crop-dialog {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(35, 29, 23, .58);
}
.crop-card {
  width: min(100%, 360px);
  padding: 20px;
  border-radius: 18px;
  background: #fffdf8;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0,0,0,.2);
}
.crop-card h2 { margin: 0 0 6px; font-size: 21px; }
.crop-card p { margin: 0 0 16px; color: #6d6257; font-size: 13px; }
#cropCanvas {
  display: block;
  width: min(240px, 100%);
  height: auto;
  margin: 0 auto 18px;
  border: 3px solid #d4b15e;
  border-radius: 50%;
  touch-action: none;
  cursor: grab;
}
#cropCanvas:active { cursor: grabbing; }
.crop-zoom { display: flex; align-items: center; gap: 12px; text-align: left; }
.crop-zoom input { flex: 1; min-width: 0; }
.crop-actions { display: flex; gap: 10px; margin-top: 20px; }
.crop-actions button { flex: 1; padding: 10px; border: 0; border-radius: 9px; background: #e9e1d5; }
.crop-actions #cropSave { background: #3e454c; color: white; }
