:root {
  --gold: #e4c16a;
  --gold-2: #f6e2a2;
  --ink: #0c0b12;
  --felt: #0f3d2c;
  --cream: #f7f0df;
  --danger: #c4494a;
  --safe: 18px;
  --pad-inline: clamp(14px, 3vw, 28px);
  --gap: clamp(8px, 1.5vw, 18px);
  --gap-sm: clamp(6px, 1vw, 12px);
  --gap-lg: clamp(16px, 3vw, 28px);
  --font-ui: "Segoe UI", Arial, Helvetica, sans-serif;
  --font-display: Georgia, "Times New Roman", serif;
  --font: var(--font-ui);
  --display: var(--font-display);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  --parallax-x: 0px;
  --parallax-y: 0px;
  font-family: var(--font);
  font-weight: 400;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  background: #07070c;
  color: var(--cream);
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  isolation: isolate;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: -24px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}

body::before {
  z-index: 0;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  filter: blur(18px) brightness(0.34) saturate(0.82);
  transform: scale(1.06);
}

body::after {
  z-index: 0;
  background:
    radial-gradient(ellipse at 50% 48%, transparent 24%, rgba(3, 4, 8, 0.48) 72%, rgba(3, 4, 8, 0.82) 100%),
    linear-gradient(90deg, rgba(2, 3, 7, 0.72), transparent 28%, transparent 72%, rgba(2, 3, 7, 0.72));
}

body[data-view="home"]::before {
  background-image: url("../assets/backgrounds/home_royal.webp");
  opacity: 0.46;
  animation: ambientSideDrift 18s ease-in-out infinite alternate;
}

body[data-view="game"]::before {
  background-image: url("../assets/backgrounds/table_royal.webp");
  opacity: 0.38;
  animation: ambientSideDrift 16s ease-in-out infinite alternate-reverse;
}

#ambient-particles {
  position: fixed;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease;
}

body[data-view="home"] #ambient-particles { opacity: 0.42; }
body[data-view="game"] #ambient-particles { opacity: 0.18; }
body.result-win #ambient-particles { opacity: 0.68; }

#ambient-particles i {
  position: absolute;
  left: var(--x);
  bottom: -4%;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: rgba(246, 226, 162, 0.72);
  box-shadow: 0 0 7px rgba(228, 193, 106, 0.38);
  opacity: 0;
  animation: ambientMote var(--duration) linear var(--delay) infinite;
}

@keyframes ambientMote {
  0% { transform: translate3d(0, 4vh, 0); opacity: 0; }
  16% { opacity: 0.32; }
  70% { opacity: 0.14; }
  100% { transform: translate3d(var(--drift), -108vh, 0); opacity: 0; }
}

body[data-view="home"]::after,
body[data-view="game"]::after {
  opacity: 1;
}

@keyframes ambientSideDrift {
  from { transform: scale(1.06) translate3d(-0.6%, -0.4%, 0); }
  to { transform: scale(1.11) translate3d(0.6%, 0.4%, 0); }
}

body[data-view="game"] .screen[data-screen="game"] .bg-table {
  animation: ambientTableDrift 16s ease-in-out infinite alternate;
}

@keyframes ambientTableDrift {
  from { transform: scale(1.08) translate3d(-0.35%, 0, 0); }
  to { transform: scale(1.12) translate3d(0.35%, -0.3%, 0); }
}

body[data-view="game"].is-card-animating::after {
  animation: sideActionPulse 0.6s ease-out;
}

@keyframes sideActionPulse {
  0%, 100% { filter: brightness(1); }
  45% { filter: brightness(1.24); }
}

