:root {
  --tile-w: 64px;
  --tile-h: 84px;
  --tile-depth: 18px;
  --tile-gap: 2px;
  --layer-gap: 5px;
  --tilt: 0deg;
  --fit: 1;
  --yaw: 0deg;
  --pitch: 0deg;
  --shadow-x: 0px;
  --shadow-y: 0px;

  --bg: #0e2a24;
  --bg-2: #071713;
  --bg-glow: rgba(71, 138, 112, 0.18);
  --pattern-color: rgba(255, 255, 255, 0.028);
  --text: #f7efdc;
  --muted: rgba(247, 239, 220, 0.62);
  --faint: rgba(247, 239, 220, 0.38);
  --panel: rgba(8, 23, 20, 0.7);
  --panel-strong: rgba(10, 27, 23, 0.94);
  --panel-soft: rgba(255, 255, 255, 0.045);
  --border: rgba(216, 181, 106, 0.2);
  --border-strong: rgba(216, 181, 106, 0.38);
  --input-bg: rgba(0, 0, 0, 0.22);
  --gold: #d8b56a;
  --gold-bright: #f0d492;
  --gold-soft: rgba(216, 181, 106, 0.14);
  --danger: #e07b66;
  --success: #82c9a3;
  --tile-ivory: #f5ead4;
  --tile-ivory-2: #e4d2b2;
  --tile-edge: #b99a70;
  --tile-side: #d3bd98;
  --mat: #123a32;
  --mat-2: #0a241f;
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow-lg: 0 30px 80px rgba(0, 0, 0, 0.48);
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: Georgia, "Times New Roman", "Songti SC", "Noto Serif CJK SC", serif;
}

body[data-bg-preset="wood"] {
  --bg: #24160f;
  --bg-2: #120a07;
  --bg-glow: rgba(147, 96, 58, 0.18);
}
body[data-bg-preset="emerald"] {
  --bg: #0f4a3c;
  --bg-2: #06251d;
  --bg-glow: rgba(70, 175, 140, 0.16);
}
body[data-bg-preset="sakura"] {
  --bg: #351b28;
  --bg-2: #1b0c14;
  --bg-glow: rgba(182, 100, 130, 0.16);
}
body[data-bg-preset="ocean"] {
  --bg: #0d2436;
  --bg-2: #06121c;
  --bg-glow: rgba(65, 136, 180, 0.16);
}
body[data-bg-preset="sand"] {
  --bg: #d9c7a5;
  --bg-2: #bda77f;
  --bg-glow: rgba(255, 244, 210, 0.42);
}

body.light-bg {
  --text: #1b2924;
  --muted: rgba(27, 41, 36, 0.64);
  --faint: rgba(27, 41, 36, 0.42);
  --panel: rgba(255, 250, 238, 0.78);
  --panel-strong: rgba(255, 252, 246, 0.95);
  --panel-soft: rgba(34, 44, 39, 0.06);
  --border: rgba(78, 63, 39, 0.18);
  --border-strong: rgba(78, 63, 39, 0.34);
  --input-bg: rgba(255, 255, 255, 0.55);
  --pattern-color: rgba(52, 48, 36, 0.045);
  --gold: #9a742c;
  --gold-bright: #b58a36;
  --gold-soft: rgba(154, 116, 44, 0.13);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

[hidden] {
  display: none !important;
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

.icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

.scene {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 34%, var(--bg-glow), transparent 42%),
    radial-gradient(circle at 50% 110%, var(--bg-2), transparent 62%),
    linear-gradient(160deg, var(--bg-2), var(--bg) 46%, var(--bg-2));
  perspective: 2600px;
  perspective-origin: 50% 50%;
  touch-action: none;
}

.scene-pattern {
  position: absolute;
  inset: -12%;
  opacity: 0.7;
  background-image:
    repeating-linear-gradient(116deg, transparent 0 37px, var(--pattern-color) 37px 38px, transparent 38px 76px),
    radial-gradient(circle at 30% 20%, var(--pattern-color), transparent 34%),
    radial-gradient(circle at 75% 70%, var(--pattern-color), transparent 40%);
  pointer-events: none;
}

.scene-glow {
  position: absolute;
  width: min(90vw, 1200px);
  height: min(58vw, 760px);
  left: 50%;
  top: 54%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.36), rgba(0, 0, 0, 0.12) 46%, transparent 72%);
  filter: blur(18px);
  opacity: 0.7;
  pointer-events: none;
}

