:root {
  color-scheme: light;
  --paper: #f8f6ef;
  --ink: #302e29;
  --safe-left: max(17px, env(safe-area-inset-left));
  --safe-right: max(17px, env(safe-area-inset-right));
  --wheel-space: calc(100vw - var(--safe-left) - var(--safe-right));
  --size: min(536px, var(--wheel-space), 65vh);
  --size: min(536px, var(--wheel-space), 65svh);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--paper); color: var(--ink); }
button, textarea { font: inherit; }
button {
  color: inherit;
  border: 0;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  cursor: pointer;
}
button:focus-visible { outline: 2px solid #685c45; outline-offset: 5px; }
button:disabled { cursor: default; }
button, .machine { -webkit-user-select: none; user-select: none; }
.tabletop {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100svh;
  padding: max(50px, env(safe-area-inset-top)) var(--safe-right) max(40px, env(safe-area-inset-bottom)) var(--safe-left);
  background:
    radial-gradient(ellipse at 43% 34%, #fdfbf539, transparent 63%),
    radial-gradient(ellipse at 50% 56%, #e9e2d04d, transparent 62%);
}
.tabletop::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  background-image: radial-gradient(circle, #82796329 .65px, transparent .95px);
  background-position: center center;
  background-size: 19px 19px;
  -webkit-mask-image: radial-gradient(ellipse at center, black 12%, #0009 72%, #0004);
  mask-image: radial-gradient(ellipse at center, black 12%, #0009 72%, #0004);
  pointer-events: none;
}
.round-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  transition: background-color .18s, transform .18s, opacity .2s, box-shadow .18s;
}
.edit-button {
  position: absolute;
  z-index: 3;
  top: max(clamp(19px, 4.6vh, 43px), calc(env(safe-area-inset-top) + 10px));
  right: max(clamp(20px, 3.8vw, 58px), calc(env(safe-area-inset-right) + 12px));
  color: #514d42;
  background: #fbf9f3;
  border: 1px solid #d9d5c9;
  box-shadow: inset 0 1px 0 #ffffffd9, 0 2px 4px #5147310a;
}
.edit-button:disabled { opacity: .38; }
.round-button:active:not(:disabled) { transform: scale(.93); }
.pencil {
  width: 6px;
  height: 15px;
  margin: -2px 0 0 2px;
  border: 1.5px solid currentColor;
  border-radius: 2px 2px 0 0;
  position: relative;
  transform: rotate(39deg);
}
.pencil::before {
  content: "";
  position: absolute;
  width: 4px;
  height: 4px;
  left: -.5px;
  bottom: -3.4px;
  background: currentColor;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.pencil i { position: absolute; left: 0; right: 0; top: 2px; border-bottom: 1px solid currentColor; }
.instrument {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(29px, 5.3vh, 54px);
  position: relative;
}
.wheel {
  position: relative;
  width: var(--size);
  height: var(--size);
  display: block;
  flex: none;
  border-radius: 50%;
  background: transparent;
  overflow: visible;
}
.machine {
  display: block;
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: transform .24s cubic-bezier(.18,.84,.24,1.14);
}
.wheel:active:not([aria-disabled="true"]) .machine { transform: translateY(1px) scale(.989); transition-duration: .08s; }
.case {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: linear-gradient(145deg, #fffef9 4%, #f6f2e8 45%, #e4dece 84%, #d6cfbd);
  border: 1px solid #c8c1b2;
  box-shadow:
    inset 0 2px 2px #ffffffef,
    inset 0 -2px 3px #b8ac935c,
    0 2px 1px #a3988130,
    0 6px 9px -5px #55472c39,
    0 17px 22px -14px #63553856,
    0 34px 48px -27px #6150344d;
}
.case::after {
  content: "";
  position: absolute;
  inset: 1.15%;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #bfb7a477, 0 1px 0 1.5px #ffffffe0;
}
.wheel-window {
  position: absolute;
  inset: 1.4%;
  overflow: hidden;
  border-radius: 50%;
  isolation: isolate;
}
.rotor {
  position: absolute;
  inset: 0;
  display: block;
  border-radius: 50%;
  background: #f6f2e7;
  transform: rotate(var(--turn, 0deg));
}
.instrument[data-phase="running"] .rotor, .instrument[data-phase="braking"] .rotor { will-change: transform; }
.dial, .selection, .labels { position: absolute; inset: 0; width: 100%; height: 100%; display: block; border-radius: 50%; }
.selection { opacity: 0; transition: opacity .26s ease-out; }
.wheel.has-result .selection { opacity: 1; }
.option {
  position: absolute;
  transform: translate(-50%, -50%);
  display: block;
}
.option-content {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: calc(var(--size) * .008);
  color: var(--legend-ink);
  transform: rotate(calc(0deg - var(--turn, 0deg)));
}
.option-icon { display: block; width: calc(var(--size) * .076); height: calc(var(--size) * .076); }
.option-name {
  display: block;
  font-size: clamp(13px, calc(var(--size) * .0345), 19px);
  line-height: 1.35;
  font-weight: 560;
  letter-spacing: .06em;
  padding-left: .06em;
  max-width: var(--label-width);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.hub {
  position: absolute;
  display: grid;
  place-items: center;
  width: 15.3%;
  height: 15.3%;
  left: 42.35%;
  top: 42.35%;
  border-radius: 50%;
  background: linear-gradient(155deg, #fffdf6 10%, #f8f4e8 68%, #e6dfca);
  border: 1px solid #bdb29a;
  box-shadow: inset 0 2px 1px #ffffffe8, inset 0 -2px 2px #d1c7b27a, 0 2px 3px #67563842, 0 5px 9px #5b48321f;
}
.hub::before { content: ""; position: absolute; inset: 8%; border-radius: 50%; border: 1px solid #cfc5af8a; }
.hub canvas { display: block; width: 55%; height: 55%; }
.needle {
  position: absolute;
  z-index: 2;
  display: block;
  width: 7.8%;
  height: 12.1%;
  left: 46.1%;
  top: -3.4%;
  transform-origin: 50% 24.7%;
  filter: drop-shadow(0 2px 1px #4237214a);
}
.needle canvas { width: 100%; height: 100%; display: block; }
.controls { position: relative; display: flex; flex-direction: column; align-items: center; }
.spin-button, .save-button {
  position: relative;
  color: #fffdf5;
  background: linear-gradient(165deg, #393832, #292924);
  border: 1px solid #282721;
  box-shadow: inset 0 1px 0 #ffffff24, 0 3px 4px -2px #332c1e45, 0 7px 14px -9px #352c1e65;
  transition: transform .2s, box-shadow .2s, background-color .16s;
}
.spin-button {
  width: clamp(142px, 15.5vw, 159px);
  height: 53px;
  border-radius: 40px;
  font-weight: 550;
  letter-spacing: .12em;
  font-size: 17px;
}
.spin-button:active, .save-button:active { transform: translateY(1px) scale(.968); }
.control-state {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  position: absolute; inset: 0; padding-left: .12em;
  transition: transform .21s cubic-bezier(.2,.8,.25,1), opacity .17s;
}
.control-state span { line-height: 1; }
.stop-state, .brake-state { opacity: 0; transform: translateY(4px); }
.instrument[data-phase="running"] .stop-state, .instrument[data-phase="braking"] .brake-state { opacity: 1; transform: translateY(0); }
.instrument:not([data-phase="idle"]) .start-state { opacity: 0; transform: translateY(-4px); }
.instrument[data-phase="braking"] .spin-button { cursor: progress; }
.brake-icon {
  width: 15px; height: 15px; border-radius: 50%;
  background: conic-gradient(currentColor var(--brake-progress, 0deg), #fffa 0);
  -webkit-mask: radial-gradient(circle, transparent 49%, #000 55%);
  mask: radial-gradient(circle, transparent 49%, #000 55%);
}
.play-icon { width: 13px; height: 15px; background: currentColor; clip-path: polygon(7% 7%, 13% 3%, 94% 44%, 98% 50%, 94% 56%, 13% 97%, 7% 93%); }
.stop-icon { width: 11px; height: 11px; border-radius: 2px; background: currentColor; }
.result { position: absolute; height: 1px; width: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.result.expanded {
  position: static; margin-top: 12px;
  width: min(var(--wheel-space), 480px); height: auto; max-height: min(6em, 18vh); overflow: auto;
  padding: 0 4px 4px;
  clip-path: none; white-space: normal; text-align: center; overflow-wrap: anywhere;
  font-size: 16px; font-weight: 550; color: #514a3b;
}
dialog {
  position: fixed;
  inset: var(--visible-top, 0px) 0 var(--covered-bottom, 0px);
  width: min(390px, calc(100vw - 36px));
  max-height: min(88vh, 640px);
  max-height: min(640px, calc(var(--visible-h, 100dvh) - 16px));
  padding: 26px;
  border: 1px solid #d8d1c1; border-radius: 22px;
  background: #faf8f1; color: var(--ink);
  box-shadow: 0 22px 75px #352d2040, 0 2px 9px #352d2010, inset 0 1px 0 #fff;
  overscroll-behavior: contain; overflow-y: auto;
}
dialog[open] { animation: sheet-in .23s cubic-bezier(.22,.8,.28,1); }
dialog::backdrop { background: #34312638; -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px); }
.editor-head { display: flex; align-items: center; justify-content: space-between; margin: -4px -4px 20px 0; }
.editor-head h1 { margin: 0; font-size: 21px; font-weight: 620; letter-spacing: .035em; }
.close-button { width: 44px; height: 44px; color: #645e4e; background: transparent; }
.close-button span { position: relative; width: 16px; height: 16px; }
.close-button span::before, .close-button span::after { content: ""; position: absolute; top: 7px; left: 0; width: 16px; height: 1.5px; border-radius: 1px; background: currentColor; transform: rotate(45deg); }
.close-button span::after { transform: rotate(-45deg); }
dialog label { display: block; font-size: 14px; line-height: 1.5; color: #696456; margin-bottom: 8px; }
textarea {
  width: 100%; display: block; resize: vertical; min-height: 50px;
  height: clamp(50px, calc(var(--visible-h, 100dvh) - 250px), 238px);
  max-height: max(50px, calc(var(--visible-h, 100dvh) - 214px));
  padding: 12px 15px; color: #37342c; background: #fffdf7; border: 1px solid #d5cfbf; border-radius: 10px;
  font-size: 16px; line-height: 1.65; outline: 0;
}
textarea:focus { border-color: #8b816b; box-shadow: 0 0 0 3px #a69a7d1f; }
.save-button { display: block; width: 100%; height: 47px; margin-top: 19px; border-radius: 24px; font-weight: 550; letter-spacing: .12em; }
.error { color: #914e34; font-size: 14px; margin: 8px 0 0; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: translateY(0); } }
@media (hover: hover) {
  .edit-button:hover:not(:disabled) { background: #fffdf7; box-shadow: inset 0 1px 0 white, 0 3px 8px #51473117; }
  .spin-button:hover:not([aria-disabled="true"]), .save-button:hover { box-shadow: inset 0 1px 0 #ffffff28, 0 4px 7px -3px #332c1e55, 0 9px 16px -8px #352c1e58; }
  .close-button:hover { background: #ede9de; }
}
@media (max-width: 520px) {
  .instrument { gap: 36px; }
  .tabletop { padding-top: max(37px, env(safe-area-inset-top)); padding-bottom: max(34px, env(safe-area-inset-bottom)); }
  dialog { margin: auto auto 0; width: 100%; max-width: none; border-radius: 23px 23px 0 0; padding: 22px 22px max(22px, env(safe-area-inset-bottom)); }
  textarea { resize: none; }
}
@media (max-height: 490px) {
  :root { --size: min(59vh, var(--wheel-space)); --size: min(59svh, var(--wheel-space)); }
  .tabletop { padding: max(24px, env(safe-area-inset-top)) var(--safe-right) max(14px, env(safe-area-inset-bottom)) var(--safe-left); }
  .instrument { gap: 18px; }
  .spin-button { height: 44px; }
  .edit-button { top: max(12px, env(safe-area-inset-top)); right: max(16px, calc(env(safe-area-inset-right) + 8px)); }
  dialog { padding: 12px 18px max(12px, env(safe-area-inset-bottom)); }
  .editor-head { margin-bottom: 3px; }
  .save-button { margin-top: 9px; min-height: 44px; }
  textarea { height: clamp(50px, calc(var(--visible-h, 100dvh) - 186px), 180px); max-height: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