@media (min-width: 700px) and (min-aspect-ratio: 4/3) {
  body::before {
    inset: -38px;
    filter: blur(24px) brightness(0.42) saturate(0.88) contrast(0.92);
  }
  body[data-view="home"]::before { opacity: 0.68; }
  body[data-view="game"]::before {
    opacity: 0.58;
    background-position: center 64%;
    filter: blur(28px) brightness(0.33) saturate(0.76) contrast(0.88);
  }
  body[data-view="game"] .screen[data-screen="game"] .bg-table {
    inset: -28px;
    filter: blur(22px) brightness(0.3) saturate(0.72) contrast(0.9);
  }
  body[data-view="game"] .table-stage {
    box-shadow: 0 16px 54px rgba(0, 0, 0, 0.58);
  }
  body::after {
    background:
      radial-gradient(ellipse at 50% 48%, transparent 18%, rgba(3, 4, 8, 0.34) 54%, rgba(3, 4, 8, 0.84) 100%),
      linear-gradient(90deg, rgba(2, 3, 8, 0.76), rgba(8, 12, 23, 0.18) 32%, rgba(8, 12, 23, 0.18) 68%, rgba(2, 3, 8, 0.76));
  }
  body[data-view="home"] .app,
  body[data-view="game"] .app {
    box-shadow:
      0 0 0 1px rgba(228, 193, 106, 0.14),
      0 22px 70px rgba(0, 0, 0, 0.66),
      0 0 90px rgba(34, 55, 83, 0.16);
  }
}

@media (max-width: 699px) and (orientation: portrait) {
  body[data-view="home"]::before,
  body[data-view="game"]::before {
    opacity: 0;
    animation: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  body::before,
  body[data-view="game"] .screen[data-screen="game"] .bg-table,
  body[data-view="game"].is-card-animating::after {
    animation: none;
  }
  #ambient-particles { display: none; }
  body[data-view="home"] .screen[data-screen="home"] .bg-home {
    animation: none;
    transform: scale(1.025);
    transition: none;
  }
}

img { display: block; max-width: 100%; pointer-events: none; object-fit: contain; object-position: center; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }

.app {
  width: min(100vw, 430px);
  height: 100dvh;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  background: #0b0b12;
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.65);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  z-index: 1;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}
.screen.is-active { display: flex; }

.bg-home, .bg-table {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
.bg-home { background-image: url("../assets/backgrounds/home_royal.webp"); }
.bg-table {
  background-image: url("../assets/backgrounds/table_royal.webp");
  background-position: center 68%;
}

body[data-view="home"] .screen[data-screen="home"] .bg-home {
  transform: translate3d(var(--parallax-x), var(--parallax-y), 0) scale(1.025);
  filter: brightness(0.98);
  transition: transform 0.28s ease-out;
  animation: homeLanternBreath 8s ease-in-out infinite;
}

@keyframes homeLanternBreath {
  0%, 100% { filter: brightness(0.97) saturate(0.98); }
  38% { filter: brightness(1.01) saturate(1.02); }
  62% { filter: brightness(0.985) saturate(1); }
}
.veil {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 70% at 50% 10%, rgba(212, 175, 90, 0.12), transparent 46%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.25), rgba(0, 0, 0, 0.55));
  pointer-events: none;
}

/* —— Home —— */
.screen[data-screen="home"].is-active {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}
.home-top {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--gap);
  padding:
    calc(12px + env(safe-area-inset-top))
    var(--pad-inline)
    0;
}
.home-top-right {
  display: flex;
  gap: var(--gap-sm);
  align-items: center;
}
.home-record-wrap {
  position: relative;
  z-index: 2;
  padding: var(--gap-sm) var(--pad-inline) 0;
}
.home-record-wrap .chip {
  width: fit-content;
  max-width: min(48vw, 180px);
  justify-content: flex-start;
}

.brand {
  position: relative;
  z-index: 2;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(28px, 6vh, 56px) var(--pad-inline) var(--gap);
  margin-top: auto;
  margin-bottom: auto;
}
.screen[data-screen="home"] .brand {
  min-height: 0;
  justify-content: center;
  margin: 0;
  padding:
    clamp(12px, 3.5dvh, 32px)
    var(--pad-inline)
    clamp(10px, 2dvh, 18px);
}
.brand-crest {
  width: clamp(72px, 18vw, 96px);
  height: clamp(72px, 18vw, 96px);
  margin: 0 auto;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, .65));
}
.brand-kicker {
  font-family: var(--font-ui);
  font-weight: 600;
  letter-spacing: 0.22em;
  font-size: clamp(10px, 2.7vw, 12px);
  color: var(--gold);
  text-transform: uppercase;
  margin-top: clamp(14px, 2.4vh, 22px);
}
.brand h1 {
  font-family: var(--display);
  font-size: clamp(34px, 9vw, 44px);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: 0.015em;
  margin: clamp(10px, 1.8vh, 16px) 0 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.52);
}
.brand h1 span { color: var(--gold-2); display: block; font-size: 22px; letter-spacing: 0.12em; }
.tagline {
  font-family: var(--font-ui);
  color: rgba(247, 240, 223, 0.78);
  font-size: clamp(12px, 3.2vw, 14px);
  font-weight: 400;
  letter-spacing: 0.02em;
  margin-top: clamp(10px, 1.6vh, 16px);
  max-width: 18em;
  line-height: 1.4;
}