.camera {
  position: absolute;
  left: 50%;
  top: calc(50% + var(--stage-shift, 0px));
  width: var(--board-w, 1000px);
  height: var(--board-h, 700px);
  transform-style: preserve-3d;
  transform: translate(-50%, -50%) translate3d(calc(var(--pan-x, 0px) + var(--parallax-x, 0px)), calc(var(--pan-y, 0px) + var(--parallax-y, 0px)), 0) scale(var(--fit)) rotateY(var(--yaw)) rotateX(var(--pitch));
  transform-origin: 50% 50%;
  will-change: transform;
}

.board {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform: rotateX(var(--tilt));
  transform-origin: 50% 50%;
}

.shadow-layer,
.tiles-layer {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.shadow-layer {
  pointer-events: none;
  transform: translate3d(var(--shadow-x, 0px), var(--shadow-y, 0px), 0);
}

.tile-layer {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  pointer-events: none;
}

.tile-shadow {
  position: absolute;
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: 6px;
  background: transparent;
  box-shadow:
    0 4px 7px rgba(0, 0, 0, 0.44),
    0 9px 16px rgba(0, 0, 0, 0.26);
  opacity: var(--shadow-op, 0.3);
  transform: translate3d(1px, 3px, var(--shadow-z, -3px));
  pointer-events: none;
}

body.view-static .tile-shadow {
  opacity: 1;
  box-shadow:
    0 calc(7px + var(--shadow-layer, 0) * 2px)
      calc(8px + var(--shadow-layer, 0) * 2px)
      rgba(0, 0, 0, 0.62),
    0 calc(16px + var(--shadow-layer, 0) * 4px)
      calc(20px + var(--shadow-layer, 0) * 4px)
      rgba(0, 0, 0, 0.44),
    0 calc(26px + var(--shadow-layer, 0) * 6px)
      calc(32px + var(--shadow-layer, 0) * 6px)
      rgba(0, 0, 0, 0.26);
  transform: translate3d(0, 0, var(--shadow-z, -3px));
}

.tile {
  position: absolute;
  width: var(--tile-w);
  height: var(--tile-h);
  transform-style: preserve-3d;
  transform: translate3d(var(--x), var(--y), var(--z));
  pointer-events: none;
}

.tile-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform: translate3d(0, var(--float-y, 0px), var(--lift, 0px)) scale(var(--tile-scale, 1));
  transition: transform 150ms ease;
  pointer-events: none;
}

.tile-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 7px 7px 8px;
  border: 1px solid rgba(139, 105, 61, 0.34);
  border-radius: 6px;
  background:
    linear-gradient(148deg, rgba(255, 255, 255, 0.94) 0%, rgba(255, 250, 235, 0.62) 26%, transparent 52%),
    linear-gradient(145deg, var(--tile-ivory) 0%, var(--tile-ivory-2) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.92),
    inset 0 -2px 4px rgba(117, 84, 43, 0.2),
    1px 2px 0 -1px rgba(163, 132, 90, 0.5);
  transform: translateZ(var(--tile-depth));
  backface-visibility: hidden;
  pointer-events: auto;
  touch-action: manipulation;
}

body.tiles-raster .tile-face {
  background-color: #f6e9d0;
  background-image: var(--face-img, none);
  background-repeat: no-repeat;
  background-position: 50% 50%;
  background-size: 100% 100%;
}

.tile-face::before {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 4px;
  border: 1px solid rgba(115, 83, 43, 0.13);
  pointer-events: none;
}

body.tiles-raster .tile-face::before {
  content: none;
}

.tile-symbol {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  pointer-events: none;
}

.tile-side {
  position: absolute;
  background: var(--tile-side);
  backface-visibility: visible;
  pointer-events: auto;
}

