:root {
  color-scheme: light;
  --ink: #fff0d7;
  --subtle: #eac4a1;
  --accent: #ffcc8b;
  --deep: #542b20;
  --panel: #683624;
  --border: #f7cfaa4d;
  --paper: #f8e5cb;
  --paper-ink: #51291d;
  --paper-border: #a05e3b66;
  --serif: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif CJK JP", "Batang", Georgia, serif;
  --sans: "Yu Gothic UI", "Hiragino Kaku Gothic ProN", "Malgun Gothic", system-ui, sans-serif;
  font-family: var(--sans);
  background: var(--deep);
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, select, a { -webkit-tap-highlight-color: transparent; }
button, select { color: inherit; font: inherit; }
button, a, select { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: default; }
a { color: inherit; }
:focus-visible { outline: 2px solid #9b391d; outline-offset: 4px; }
.sr { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.atelier {
  --stage-outer: #ba8456;
  --stage-mid: #e2b080;
  --stage-light: #f7deaf;
  --stone: #c88d55;
  --stone-side: #82482e;
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "head" "scene" "tray";
  height: 100vh;
  height: 100dvh;
  min-height: 480px;
  isolation: isolate;
  overflow: hidden;
  background: var(--panel);
}
.atelier[data-level="1"] { --stage-outer: #b87a62; --stage-mid: #e4a990; --stage-light: #ffe1c2; --stone: #d99b78; --stone-side: #96553e; }
.atelier[data-level="2"] { --stage-outer: #b77e54; --stage-mid: #dda16c; --stage-light: #f8cd9b; --stone: #c88a55; --stone-side: #874626; }
.masthead {
  grid-area: head;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 63px;
  padding: max(9px, env(safe-area-inset-top)) clamp(18px, 3.7vw, 64px) 9px;
  color: var(--paper-ink);
  background: linear-gradient(106deg, #fff0d9, var(--paper) 64%, #f3d6b5);
  border-bottom: 1px solid var(--paper-border);
}
.masthead h1 { display: flex; align-items: center; gap: 13px; margin: 0; font: 650 clamp(19px, 2vw, 27px)/1.1 var(--serif); letter-spacing: .11em; }
.seal { display: inline-block; width: 28px; height: 31px; background: conic-gradient(from 34deg, #eaa25e 0 17%, #b86941 17% 34%, #8c412e 34% 55%, #cc784f 55% 74%, #f4c58c 74% 100%); clip-path: polygon(51% 0, 99% 27%, 94% 73%, 51% 100%, 7% 75%, 0 29%); }
.settings { display: flex; align-items: center; gap: 12px; }
.icon, .settings select {
  display: inline-grid;
  place-items: center;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: #6f392b13;
  transition: background .15s ease, border-color .15s ease;
}
.icon:hover, .settings select:hover { background: #eecba7; border-color: #9a542f92; }
.settings { --border: var(--paper-border); }
.settings select { border-radius: 30px; padding: 0 13px; background: var(--paper); font-size: .78rem; }
.settings option { background-color: var(--paper); }
.speaker { position: relative; width: 20px; height: 18px; }
.speaker::before { position: absolute; inset: 2px 8px 2px 0; content: ""; background: currentColor; clip-path: polygon(0 31%, 39% 31%, 94% 0, 94% 100%, 39% 69%, 0 69%); }
.speaker::after { content: ""; position: absolute; inset: 1px 2px 1px 3px; border: 1px solid transparent; border-right-color: currentColor; border-radius: 50%; }
[aria-pressed="false"] .speaker::after { inset: 6px 0 auto auto; width: 8px; height: 7px; border: 0; border-radius: 0; background: currentColor; clip-path: polygon(0 11%, 11% 0, 50% 38%, 89% 0, 100% 11%, 62% 50%, 100% 89%, 89% 100%, 50% 62%, 11% 100%, 0 89%, 38% 50%); }
.stage-meta {
  position: absolute;
  inset: clamp(12px, 2.7vh, 28px) clamp(14px, 3.7vw, 64px) auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
}
.specimen { display: flex; align-items: center; gap: 12px; color: var(--paper-ink); }
.stage-meta .specimen { position: absolute; left: 50%; translate: -50%; white-space: nowrap; }
.edition { padding-right: 12px; border-right: 1px solid #78492f6b; font-size: .74rem; font-variant-numeric: tabular-nums; letter-spacing: .07em; white-space: nowrap; }
.specimen h2 { margin: 0; font: 700 clamp(20px, 3vw, 33px)/1.13 var(--serif); letter-spacing: .035em; }
.progress { width: clamp(75px, 12vw, 138px); margin: 2px 0 0 auto; color: var(--paper-ink); font-weight: 650; font-size: .68rem; }
.progress div { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; margin-bottom: 4px; }
.progress output { color: var(--paper-ink); font: 700 clamp(1.02rem, 2vw, 1.4rem)/1 Georgia, serif; font-variant-numeric: tabular-nums; }
progress { appearance: none; display: block; width: 100%; height: 3px; border: 0; border-radius: 3px; background: #7f432945; overflow: hidden; }
progress::-webkit-progress-bar { background: #7f432945; }
progress::-webkit-progress-value { background: #97492a; }
progress::-moz-progress-bar { background: #97492a; }
.arena {
  grid-area: scene;
  position: relative;
  min-width: 0;
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(ellipse at 44% 20%, #fff5dc7c, transparent 56%), radial-gradient(ellipse at 50% 38%, var(--stage-light), var(--stage-mid) 60%, var(--stage-outer));
}
.arena::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(134deg, #6e341f20 0 1px, transparent 1px 5px), repeating-linear-gradient(24deg, #fff4e21c 0 1px, transparent 1px 6px);
  opacity: .38;
  mask-image: linear-gradient(#000, transparent 90%);
}
.arena::after { content: ""; position: absolute; z-index: -1; inset: 0; background: conic-gradient(from 221deg at -12% 4%, transparent 0 57%, #fff6d92c 60% 64%, #f9ebc030 65%, transparent 68%), linear-gradient(transparent 65%, #8c44274d); pointer-events: none; }
.base { position: absolute; translate: -50% -50%; width: var(--diameter, 300px); height: var(--lip, 80px); border-radius: 50%; background: linear-gradient(142deg, #ffdfae7b, transparent 58%), var(--stone); box-shadow: 0 1px 1px #f1c58e, 0 11px 0 var(--stone-side), 0 14px 0 #5b2e239e, 28px 24px 34px #703c2a88, 58px 40px 62px #7b43315c; }
.base::before { content: ""; position: absolute; inset: 4% 1.5%; border-radius: 50%; border: 1px solid #fff6d181; background: radial-gradient(ellipse at 48% 44%, #713f2c88, transparent 47%), repeating-linear-gradient(153deg, #72402c1c 0 1px, transparent 1px 7px); }
.base-rim { position: absolute; inset: 11% 5%; border: 1px solid #8c4a2e46; border-radius: 50%; }
#surface { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; cursor: grab; }
#surface:active { cursor: grabbing; }
#surface:focus-visible { outline-offset: -4px; }
.orbit { position: absolute; left: 50%; bottom: 10px; translate: -50%; display: flex; align-items: center; gap: 12px; }
.orbit-button, .restart { color: var(--ink); background: #633422ea; }
.orbit-button:hover, .restart:hover:not(:disabled) { background: #80452d; }
.orbit-button { font: 400 23px/1 Georgia, serif; }
.orbit-button span { translate: 0 -1px; }
#rotate-label { color: var(--paper-ink); font-size: .72rem; font-weight: 650; letter-spacing: .05em; text-shadow: 0 1px 3px #ffe1b9; white-space: nowrap; }
.restart { position: absolute; right: 17px; bottom: 10px; font-size: 23px; }
.restart:disabled { visibility: hidden; }
.tray-wrap {
  color-scheme: dark;
  grid-area: tray;
  z-index: 1;
  background: radial-gradient(ellipse at 50% 0, #9b5a3b, transparent 77%), var(--panel);
  border-top: 1px solid var(--border);
  padding: 8px 13px max(9px, env(safe-area-inset-bottom));
}
.tray-wrap :focus-visible { outline-color: #ffdd9e; }
.tray-inner { width: min(100%, 430px); margin: 0 auto; }
.tray, .orders { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.tray {
  padding: 5px;
  border: 1px solid #efb88b99;
  border-radius: 11px;
  background: linear-gradient(#bd855b, #82492e);
  box-shadow: 0 6px 15px #4c261b9c, inset 0 1px 2px #f5c9949e;
}
.well {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 37px;
  padding: 1px 6px;
  border: 1px solid #eaad7c88;
  border-radius: 6px;
  background: linear-gradient(145deg, #633c2b, #89563b);
  box-shadow: inset 0 2px 5px #4b281fb5;
}
.well::after { content: ""; width: 5px; height: 5px; background: #f6c39879; transform: rotate(45deg); }
.well.filled {
  background: radial-gradient(ellipse at center, var(--glaze) 0% 19%, color-mix(in srgb, var(--glaze) 48%, #70432e) 95%);
  border-color: color-mix(in srgb, var(--glaze) 70%, #fff1b7);
  color: var(--glaze-ink);
  text-shadow: 0 1px 1px var(--glaze-shadow);
}
.well.filled::after { display: none; }
.well-hit {
  position: absolute;
  inset: 1px;
  opacity: 0;
  border: 1px solid #fff4c5;
  border-radius: inherit;
  background: radial-gradient(ellipse, #fff0b549 0%, transparent 74%);
  box-shadow: inset 0 0 12px #fff3bf5c;
  pointer-events: none;
}
.well.settled { border-color: #f0db9a; }
.well i, .well b { position: relative; z-index: 1; }
.well.waiting { border-style: dashed; filter: saturate(.58); }
.well i, .order i { font: 720 .68rem/1 var(--sans); font-style: normal; }
.well b, .order b { font: 700 1.22rem/.9 Georgia, serif; font-variant-numeric: tabular-nums; }
.match {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 1.3em;
  gap: 7px;
  margin: 5px 0 1px;
  color: var(--subtle);
  font-size: .68rem;
  letter-spacing: .035em;
}
.match i { width: 5px; height: 5px; transform: rotate(45deg); background: var(--accent); }
.match[data-full="true"] { color: #f6c28e; }
.orders { padding: 0 5px; }
.lane { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.order {
  position: relative;
  order: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  width: 100%;
  min-height: 43px;
  padding: 1px 7px 3px;
  border: 1px solid color-mix(in srgb, var(--glaze) 72%, #ffedb2);
  border-radius: 8px 8px 10px 10px;
  color: var(--glaze-ink);
  text-shadow: 0 1px 1px var(--glaze-shadow);
  background: radial-gradient(ellipse at 36% 0%, #fff4ce89, transparent 71%),
    linear-gradient(152deg, var(--glaze), color-mix(in srgb, var(--glaze) 59%, #6c422c));
  box-shadow: inset 0 -3px 0 #4d291f6b, inset 0 1px 2px #ffeeb278, 0 3px 5px #4a231a;
}
.order:hover:not(:disabled) { filter: brightness(1.18); }
.order:active:not(:disabled) { transform: translateY(2px); }
.order:disabled { filter: saturate(.67) brightness(.73); }
.order.empty { visibility: hidden; }
.next-order {
  order: 1;
  display: block;
  width: 69%;
  min-width: 38px;
  margin-inline: auto;
  border-radius: 2px 2px 5px 5px;
  background: color-mix(in srgb, var(--next-glaze) 29%, #713e2d);
  color: #fbf1d8;
  font: 600 .61rem/1.45 var(--sans);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
#effects { position: fixed; z-index: 4; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.atelier[data-draw="lite"] .arena { background: radial-gradient(ellipse at 50% 40%, var(--stage-light), var(--stage-outer)); }
.atelier[data-draw="lite"] .arena::before, .atelier[data-draw="lite"] .arena::after { display: none; }
.atelier[data-draw="lite"] .base { box-shadow: 0 8px 0 var(--stone-side), 0 10px 0 #5b302161; }
dialog {
  --ink: var(--paper-ink);
  --subtle: #754530;
  --accent: #98442b;
  --border: var(--paper-border);
  color: var(--ink);
  background: linear-gradient(140deg, #fff1de, var(--paper));
  border: 1px solid var(--paper-border);
  font-family: inherit;
}
dialog::backdrop { background: #522e2395; }
.result { inset: auto 0 max(13px, env(safe-area-inset-bottom)) auto; width: min(365px, calc(100vw - 24px)); margin: 0 18px 0 0; padding: 0; border-radius: 14px; box-shadow: 0 20px 48px #4f281fb0; z-index: 3; }
.result-inner { padding: 21px 25px 20px; }
.result-number { margin: 0 0 5px; color: var(--accent); font: 500 .77rem/1.3 var(--sans); letter-spacing: .11em; }
.result h2, .share-head h2 { margin: 0; font: 650 clamp(25px, 4vw, 31px)/1.2 var(--serif); }
.result-record { margin: 9px 0 14px; color: var(--subtle); font: 500 .82rem/1.4 var(--sans); }
.result-actions, .share-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 4px; }
.primary, .secondary, .text-button { display: inline-grid; place-items: center; min-height: 44px; font-size: .84rem; font-weight: 600; text-decoration: none; border-radius: 7px; padding: 0 13px; }
.primary { border: 1px solid #883a23; color: #fff5e6; background: #9a3f28; }
.primary:hover { background: #7d2e1d; }
.secondary { border: 1px solid #ac70488f; color: var(--ink); background: #f1d4b6; }
.secondary:hover { background: #ebc4a1; }
.text-button { background: transparent; border: 0; padding: 0 5px; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.text-button:hover { color: var(--accent); }
.result .text-button + .text-button { margin-left: 7px; }
.share-dialog { max-width: min(470px, calc(100vw - 22px)); max-height: min(92vh, calc(100dvh - 30px)); padding: 13px 17px 18px; border-radius: 14px; overflow: auto; overscroll-behavior: contain; }
.share-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 10px; }
.share-dialog img { display: block; width: 100%; height: auto; background: #82482f; }
.share-dialog p { color: var(--subtle); font-size: .78rem; line-height: 1.45; }
.share-actions { margin: 0; }
@media (max-height: 620px) {
  .masthead { min-height: 51px; }
  .tray-wrap { padding-top: 5px; }
  .well { min-height: 31px; }
  .orbit, .restart { bottom: 4px; }
  .stage-meta { top: 8px; }
}
@media (max-width: 700px) {
  .atelier { min-height: 410px; }
  .masthead { min-height: 51px; padding: max(3px, env(safe-area-inset-top)) 13px 3px; }
  .masthead h1 { gap: 8px; letter-spacing: .065em; }
  .seal { width: 19px; height: 21px; }
  .settings { gap: 6px; }
  .settings select { padding: 0 8px; }
  .stage-meta { inset-inline: 13px; }
  .specimen { gap: 6px; }
  .specimen h2 { font-size: clamp(16px, 5vw, 26px); letter-spacing: 0; }
  .edition { padding-right: 6px; font-size: .59rem; }
  .progress { font-size: .56rem; }
  .arena::before { opacity: .28; }
  .orbit, .restart { bottom: 5px; }
  .restart { right: 8px; }
  .orbit { gap: 8px; }
  .tray-wrap { padding-inline: 10px; }
  .tray-inner { width: min(100%, 390px); }
  .tray, .orders { gap: 5px; }
  .result { width: min(365px, calc(100vw - 20px)); margin-inline: auto; inset-inline: 0; }
  .result-inner { padding: 14px 17px 9px; }
}
@media (max-width: 355px) {
  .specimen h2 { max-width: 158px; }
  .stage-meta .specimen { left: 0; translate: none; }
  .progress { width: 63px; }
  .progress div { gap: 2px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::after, *::before { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