.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: url("../assets/decorative/button_secondary.webp") center / 100% 100% no-repeat;
  border: 0;
  border-radius: 999px;
  padding: 6px 12px 6px 6px;
  min-height: 40px;
  max-width: 100%;
  overflow: hidden;
}
.chip img { width: 28px; height: 28px; flex: 0 0 auto; object-fit: contain; }
.chip b,
.chip span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.icon-btn {
  width: clamp(42px, 11vw, 48px);
  height: clamp(42px, 11vw, 48px);
  flex: 0 0 auto;
  background: url("../assets/decorative/icon_button.webp") center / contain no-repeat;
  display: grid;
  place-items: center;
}
.icon-btn img {
  width: 52%;
  height: 52%;
  object-fit: contain;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.55));
}

.menu {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap-sm);
  width: 100%;
  padding:
    var(--gap-lg)
    var(--pad-inline)
    calc(18px + env(safe-area-inset-bottom));
  box-sizing: border-box;
}
.menu .menu-primary {
  width: min(78%, 320px);
  margin-inline: auto;
  margin-bottom: clamp(6px, 1.2vh, 12px);
}
.menu .menu-secondary {
  width: min(66%, 280px);
  margin-inline: auto;
}

.difficulty-sheet {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: clamp(14px, 4vw, 26px);
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 46%, rgba(34, 47, 68, 0.24), transparent 46%),
    rgba(2, 4, 9, 0.82);
  backdrop-filter: blur(6px) saturate(0.75);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