.side-n,
.side-s {
  width: var(--tile-w);
  height: var(--tile-depth);
  left: 0;
}

.side-n {
  top: calc(var(--tile-depth) * -0.5);
  transform: translateZ(calc(var(--tile-depth) * 0.5)) rotateX(90deg);
  background: linear-gradient(to bottom, #e0cfb0, #a98a5e);
}

.side-s {
  top: calc(var(--tile-h) - var(--tile-depth) * 0.5);
  transform: translateZ(calc(var(--tile-depth) * 0.5)) rotateX(-90deg);
  background: linear-gradient(to top, #8f7048, #d8c5a1);
}

.side-e,
.side-w {
  width: var(--tile-depth);
  height: var(--tile-h);
  top: 0;
}

.side-e {
  left: calc(var(--tile-w) - var(--tile-depth) * 0.5);
  transform: translateZ(calc(var(--tile-depth) * 0.5)) rotateY(90deg);
  background: linear-gradient(to right, #a3845a, #d6c19d);
}

.side-w {
  left: calc(var(--tile-depth) * -0.5);
  transform: translateZ(calc(var(--tile-depth) * 0.5)) rotateY(-90deg);
  background: linear-gradient(to left, #96764c, #ddcbaa);
}

.tile.is-free .tile-face {
  cursor: pointer;
}

.tile:focus-visible .tile-face {
  outline: 2px solid var(--gold-bright);
  outline-offset: 3px;
}

body.show-free .tile.is-free:not(.is-selected) .tile-face {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    inset 0 -2px 4px rgba(117, 84, 43, 0.2),
    inset 0 0 0 1px rgba(110, 79, 38, 0.22),
    0 0 0 1px rgba(216, 181, 106, 0.42),
    0 0 18px rgba(216, 181, 106, 0.13);
}

.tile.is-blocked .tile-face {
  filter: saturate(0.88) brightness(0.95);
  cursor: not-allowed;
}

body.tiles-raster .tile.is-blocked .tile-face {
  filter: none;
  background-image:
    linear-gradient(rgba(41, 32, 18, 0.11), rgba(41, 32, 18, 0.11)),
    var(--face-img, none);
  background-size: 100% 100%, 100% 100%;
}

.tile.is-free:not(.is-selected):hover .tile-inner,
.tile.is-free.is-hovered:not(.is-selected) .tile-inner {
  --lift: 6px;
  --float-y: -5px;
  --tile-scale: 1.03;
}

.tile.is-free:not(.is-selected):hover .tile-face,
.tile.is-free.is-hovered:not(.is-selected) .tile-face {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    inset 0 -2px 4px rgba(117, 84, 43, 0.16),
    0 0 0 1px rgba(240, 212, 146, 0.72),
    0 0 26px rgba(240, 212, 146, 0.26);
}

.tile.is-selected {
  z-index: 2;
}

.tile.is-selected .tile-inner {
  --lift: 12px;
  --float-y: -7px;
  --tile-scale: 1.06;
}

.tile.is-selected .tile-face {
  outline: 3px solid #ffd45c;
  outline-offset: 2px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 1),
    inset 0 0 0 2px rgba(255, 226, 146, 0.85),
    0 0 0 2px rgba(56, 34, 8, 0.85),
    0 0 0 7px rgba(255, 204, 90, 0.22),
    0 0 36px 10px rgba(255, 196, 72, 0.55);
}

body.tiles-raster .tile.is-selected .tile-face {
  background-image:
    linear-gradient(rgba(255, 210, 110, 0.18), rgba(255, 210, 110, 0.18)),
    var(--face-img, none);
  background-size: 100% 100%, 100% 100%;
}

.tile.is-hint .tile-face {
  animation: hintPulse 900ms ease-in-out infinite;
}

.tile.is-removed {
  display: none;
}

.tile.is-burning .tile-inner {
  animation: burnTile 420ms cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

.tile.is-burning .tile-face {
  animation: burnFace 420ms ease-out forwards;
}

.tile.is-shuffling .tile-inner {
  animation: shuffleTile 560ms cubic-bezier(0.3, 0.7, 0.3, 1);
}

.tile.is-dealing .tile-inner {
  animation: dealTile 440ms cubic-bezier(0.2, 0.8, 0.3, 1) both;
  animation-delay: var(--deal-delay, 0ms);
}

body.no-shadows .tile-shadow {
  display: none;
}

body.no-shadows .tile-face {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    inset 0 0 0 1px rgba(110, 79, 38, 0.22);
}

body.no-animations .tile-inner,
body.no-animations .tile-face,
body.no-animations .toast,
body.no-animations .score-pop {
  animation: none !important;
  transition: none !important;
}

.tile.is-shaking .tile-inner {
  animation: shakeTile 280ms ease;
}

@keyframes shakeTile {
  0%, 100% { transform: translateZ(var(--lift, 0px)) translateX(0); }
  25% { transform: translateZ(var(--lift, 0px)) translateX(-4px); }
  50% { transform: translateZ(var(--lift, 0px)) translateX(4px); }
  75% { transform: translateZ(var(--lift, 0px)) translateX(-2px); }
}

body.no-animations .tile.is-dealing {
  opacity: 1;
}

@keyframes hintPulse {
  0%, 100% {
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.95),
      0 0 0 1px rgba(240, 212, 146, 0.68),
      0 0 16px rgba(240, 212, 146, 0.22);
  }
  50% {
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.95),
      0 0 0 3px rgba(240, 212, 146, 0.9),
      0 0 38px rgba(240, 212, 146, 0.52);
  }
}

@keyframes burnTile {
  0% {
    transform: translateZ(var(--lift, 0px)) scale(1);
    opacity: 1;
    filter: brightness(1);
  }
  32% {
    transform: translateZ(calc(var(--lift, 0px) + 10px)) scale(1.035);
    opacity: 1;
    filter: brightness(1.55) sepia(0.24);
  }
  100% {
    transform: translateZ(calc(var(--lift, 0px) + 30px)) scale(0.28);
    opacity: 0;
    filter: brightness(0.1);
  }
}

@keyframes burnFace {
  0%, 30% {
    box-shadow: 0 0 0 2px rgba(255, 220, 140, 0.9), 0 0 38px rgba(255, 139, 62, 0.68);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 220, 140, 0), 0 0 0 rgba(255, 139, 62, 0);
  }
}

@keyframes shuffleTile {
  0% {
    transform: translateZ(var(--lift, 0px)) rotateZ(0deg);
    opacity: 1;
  }
  42% {
    transform: translateZ(calc(var(--lift, 0px) + 26px)) rotateZ(2deg);
    opacity: 0.35;
  }
  100% {
    transform: translateZ(var(--lift, 0px)) rotateZ(0deg);
    opacity: 1;
  }
}

@keyframes dealTile {
  0% {
    transform: translateZ(calc(var(--lift, 0px) + 42px)) scale(0.82);
    opacity: 0;
  }
  100% {
    transform: translateZ(var(--lift, 0px)) scale(1);
    opacity: 1;
  }
}

.hud {
  position: fixed;
  z-index: 30;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr) auto;
  grid-template-areas: "brand stats toolbar";
  align-items: center;
  gap: 18px;
  padding: 14px 18px 16px;
  background: linear-gradient(to bottom, rgba(3, 12, 10, 0.9), rgba(3, 12, 10, 0.64) 62%, transparent);
  color: var(--text);
  pointer-events: none;
}

