:root {
  --felt: #10241c;
  --gold: #e3c27a;
  --gold-deep: #a97838;
  --ivory: #f4efe4;
  --text: #10241c;
  --muted: #5c6b62;
  --line: rgba(227, 194, 122, 0.2);
  --cinnabar: #f0b4aa;
  --bamboo: #b7d4c4;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  color-scheme: light;
}

* { box-sizing: border-box; }

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

body {
  min-height: var(--tg-viewport-stable-height, 100vh);
  font-family: "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--ivory);
}

button, input { font: inherit; }

button {
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.wrap {
  width: min(480px, 100%);
  max-width: 100%;
  margin: 0 auto;
  padding: 18px 16px calc(28px + env(safe-area-inset-bottom));
  overflow-wrap: break-word;
}

.loading, .fatal {
  min-height: 70vh;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  line-height: 1.5;
}

.fatal strong {
  display: block;
  margin-bottom: 8px;
  color: var(--felt);
  font-family: Palatino, "Palatino Linotype", "Times New Roman", serif;
  font-size: 34px;
  font-weight: 600;
}

.top {
  position: sticky;
  top: 0;
  z-index: 3;
  padding: 8px 0 12px;
  background: linear-gradient(var(--ivory), rgba(244, 239, 228, 0.94) 72%, transparent);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--gold-deep);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1, h2 {
  font-family: Palatino, "Palatino Linotype", "Times New Roman", serif;
  font-weight: 600;
  letter-spacing: 0.01em;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.option-line, .hint, .caption, .quota, .time, .footer, .row-sub {
  color: var(--muted);
  line-height: 1.45;
}

.option-line { margin: 8px 0 0; }

.banner {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 14px;
  text-align: center;
  color: var(--gold-deep);
  background: rgba(227, 194, 122, 0.1);
  border: 1px solid var(--line);
}

.rules {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.rule {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
  padding: 8px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.rule img {
  width: 34px;
  max-width: 34px;
  min-width: 0;
  height: auto;
  flex: none;
}

.rule b, .rule small { display: block; overflow-wrap: anywhere; }
.rule b { font-size: 13px; line-height: 1.2; }
.rule b { font-size: 13px; }
.rule small { color: var(--muted); font-size: 12px; }

.meter { margin-top: 16px; }

.meter-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  font-weight: 600;
}

.bar {
  height: 6px;
  margin: 8px 0;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold));
}

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

.table-wrap {
  margin-top: 16px;
}

.table-kicker {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 700;
}

.table {
  max-width: 100%;
  overflow-x: auto;
  padding: 52px 10px 18px;
  border-radius: 22px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(227, 194, 122, 0.16), transparent 46%),
    var(--felt);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), var(--shadow);
}

.table-wrap {
  max-width: 100%;
  min-width: 0;
}

.table-kicker {
  max-width: 100%;
}

.line {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: max-content;
  min-width: 100%;
  justify-content: flex-start;
  padding: 0 2px 2px;
}

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

.slot:has(.is-turning) {
  z-index: 4;
  animation: table-kick 0.72s linear;
}

.slot-name {
  height: 2.7em;
  margin: 0 0 6px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  color: var(--ivory);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
}

.slot-name small {
  display: block;
  font-size: 10px;
  font-weight: 700;
}