.difficulty-sheet::before {
  content: "";
  position: absolute;
  inset: 8%;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 50%, rgba(228, 193, 106, 0.13), transparent 34%),
    radial-gradient(circle at 24% 30%, rgba(246, 226, 162, 0.08) 0 1px, transparent 2px),
    radial-gradient(circle at 76% 67%, rgba(228, 193, 106, 0.07) 0 1px, transparent 2px);
  filter: blur(0.4px);
  opacity: 0.8;
}
.difficulty-sheet.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.difficulty-panel {
  position: relative;
  isolation: isolate;
  width: min(94%, 390px);
  padding:
    clamp(28px, 6vw, 36px)
    clamp(20px, 5.5vw, 30px)
    clamp(20px, 4.5vw, 26px);
  background:
    radial-gradient(ellipse at 50% 7%, rgba(228, 193, 106, 0.13), transparent 38%),
    linear-gradient(155deg, rgba(16, 25, 40, 0.98), rgba(5, 9, 17, 0.99) 58%, rgba(11, 16, 28, 0.98));
  border: 1px solid rgba(228, 193, 106, 0.68);
  border-radius: 18px;
  box-shadow:
    0 28px 64px rgba(0, 0, 0, 0.78),
    0 0 34px rgba(185, 137, 50, 0.12),
    inset 0 1px 0 rgba(255, 239, 186, 0.16),
    inset 0 0 42px rgba(0, 0, 0, 0.44);
  text-align: center;
  transform: translateY(8px) scale(0.985);
  transition: transform 0.24s cubic-bezier(.22,.8,.3,1);
}
.difficulty-panel::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 5px;
  border-radius: 14px;
  pointer-events: none;
  background:
    linear-gradient(rgba(4, 8, 15, 0.64), rgba(5, 8, 15, 0.76)),
    url("../assets/decorative/panel_royal.webp") center / 94% 94% no-repeat;
  opacity: 0.38;
}
.difficulty-panel::after {
  content: "";
  position: absolute;
  z-index: 3;
  inset: 7px;
  border: 1px solid rgba(228, 193, 106, 0.16);
  border-radius: 12px;
  box-shadow: inset 0 0 20px rgba(228, 193, 106, 0.05);
  pointer-events: none;
}
.difficulty-panel > * {
  position: relative;
  z-index: 1;
}
.difficulty-sheet.is-open .difficulty-panel { transform: translateY(0) scale(1); }
.difficulty-kicker {
  color: #d9ad56;
  font-size: clamp(9px, 2.4vw, 11px);
  font-weight: 700;
  letter-spacing: 0.26em;
  line-height: 1;
  text-shadow: 0 0 12px rgba(228, 193, 106, 0.28);
  text-transform: uppercase;
}
.difficulty-panel h2 {
  margin: 10px 0 clamp(25px, 5.5vw, 32px);
  color: #fff0bc;
  font-family: var(--font-display);
  font-size: clamp(26px, 7vw, 34px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 0.015em;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.72), 0 0 18px rgba(228, 193, 106, 0.15);
}
.difficulty-panel h2::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: clamp(-15px, -3.5vw, -11px);
  width: min(54%, 150px);
  height: 1px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, transparent, rgba(228, 193, 106, 0.76), transparent);
  box-shadow: 0 0 7px rgba(228, 193, 106, 0.28);
}
.difficulty-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(12px, 3vw, 16px);
}
.difficulty-option {
  position: relative;
  isolation: isolate;
  min-width: 0;
  min-height: clamp(78px, 20vw, 92px);
  padding: 15px 10px 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: rgba(247, 240, 223, 0.82);
  background:
    radial-gradient(circle at 50% 0%, rgba(112, 138, 173, 0.12), transparent 55%),
    linear-gradient(145deg, rgba(15, 25, 40, 0.94), rgba(5, 9, 17, 0.97));
  border: 1px solid rgba(208, 164, 79, 0.42);
  border-radius: 12px;
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.34),
    inset 0 1px 0 rgba(255, 242, 199, 0.06),
    inset 0 0 18px rgba(0, 0, 0, 0.2);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  transition:
    transform 0.18s cubic-bezier(.22,.8,.3,1),
    border-color 0.18s ease,
    background 0.18s ease,
    box-shadow 0.18s ease,
    filter 0.18s ease;
}
.difficulty-option::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 3px;
  border: 1px solid rgba(246, 226, 162, 0.06);
  border-radius: 9px;
  pointer-events: none;
}
.difficulty-option b {
  color: #f7df9d;
  font-size: clamp(13px, 3.7vw, 16px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.085em;
  text-transform: uppercase;
}
.difficulty-option span {
  color: rgba(237, 232, 220, 0.66);
  font-size: clamp(10px, 2.7vw, 12px);
  line-height: 1;
  letter-spacing: 0.035em;
}
.difficulty-option.is-selected {
  border-color: rgba(255, 226, 145, 0.94);
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 224, 135, 0.23), transparent 55%),
    linear-gradient(145deg, rgba(91, 61, 25, 0.96), rgba(35, 25, 17, 0.98));
  box-shadow:
    0 9px 22px rgba(0, 0, 0, 0.42),
    0 0 20px rgba(228, 193, 106, 0.24),
    inset 0 1px 0 rgba(255, 244, 202, 0.26),
    inset 0 0 20px rgba(228, 193, 106, 0.1);
}
.difficulty-option.is-selected::before {
  border-color: rgba(255, 232, 167, 0.2);
}
.difficulty-option.is-selected::after {
  content: "Selected";
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -50%);
  padding: 3px 9px;
  color: #fff1bd;
  background: linear-gradient(180deg, #8c652d, #523713);
  border: 1px solid rgba(255, 228, 157, 0.72);
  border-radius: 999px;
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.55), 0 0 9px rgba(228, 193, 106, 0.2);
  font-size: 7px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  white-space: nowrap;
}
.difficulty-option:active {
  transform: translateY(1px) scale(0.982);
  transition-duration: 0.1s;
}
.difficulty-cancel {
  min-width: 112px;
  margin-top: clamp(18px, 4vw, 23px);
  padding: 9px 20px;
  color: rgba(247, 240, 223, 0.74);
  background: linear-gradient(180deg, rgba(25, 34, 48, 0.56), rgba(7, 11, 19, 0.68));
  border: 1px solid rgba(228, 193, 106, 0.24);
  border-radius: 999px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  transition: color 0.16s ease, border-color 0.16s ease, background 0.16s ease, transform 0.12s ease;
}
.difficulty-cancel:active { transform: scale(0.97); }