body.light-bg .hud {
  background: linear-gradient(to bottom, rgba(255, 250, 238, 0.92), rgba(255, 250, 238, 0.68) 62%, transparent);
}

.hud > * {
  pointer-events: auto;
}

.brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 13px;
  color: #f7e7bd;
  background:
    radial-gradient(circle at 30% 22%, rgba(255, 255, 255, 0.3), transparent 42%),
    linear-gradient(145deg, #9c2d27, #5e1617);
  border: 1px solid rgba(240, 212, 146, 0.55);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35), inset 0 0 0 2px rgba(0, 0, 0, 0.16);
  font-family: var(--font-display);
  font-size: 25px;
  line-height: 1;
}

.brand-copy {
  min-width: 0;
}

.brand-copy h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: 0.18em;
  line-height: 1.08;
  white-space: nowrap;
}

.brand-layout {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.brand-layout:hover {
  color: var(--gold-bright);
}

.brand-chevron {
  font-size: 10px;
  opacity: 0.7;
}

.stats {
  grid-area: stats;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 2.4vw, 34px);
  min-width: 0;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 54px;
}

.stat-label {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
}

.stat strong {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  white-space: nowrap;
}

.stat strong.is-bumping {
  animation: valueBump 260ms ease-out;
}

#hudCombo {
  color: var(--gold-bright);
}