.slot.is-you .slot-name { color: #f0b4aa; }
.slot.kind-sou .slot-name small { color: #b7d4c4; }
.slot.kind-dragon .slot-name small { color: #f0b4aa; }

.tile-hit, .tile-still {
  position: relative;
  width: 70px;
  height: auto;
  padding: 0;
  border: 0;
  background: transparent;
}

.tile-hit { cursor: pointer; }

@property --face {
  syntax: "<length>";
  inherits: true;
  initial-value: 42px;
}

@property --side {
  syntax: "<length>";
  inherits: true;
  initial-value: 8px;
}

@property --lit {
  syntax: "<number>";
  inherits: true;
  initial-value: 1;
}

.bone {
  --w: 42px;
  --h: 56px;
  --d: 8px;
  --face: 42px;
  --side: 8px;
  --lit: 1;
  --flash: #fff6d8;
  position: relative;
  display: block;
  width: 70px;
  height: var(--h);
  margin: 0 auto 4px;
  transform: perspective(680px) rotateX(3.5deg);
  transform-origin: center bottom;
}

.bone.is-sou { --flash: #d9ffe8; }
.bone.is-dragon { --flash: #ffd0c8; }

.bone-core {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: calc(var(--face) + var(--side));
  transform: translateX(-50%);
}

.bone-top { display: none; }

.bone-body {
  position: relative;
  z-index: 1;
  display: block;
  width: var(--face);
  height: var(--h);
  overflow: hidden;
  border-radius: 4px 0 0 5px;
  filter: brightness(var(--lit));
  background: #f4f6f4;
  box-shadow: inset 0 0 0 1px rgba(150, 164, 156, 0.45);
}

.bone-shirt {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: inherit;
  background:
    radial-gradient(120% 80% at 18% 0%, rgba(255, 236, 190, 0.55), transparent 42%),
    linear-gradient(180deg, #ffb347 0%, #f08a1c 46%, #e26508 100%);
}

.bone-shirt::after {
  content: "";
  position: absolute;
  top: -45%;
  left: -55%;
  width: 42%;
  height: 190%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.35) 18%,
    rgba(255, 255, 255, 0.52) 40%,
    rgba(255, 255, 255, 0.68) 64%,
    rgba(255, 255, 255, 0.42) 86%,
    transparent 100%
  );
  transform: rotate(18deg);
  animation: shirt-gloss 2.8s ease-in-out infinite;
}

@keyframes shirt-gloss {
  0% {
    transform: translateX(-30%) rotate(18deg);
    opacity: 0.55;
  }
  100% {
    transform: translateX(460%) rotate(18deg);
    opacity: 0.88;
  }
}

.bone-mark {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  padding: 8% 11%;
  box-sizing: border-box;
  object-fit: fill;
  object-position: center;
  display: block;
}

.bone-body .reveal { display: none; }
.bone.is-open .bone-shirt { display: none; }
.bone.is-open .reveal { display: block; }

.bone.is-closed:not(.is-open) .bone-body {
  background: #f08a1c;
  box-shadow: none;
}

.bone.is-closed:not(.is-open) .bone-side {
  background: linear-gradient(
    90deg,
    #e87812 0 19%,
    #e7eeea 19%,
    #d5dfda 58%,
    #c5d0ca 100%
  );
  box-shadow: none;
}

.bone.is-turning {
  animation: tile-turn 0.72s linear forwards;
  z-index: 5;
}

.bone.is-turning::before {
  content: "";
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 18%;
  width: 10px;
  height: 64px;
  margin-left: -5px;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(90deg, transparent, #fff 35%, var(--flash) 50%, #fff 65%, transparent);
  filter: blur(0.4px);
  animation: tile-slash 0.72s linear forwards;
}

@keyframes tile-turn {
  0% {
    --face: 42px;
    --side: 8px;
    --lit: 1;
    transform: perspective(680px) translateY(0) rotateX(3.5deg);
  }
  10% {
    --face: 40px;
    --side: 10px;
    --lit: 1;
    transform: perspective(680px) translateY(3px) rotateX(5.5deg);
  }
  22% {
    --face: 22px;
    --side: 26px;
    --lit: 0.75;
    transform: perspective(680px) translateY(-20px) rotateX(14deg);
  }
  36% {
    --face: 2px;
    --side: 34px;
    --lit: 0.4;
    transform: perspective(680px) translateY(-24px) rotateX(16deg);
  }
  48% {
    --face: 34px;
    --side: 14px;
    --lit: 1.15;
    transform: perspective(680px) translateY(-10px) rotateX(8deg);
  }
  60% {
    --face: 46px;
    --side: 6px;
    --lit: 1.25;
    transform: perspective(680px) translateY(3px) rotateX(2deg);
  }
  74% {
    --face: 39px;
    --side: 10px;
    --lit: 1;
    transform: perspective(680px) translateY(-6px) rotateX(4.5deg);
  }
  100% {
    --face: 42px;
    --side: 8px;
    --lit: 1;
    transform: perspective(680px) translateY(0) rotateX(3.5deg);
  }
}

@keyframes tile-slash {
  0%, 28% { opacity: 0; transform: scaleX(0.3) scaleY(0.5); }
  36% { opacity: 1; transform: scaleX(7) scaleY(1.05); }
  50% { opacity: 0; transform: scaleX(12) scaleY(1.2); }
  100% { opacity: 0; transform: scaleX(12) scaleY(1.2); }
}

@keyframes table-kick {
  0%, 56% { transform: none; }
  64% { transform: translateY(2px); }
  74% { transform: translateY(-1px); }
  100% { transform: none; }
}

.bone-side {
  position: absolute;
  z-index: 3;
  top: 0;
  right: 0;
  width: var(--side);
  height: var(--h);
  background: linear-gradient(90deg, #e7eeea 0%, #d5dfda 55%, #c5d0ca 100%);
  border-radius: 0 4px 5px 0;
  box-shadow: inset 1px 0 0 rgba(255, 255, 255, 0.7);
  overflow: hidden;
}

.bone-side::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.8), transparent);
  transform: translateX(-130%);
}

.bone.is-turning .bone-side::after {
  animation: edge-pass 0.72s linear forwards;
}

@keyframes edge-pass {
  0% { transform: translateX(-140%); }
  48% { transform: translateX(0); }
  100% { transform: translateX(150%); }
}

.bone-foot { display: none; }

.kicker {
  margin: 0 0 14px;
  font-size: 18px;
  font-weight: 700;
}

.caption {
  margin: 8px 0 0;
  font-size: 14px;
  line-height: 1.45;
}

.deck, .result {
  position: relative;
  width: min(54vw, 210px);
  margin: 0 auto;
  aspect-ratio: 3 / 4;
}

.deck { margin-bottom: 36px; }

.shadow {
  position: absolute;
  inset: 0;
  background: url("/tiles/Back.svg") center / contain no-repeat;
  filter: brightness(0.72);
}

.shadow.one { transform: translate(10px, 10px); }
.shadow.two { transform: translate(18px, 18px); }

.tile-hit {
  perspective: 900px;
}

.tile-3d {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.tile-hit.is-flipped .tile-3d {
  transform: rotateY(180deg);
}

.tile-3d img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  backface-visibility: hidden;
  filter: drop-shadow(0 16px 16px rgba(0, 0, 0, 0.38));
}

.tile-3d .front { transform: rotateY(180deg); }

.gold {
  width: 100%;
  margin-top: 8px;
  border: 0;
  border-radius: 16px;
  padding: 15px 18px;
  color: #2a1c09;
  font-weight: 800;
  background: linear-gradient(180deg, #f3d7a2, #c49645);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.gold:disabled, .tile-btn:disabled { opacity: 0.65; }

.result img {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 16px 16px rgba(0, 0, 0, 0.38));
}

.seal {
  position: absolute;
  right: 0;
  bottom: 10px;
  width: 108px;
  height: 108px;
  display: grid;
  place-items: center;
  padding: 10px;
  border-radius: 50%;
  border: 3px solid currentColor;
  box-shadow: inset 0 0 0 1px currentColor;
  background: rgba(244, 239, 228, 0.94);
  color: #355e49;
  font-family: Palatino, "Palatino Linotype", "Times New Roman", serif;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transform: rotate(-12deg);
  animation: stamp 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.seal.dragon { color: #9d2c22; }

.chronicle { margin-top: 26px; }

.chronicle h2, .waiting h2 {
  margin: 0 0 4px;
  font-size: 30px;
}

.hint { margin: 0 0 12px; }

.rows, .chips { list-style: none; margin: 0; padding: 0; }

.rows { display: grid; gap: 10px; }

.row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-width: 0;
  padding: 10px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.row.is-you {
  background: rgba(227, 194, 122, 0.09);
  border-color: rgba(227, 194, 122, 0.65);
}

.row img {
  width: 64px;
  max-width: 64px;
  min-width: 0;
  height: auto;
  filter: drop-shadow(0 8px 8px rgba(0, 0, 0, 0.32));
}

.row-top {
  display: flex;
  gap: 8px;
  align-items: baseline;
  min-width: 0;
}

.order {
  flex: none;
  color: var(--gold-deep);
  font-weight: 800;
}

.name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.you-tag {
  flex: none;
  color: #2a1c09;
  background: var(--gold);
  border-radius: 99px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.row-sub { margin-top: 2px; font-size: 14px; }
.kind-dragon { color: var(--cinnabar); }
.kind-sou { color: var(--bamboo); }
.time { font-size: 12px; }

.empty {
  margin: 0;
  padding: 16px;
  border-radius: 18px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
}

.waiting { margin-top: 22px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(16, 36, 28, 0.06);
  border: 1px solid rgba(16, 36, 28, 0.12);
  font-size: 14px;
}

.chip.is-you { border-color: var(--gold-deep); color: var(--gold-deep); }
.chip small { color: var(--muted); }

.footer {
  margin-top: 28px;
  font-size: 12px;
  text-align: center;
}

.footer a { color: var(--gold-deep); }

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

@keyframes stamp {
  from { opacity: 0; transform: rotate(-12deg) scale(1.35); }
  to { opacity: 1; transform: rotate(-12deg) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .bone.is-turning,
  .bone.is-turning::before,
  .bone.is-turning .bone-side::after,
  .slot:has(.is-turning),
  .bone-shirt::after,
  .seal { animation: none; transition: none; }
}