@media (hover: hover) and (pointer: fine) {
  .difficulty-option:hover {
    transform: translateY(-3px) scale(1.012);
    border-color: rgba(244, 208, 129, 0.76);
    background:
      radial-gradient(circle at 50% 0%, rgba(228, 193, 106, 0.19), transparent 58%),
      linear-gradient(145deg, rgba(24, 36, 54, 0.98), rgba(8, 13, 23, 0.98));
    box-shadow:
      0 12px 22px rgba(0, 0, 0, 0.4),
      0 0 15px rgba(228, 193, 106, 0.13),
      inset 0 1px 0 rgba(255, 242, 199, 0.1);
  }
  .difficulty-option.is-selected:hover {
    background:
      radial-gradient(circle at 50% 0%, rgba(255, 224, 135, 0.3), transparent 57%),
      linear-gradient(145deg, rgba(103, 70, 29, 0.98), rgba(39, 28, 18, 0.98));
    box-shadow:
      0 12px 25px rgba(0, 0, 0, 0.44),
      0 0 24px rgba(228, 193, 106, 0.3),
      inset 0 1px 0 rgba(255, 244, 202, 0.3);
  }
  .difficulty-cancel:hover {
    color: #f4dda2;
    border-color: rgba(228, 193, 106, 0.5);
    background: rgba(31, 39, 52, 0.72);
  }
}

@media (orientation: landscape) and (max-height: 440px) {
  .difficulty-panel {
    width: min(88%, 390px);
    padding: 16px 22px 12px;
    border-radius: 14px;
  }
  .difficulty-kicker { font-size: 8px; }
  .difficulty-panel h2 {
    margin: 5px 0 17px;
    font-size: clamp(19px, 5.5dvh, 23px);
  }
  .difficulty-panel h2::after { bottom: -9px; }
  .difficulty-list { gap: 9px 12px; }
  .difficulty-option {
    min-height: 52px;
    padding: 8px 7px 6px;
    gap: 4px;
    border-radius: 9px;
  }
  .difficulty-option b { font-size: 12px; }
  .difficulty-option span { font-size: 9px; }
  .difficulty-option.is-selected::after { padding: 2px 7px; font-size: 6px; }
  .difficulty-cancel {
    min-width: 96px;
    margin-top: 9px;
    padding: 5px 15px;
    font-size: 8px;
  }
}
.screen[data-screen="home"] .menu {
  padding-top: clamp(8px, 1.8dvh, 16px);
}
.screen[data-screen="home"] .menu .btn {
  line-height: 1.1;
}