body.hide-timer .stat-time {
  display: none;
}

.toolbar {
  grid-area: toolbar;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  min-width: 0;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  font-size: 12px;
  line-height: 1;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

body.light-bg .tool-btn {
  background: rgba(30, 40, 35, 0.055);
}

.tool-btn:hover {
  background: rgba(216, 181, 106, 0.14);
  border-color: rgba(216, 181, 106, 0.28);
  color: var(--gold-bright);
}

.tool-btn:active {
  transform: translateY(1px);
}

.tool-btn:focus-visible,
.brand-layout:focus-visible,
.icon-btn:focus-visible,
.primary-btn:focus-visible,
.ghost-btn:focus-visible,
.sort-btn:focus-visible,
.menu-item:focus-visible,
.layout-card:focus-visible,
.bg-swatch:focus-visible,
.auth-tab:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 2px;
}

.tool-label {
  white-space: nowrap;
}

body.hide-timer #hudTime {
  display: none;
}

.statusbar {
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr minmax(120px, 26vw) auto;
  align-items: center;
  gap: 18px;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(3, 12, 10, 0.9), rgba(3, 12, 10, 0.54) 64%, transparent);
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

body.light-bg .statusbar {
  background: linear-gradient(to top, rgba(255, 250, 238, 0.92), rgba(255, 250, 238, 0.64) 64%, transparent);
}

.status-main {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.status-dot {
  opacity: 0.45;
}

.progress {
  height: 3px;
  border-radius: 99px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.1);
}

body.light-bg .progress {
  background: rgba(30, 40, 35, 0.12);
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #8c6a28, var(--gold-bright));
  transition: width 260ms ease;
}

.status-hint {
  text-align: right;
  white-space: nowrap;
}

@keyframes valueBump {
  0%, 100% { transform: scale(1); }
  45% { transform: scale(1.18); color: var(--gold-bright); }
}

.fx-canvas {
  position: fixed;
  inset: 0;
  z-index: 24;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.score-pop {
  position: fixed;
  z-index: 26;
  transform: translate(-50%, -50%);
  color: var(--gold-bright);
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.72);
  pointer-events: none;
  animation: scorePop 1000ms cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

@keyframes scorePop {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.7); }
  18% { opacity: 1; transform: translate(-50%, -58%) scale(1.08); }
  100% { opacity: 0; transform: translate(-50%, -120%) scale(0.94); }
}

.toast-stack {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(92vw, 520px);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  max-width: 100%;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-strong);
  color: var(--text);
  box-shadow: 0 12px 38px rgba(0, 0, 0, 0.3);
  font-size: 13px;
  text-align: center;
  animation: toastIn 220ms ease-out both;
  backdrop-filter: blur(10px);
}

.toast.is-error {
  border-color: rgba(224, 123, 102, 0.48);
  color: #ffd4ca;
}

.toast.is-success {
  border-color: rgba(130, 201, 163, 0.48);
  color: var(--success);
}

.toast.is-leaving {
  animation: toastOut 200ms ease-in both;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateY(-6px) scale(0.98); }
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background:
    radial-gradient(circle at 50% 40%, rgba(56, 113, 92, 0.24), transparent 46%),
    var(--bg);
  color: var(--text);
  transition: opacity 420ms ease, visibility 420ms ease;
}

.loading.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-seal {
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  border-radius: 22px;
  background: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.2), transparent 40%), linear-gradient(145deg, #9c2d27, #5a1416);
  border: 1px solid rgba(240, 212, 146, 0.5);
  color: #f7e7bd;
  font-family: var(--font-display);
  font-size: 38px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.4);
  animation: sealPulse 1800ms ease-in-out infinite;
}

.loading-title {
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: 0.12em;
}

.loading-sub {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
}

@keyframes sealPulse {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-3px) scale(1.03); }
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(2, 8, 7, 0.62);
  backdrop-filter: blur(8px);
  animation: modalIn 160ms ease-out;
}

.modal-card {
  width: min(560px, 100%);
  max-height: min(88vh, 860px);
  overflow: auto;
  padding: 24px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background:
    linear-gradient(150deg, rgba(255, 255, 255, 0.055), transparent 34%),
    var(--panel-strong);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  scrollbar-width: thin;
}

.modal-card::-webkit-scrollbar {
  width: 8px;
}

.modal-card::-webkit-scrollbar-thumb {
  background: rgba(216, 181, 106, 0.28);
  border-radius: 99px;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.modal-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 27px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.modal-intro {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13px;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
  flex-wrap: wrap;
}

.modal-actions.vertical {
  flex-direction: column;
  align-items: stretch;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}

.icon-btn:hover {
  background: var(--panel-soft);
  border-color: var(--border);
  color: var(--text);
}

.primary-btn,
.ghost-btn {
  min-height: 42px;
  padding: 0 18px;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: transform 130ms ease, filter 130ms ease, background 130ms ease, border-color 130ms ease;
}

.primary-btn {
  border: 1px solid rgba(240, 212, 146, 0.68);
  background: linear-gradient(145deg, #e0bf78, #b88a3d);
  color: #22190c;
  box-shadow: 0 10px 26px rgba(184, 138, 61, 0.22);
}

.primary-btn:hover {
  filter: brightness(1.06);
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--text);
}

.ghost-btn:hover {
  background: var(--gold-soft);
  border-color: var(--border-strong);
}

.primary-btn:active,
.ghost-btn:active {
  transform: translateY(1px);
}

.ghost-btn.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

.ghost-btn .icon {
  width: 16px;
  height: 16px;
}

.settings-section {
  padding: 15px 0;
  border-top: 1px solid var(--border);
}

.settings-section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.toggle-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 0;
  cursor: pointer;
}

.toggle-row > span:first-child {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.toggle-row strong {
  font-size: 13px;
  font-weight: 500;
}

.toggle-row small {
  color: var(--muted);
  font-size: 11px;
}

.toggle-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.toggle-ui {
  position: relative;
  width: 42px;
  height: 24px;
  flex: 0 0 auto;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.08);
  transition: background 160ms ease, border-color 160ms ease;
}

.toggle-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 180ms ease, background 180ms ease;
}

.toggle-input:checked + .toggle-ui {
  background: rgba(216, 181, 106, 0.3);
  border-color: var(--border-strong);
}

.toggle-input:checked + .toggle-ui::after {
  transform: translateX(18px);
  background: var(--gold-bright);
}

.toggle-input:focus-visible + .toggle-ui {
  outline: 2px solid var(--gold-bright);
  outline-offset: 2px;
}

.range-row {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px 0 4px;
  color: var(--muted);
  font-size: 12px;
}

.range-row > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.range-row output {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  height: 4px;
  margin: 5px 0;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--gold) var(--range-progress, 60%), rgba(255, 255, 255, 0.12) var(--range-progress, 60%));
  appearance: none;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  border: 2px solid #2a1c0e;
  background: var(--gold-bright);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  appearance: none;
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid #2a1c0e;
  background: var(--gold-bright);
  cursor: pointer;
}

.bg-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 8px 0 14px;
}

.bg-swatch {
  position: relative;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  background: transparent;
}

.bg-swatch span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.26), transparent 42%),
    var(--swatch);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22), 0 4px 14px rgba(0, 0, 0, 0.24);
}

.bg-swatch:hover span,
.bg-swatch.is-active span {
  box-shadow: inset 0 0 0 2px var(--gold-bright), 0 5px 18px rgba(0, 0, 0, 0.3);
}

.custom-color-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
}

input[type="color"] {
  width: 44px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  cursor: pointer;
}