@media (max-height: 720px) {
  .screen[data-screen="home"] .home-top {
    padding-top: calc(8px + env(safe-area-inset-top));
  }
  .screen[data-screen="home"] .home-record-wrap {
    padding-top: 4px;
  }
  .screen[data-screen="home"] .brand {
    padding-top: 8px;
    padding-bottom: 6px;
  }
  .screen[data-screen="home"] .brand-crest {
    width: clamp(54px, 12dvh, 72px);
    height: clamp(54px, 12dvh, 72px);
  }
  .screen[data-screen="home"] .brand-kicker {
    margin-top: 8px;
  }
  .screen[data-screen="home"] .brand h1 {
    margin-top: 6px;
    font-size: clamp(28px, 6dvh, 34px);
  }
  .screen[data-screen="home"] .tagline {
    margin-top: 6px;
    font-size: 12px;
    line-height: 1.3;
  }
  .screen[data-screen="home"] .menu {
    gap: 4px;
    padding-top: 6px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .screen[data-screen="home"] .menu .menu-primary {
    margin-bottom: 2px;
  }
  .screen[data-screen="home"] .menu .btn {
    min-height: clamp(42px, 8dvh, 48px);
    font-size: 12px;
  }
}

.btn {
  min-height: clamp(48px, 12vw, 54px);
  min-width: 0;
  max-width: 100%;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: var(--font-ui);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: clamp(12px, 3.4vw, 14px);
  width: 100%;
  padding: 0 clamp(12px, 4vw, 18px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  line-height: 1;
  box-sizing: border-box;
  flex-shrink: 0;
}
.btn img { width: 22px; height: 22px; flex: 0 0 auto; object-fit: contain; }
.btn-gold {
  background: url("../assets/decorative/button_primary.webp") center / 100% 100% no-repeat;
  color: #fff3ca;
  /* box-shadow: 0 10px 24px rgba(196, 154, 60, 0.28); */
  font-weight: 600;
  text-shadow: 0 2px 3px rgba(49,0,0,.9);
}
.btn-ghost {
  background: url("../assets/decorative/button_secondary.webp") center / 100% 100% no-repeat;
  border: 0;
  color: var(--gold-2);
  text-shadow: 0 2px 3px rgba(0,0,0,.9);
}
.btn:disabled {
  opacity: 0.42;
  cursor: default;
}

/* —— Panels —— */
.panel-screen {
  padding:
    calc(12px + env(safe-area-inset-top))
    var(--pad-inline)
    calc(16px + env(safe-area-inset-bottom));
  gap: var(--gap);
  overflow: hidden;
  align-items: center;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  width: min(92%, 680px);
}
.panel-head h2 {
  font-family: var(--display);
  font-size: clamp(21px, 5.6vw, 26px);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scroll-card {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  min-height: 0;
  width: min(92%, 680px);
  overflow: hidden;
  background: transparent;
  border-style: solid;
  border-color: transparent;
  border-width:
    clamp(52px, 13vw, 68px)
    clamp(36px, 9vw, 50px);
  border-image-source: url("../assets/decorative/panel_royal.webp");
  /* The side artwork begins farther inward than the top ornament. */
  border-image-slice: 150 220 150 220;
  border-image-width:
    clamp(52px, 13vw, 68px)
    clamp(36px, 9vw, 50px);
  border-image-outset: 0;
  border-image-repeat: stretch;
  border-radius: 0;
  padding: clamp(5px, 1.4vw, 9px);
  filter: drop-shadow(0 18px 28px rgba(0, 0, 0, 0.45));
}
.panel-inner,
.modal-inner {
  width: 100%;
  height: auto;
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  overflow: hidden;
  border: 1px solid rgba(228, 193, 106, 0.32);
  border-radius: 4px;
  background:
    radial-gradient(circle at 50% 0%, rgba(54, 80, 122, 0.3), transparent 48%),
    linear-gradient(180deg, rgba(22, 37, 64, 0.98), rgba(10, 22, 43, 0.99));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    inset 0 0 34px rgba(1, 7, 18, 0.48);
}
.panel-content,
.modal-content {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding:
    clamp(28px, 4dvh, 40px)
    clamp(24px, 4vw, 32px)
    clamp(30px, 4dvh, 40px);
  scrollbar-gutter: stable;
  scrollbar-width: none;
  -ms-overflow-style: none;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.panel-content::-webkit-scrollbar,
.modal-content::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}
.howto h3 {
  font-family: var(--display);
  color: var(--gold);
  margin: 12px 0 6px;
  font-size: clamp(15px, 4vw, 17px);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.01em;
}
.howto p, .howto li {
  font-family: var(--font-ui);
  font-size: clamp(13px, 3.5vw, 15px);
  font-weight: 400;
  line-height: 1.55;
  color: rgba(247, 240, 223, 0.88);
  overflow-wrap: anywhere;
  word-break: break-word;
}
.howto ol { padding-left: 20px; display: grid; gap: 9px; }

.setting-row {
  display: grid;
  grid-template-columns: minmax(64px, 1fr) minmax(104px, 46%);
  align-items: center;
  gap: var(--gap);
  min-height: 52px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(228, 193, 106, 0.15);
}
.setting-row > span,
.setting-row > label {
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  font-family: var(--font-ui);
  font-weight: 500;
  line-height: 1.35;
  font-size: clamp(13px, 3.5vw, 14px);
}
.setting-row input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(228, 193, 106, 0.3);
  background: rgba(0, 0, 0, 0.35);
  color: var(--cream);
  font-family: var(--font-ui);
  font-size: clamp(13px, 3.5vw, 14px);
  font-weight: 500;
  line-height: 1.2;
  padding: 0 12px;
  justify-self: end;
}
.setting-row .icon-btn { justify-self: end; }
.panel-content > p.settings-note {
  margin-top: var(--gap);
  margin-bottom: 2px;
  font-family: var(--font-ui);
  font-size: clamp(12px, 3.2vw, 13px);
  font-weight: 400;
  opacity: 0.75;
  line-height: 1.45;
  overflow-wrap: anywhere;
  max-width: 100%;
}

.load-wrap {
  position: relative;
  z-index: 2;
  margin-top: auto;
  padding: 0 var(--pad-inline) calc(36px + env(safe-area-inset-bottom));
}
.load-track {
  height: 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  border: 1px solid rgba(228, 193, 106, 0.25);
}
.load-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #c49a3c, #f6e2a2);
}
#load-label {
  margin-top: 10px;
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(4, 4, 8, 0.72);
  z-index: 20;
  padding: var(--pad-inline);
}
.overlay.is-open { display: grid; }
.modal {
  width: min(100%, 420px);
  max-height: min(88dvh, 620px);
  overflow: hidden;
  background: transparent;
  border: clamp(28px, 7vw, 38px) solid transparent;
  border-image: url("../assets/decorative/panel_royal.webp") 150 / clamp(28px, 7vw, 38px) / 0 stretch;
  border-radius: 0;
  padding: clamp(4px, 1.4vw, 8px);
  text-align: center;
  position: relative;
  box-sizing: border-box;
  filter: drop-shadow(0 22px 36px rgba(0, 0, 0, 0.58));
}
.modal-inner {
  height: auto;
  max-height: calc(min(88dvh, 620px) - clamp(64px, 16vw, 92px));
}
.modal-content {
  padding:
    clamp(28px, 5dvh, 40px)
    clamp(24px, 5vw, 32px)
    clamp(30px, 5dvh, 40px);
}
.result-crown {
  width: clamp(96px, 30vw, 130px);
  height: clamp(58px, 18vw, 72px);
  margin: 0 auto 8px;
  object-fit: contain;
  filter: drop-shadow(0 8px 18px rgba(255, 184, 46, .44));
}
.modal h3 {
  font-family: var(--display);
  font-size: clamp(24px, 6.5vw, 30px);
  font-weight: 700;
  letter-spacing: 0.01em;
  margin-bottom: 8px;
  line-height: 1.2;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  overflow-wrap: anywhere;
}
.modal p {
  font-family: var(--font-ui);
  font-size: clamp(13px, 3.5vw, 15px);
  font-weight: 400;
  color: rgba(247, 240, 223, 0.78);
  margin-bottom: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
  padding: 0 4px;
}
.modal .btn { margin-top: 8px; width: min(86%, 260px); margin-inline: auto; }
#result-coins {
  color: var(--gold-2);
  font-weight: 700;
  font-size: clamp(14px, 3.8vw, 16px);
}
.is-win h3 { color: var(--gold-2); }
.is-lose h3 { color: #f0b4b4; }

#toast {
  position: absolute;
  left: 50%;
  top: 16%;
  transform: translate(-50%, -12px);
  background: rgba(8, 8, 12, 0.88);
  border: 1px solid rgba(228, 193, 106, 0.45);
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  z-index: 16;
  font-size: 13px;
  letter-spacing: 0.04em;
  max-width: calc(100% - 2 * var(--pad-inline));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}
#toast.is-show { opacity: 1; transform: translate(-50%, 0); }