.rating-card {
  width: min(760px, 100%);
}

.account-box {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-soft);
  margin-bottom: 14px;
}

.account-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.account-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.account-avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--gold-soft);
  border: 1px solid var(--border);
  color: var(--gold-bright);
  font-family: var(--font-display);
  font-size: 17px;
}

.account-name {
  font-weight: 600;
}

.account-meta {
  color: var(--muted);
  font-size: 11px;
}

.account-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  margin-bottom: 12px;
  border-radius: 10px;
  background: var(--input-bg);
}

.auth-tab {
  flex: 1;
  min-height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.auth-tab.is-active {
  background: var(--panel-strong);
  color: var(--text);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.auth-form {
  display: grid;
  gap: 9px;
}

.field {
  display: grid;
  gap: 5px;
}

.field span {
  color: var(--muted);
  font-size: 11px;
}

.field input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--input-bg);
  color: var(--text);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.field input:focus {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

.auth-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.auth-error {
  min-height: 16px;
  color: var(--danger);
  font-size: 11px;
}

.auth-note {
  color: var(--muted);
  font-size: 11px;
}

.rating-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 0 8px;
}

.rating-status {
  color: var(--muted);
  font-size: 12px;
}

.rating-table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 46vh;
}

.rating-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  min-width: 520px;
}

.rating-table th,
.rating-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.rating-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rating-table tbody tr:last-child td {
  border-bottom: 0;
}

.rating-table tbody tr.is-me {
  background: rgba(216, 181, 106, 0.12);
}

.rating-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.035);
}

.rating-table .col-rank {
  width: 62px;
  text-align: center;
}

.rating-table .col-player {
  min-width: 150px;
}

.rating-table td:nth-child(3),
.rating-table td:nth-child(4),
.rating-table td:nth-child(5) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rating-table th:nth-child(3),
.rating-table th:nth-child(4),
.rating-table th:nth-child(5) {
  text-align: right;
}

.sort-btn {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
}

.sort-btn:hover {
  color: var(--gold-bright);
}

.sort-btn.is-sorted {
  color: var(--gold-bright);
}

.sort-btn.is-sorted::after {
  content: " ↓";
  font-size: 10px;
}

.sort-btn.is-sorted.is-asc::after {
  content: " ↑";
}

.rating-me {
  margin-top: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--gold-soft);
  color: var(--text);
  font-size: 12px;
}

.rank-gold {
  color: var(--gold-bright);
}

.rank-silver {
  color: #d6dbe0;
}

.rank-bronze {
  color: #d3a273;
}

.modal-intro {
  color: var(--muted);
}

.layout-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.layout-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--text);
  text-align: left;
  overflow: hidden;
}

.layout-card:hover {
  border-color: var(--border-strong);
  background: var(--gold-soft);
}

.layout-card.is-active {
  border-color: var(--gold-bright);
  box-shadow: 0 0 0 1px var(--gold-soft), inset 0 0 30px rgba(216, 181, 106, 0.06);
}

.layout-card.is-locked {
  cursor: not-allowed;
}

.layout-preview {
  position: relative;
  height: 92px;
  border-radius: 9px;
  background:
    radial-gradient(ellipse at 50% 60%, rgba(216, 181, 106, 0.08), transparent 68%),
    rgba(0, 0, 0, 0.16);
  overflow: hidden;
}

.layout-preview svg {
  width: 100%;
  height: 100%;
  display: block;
}

.layout-lock {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.18);
  color: var(--muted);
}

.layout-card-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}

.layout-card-meta {
  color: var(--muted);
  font-size: 10px;
}

.layout-badge {
  padding: 2px 6px;
  border-radius: 99px;
  background: var(--gold-soft);
  color: var(--gold-bright);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.menu-card {
  width: min(620px, 100%);
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-soft);
  color: var(--text);
  text-align: left;
  font-size: 12px;
}

.menu-item:hover {
  border-color: var(--border-strong);
  background: var(--gold-soft);
}

.menu-item .icon {
  color: var(--gold);
}

.text-card {
  width: min(620px, 100%);
}

.prose {
  color: var(--muted);
  font-size: 13px;
}

.prose p {
  margin: 0 0 10px;
}

.prose h3 {
  margin: 16px 0 7px;
  color: var(--text);
  font-size: 13px;
  letter-spacing: 0.03em;
}

.prose ul {
  margin: 0 0 10px;
  padding-left: 20px;
}

.prose li {
  margin: 4px 0;
}

kbd {
  display: inline-block;
  min-width: 19px;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--input-bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 10px;
  text-align: center;
}

.pause-card {
  width: min(380px, 100%);
  text-align: center;
}

.pause-seal {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--gold-soft);
  color: var(--gold-bright);
  font-family: var(--font-display);
  font-size: 28px;
}

.pause-card h2 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
}

.modal#modalResult {
  z-index: 70;
}

.result-card {
  width: min(520px, 100%);
  text-align: center;
}

.result-emblem {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  border-radius: 22px;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.24), transparent 42%),
    linear-gradient(145deg, #a4312a, #5d1516);
  border: 1px solid rgba(240, 212, 146, 0.62);
  color: #f7e7bd;
  font-family: var(--font-display);
  font-size: 36px;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.36);
}

.result-card h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 600;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.result-stat {
  padding: 10px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-soft);
}

.result-stat span {
  display: block;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.result-stat strong {
  display: block;
  margin-top: 2px;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
}

.result-auth {
  margin-top: 14px;
  text-align: left;
}

.result-auth .account-box {
  margin-bottom: 0;
}

.result-auth .auth-form {
  margin-top: 4px;
}

.result-actions {
  justify-content: center;
}

.noscript {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: #0e2a24;
  color: #f7efdc;
  font-size: 18px;
}

@media (max-width: 1600px) {
  .tool-label {
    display: none;
  }

  .tool-btn {
    width: 38px;
    padding: 0;
    justify-content: center;
  }

  .hud {
    grid-template-columns: auto minmax(220px, 1fr) auto;
    gap: 12px;
  }
}

@media (max-width: 820px) {
  .hud {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand stats"
      "toolbar toolbar";
    gap: 8px 12px;
    padding: 10px 12px 12px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    font-size: 21px;
  }

  .brand-copy h1 {
    font-size: 17px;
  }

  .stats {
    justify-content: flex-end;
    gap: 13px;
  }

  .stat {
    min-width: 42px;
  }

  .stat strong {
    font-size: 17px;
  }

  .stat-label {
    font-size: 8px;
  }

  .toolbar {
    justify-content: center;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .tool-btn {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
  }

  .tool-btn .icon {
    width: 18px;
    height: 18px;
  }

  .statusbar {
    grid-template-columns: 1fr 34vw;
    gap: 10px;
    padding: 9px 12px calc(9px + env(safe-area-inset-bottom, 0px));
    font-size: 11px;
  }

  .status-hint {
    display: none;
  }

  .modal-card {
    padding: 18px;
    border-radius: 18px;
  }

  .modal-head h2 {
    font-size: 23px;
  }

  .menu-grid {
    grid-template-columns: 1fr;
  }

  .result-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .brand-layout {
    font-size: 10px;
  }

  .stats {
    gap: 9px;
  }

  .stat {
    min-width: 36px;
  }

  .stat strong {
    font-size: 15px;
  }

  .stat-label {
    letter-spacing: 0.08em;
  }

  .status-main {
    gap: 5px;
  }

  .statusbar {
    grid-template-columns: 1fr;
  }

  .progress {
    display: none;
  }

  .rating-table {
    min-width: 480px;
  }

  .layout-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .camera {
    transition: none;
  }

  .tile-inner {
    transition: none;
  }

  .loading-seal {
    animation: none;
  }

  .tile.is-dealing .tile-inner,
  .tile.is-burning .tile-inner,
  .tile.is-shuffling .tile-inner {
    animation-duration: 1ms !important;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .hud {
    padding: 6px 10px 8px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 18px;
  }

  .brand-copy h1 {
    font-size: 15px;
  }

  .stat strong {
    font-size: 15px;
  }

  .tool-btn {
    height: 32px;
  }

  .statusbar {
    padding: 6px 10px;
  }
}
