:root {
  color-scheme: dark;
  --ink: #f6f0e3;
  --muted: #c1b6c8;
  --gold: #d9b46b;
  --tile: clamp(64px, 22vw, 146px);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  background:
    radial-gradient(ellipse at 50% -15%, #504264 0, transparent 48%),
    radial-gradient(ellipse at 8% 82%, #34233e 0, transparent 38%),
    linear-gradient(155deg, #201c2b, #15131d 68%, #1b1724);
}
button { font: inherit; }
.game-shell { width: min(960px, 100%); margin: auto; padding: 22px 16px 34px; }
.hero { text-align: center; padding: 2px 0 17px; }
.eyebrow { color: var(--gold); font-size: .7rem; font-weight: 850; letter-spacing: .23em; text-transform: uppercase; }
h1 { margin: 9px 0 4px; color: #fff9ef; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.15rem, 7.8vw, 4.5rem); font-weight: 600; letter-spacing: .025em; line-height: .98; text-shadow: 0 2px 22px #edce8050; }
h1 span { color: var(--gold); font-size: .62em; vertical-align: .13em; letter-spacing: .08em; }
.byline { margin: 9px 0 0; color: #d5cbd8; font-size: .93rem; font-weight: 550; letter-spacing: .02em; }
.details { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin: 15px auto 0; }
.details span { padding: 7px 13px; border: 1px solid #d7bd8055; border-radius: 999px; background: #ffffff08; color: #e8d7a8; font-size: .78rem; font-weight: 750; }
.play-panel { padding: clamp(12px, 3vw, 24px); border: 1px solid #d9bc754b; border-radius: 24px; background: linear-gradient(145deg, #292432eF, #1c1924f5); box-shadow: 0 22px 70px #09070e8a, inset 0 1px #fff1; }
.scorebar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 7px 14px; padding: 11px 14px; border: 1px solid #ffffff12; border-radius: 13px; background: #14121b99; color: #ded5df; font-size: .82rem; font-weight: 750; }
.scorebar strong { color: #f6e5b8; font-size: .92rem; }
.instruction { max-width: 690px; margin: 12px auto 15px; color: #d3c8d6; text-align: center; font-size: .86rem; line-height: 1.5; }
.board-frame { position: relative; overflow: hidden; max-width: 790px; margin: 0 auto; padding: 12px 8px 17px; border: 1px solid #d9bc7547; border-radius: 20px; background: radial-gradient(ellipse at 50% 30%, #47364b 0, #292230 54%, #201c28 100%); box-shadow: inset 0 0 35px #09071077, 0 8px 30px #07060b66; }
.board-frame::before { content: ""; position: absolute; inset: 8px; border: 1px solid #e2c78115; border-radius: 14px; pointer-events: none; }
.board { position: relative; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); justify-items: center; align-items: start; gap: 0 3px; width: 100%; max-width: 730px; min-height: clamp(390px, 116vw, 585px); margin: auto; padding: 5px 0 0; }
.pile { position: relative; z-index: 0; width: 100%; height: clamp(154px, 43vw, 210px); margin-bottom: -37px; isolation: isolate; }
.pile:nth-child(4n + 1) { transform: translateX(2%); }
.pile:nth-child(4n + 2) { transform: translateY(9px) translateX(-2%); }
.pile:nth-child(4n + 3) { transform: translateY(-4px) translateX(3%); }
.pile:nth-child(4n) { transform: translateY(8px) translateX(-3%); }
.game-button {
  position: absolute;
  left: var(--offset-x, 8%);
  top: var(--offset-y, 0px);
  z-index: calc(50 - var(--layer-index, 0));
  display: grid;
  place-items: center;
  width: min(84%, 104px);
  height: auto;
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  border: 2px solid #fff9;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 24%, var(--button-light), transparent 30%), radial-gradient(circle at 52% 54%, var(--button-color) 0 57%, var(--button-dark) 100%);
  box-shadow: inset -7px -9px 10px #100c2759, inset 4px 4px 8px #ffffff35, 0 7px 13px #09071291, 0 1px 2px #fff8;
  transform: rotate(var(--tilt, 0deg));
  touch-action: manipulation;
  transition: filter .16s ease, transform .16s ease, opacity .2s ease;
}
.game-button[disabled] { cursor: default; opacity: .98; }
.game-button:not([disabled]) { cursor: pointer; }
.game-button:not([disabled]):hover { filter: brightness(1.08); transform: translateY(-3px) rotate(var(--tilt, 0deg)); }
.game-button:not([disabled]):active { filter: brightness(1.14); transform: scale(.96) rotate(var(--tilt, 0deg)); }
.game-button:not([disabled]):focus-visible { outline: 3px solid #f6d78a; outline-offset: 3px; }
.button-hole { position: absolute; z-index: 1; width: 9%; aspect-ratio: 1; border: 1px solid #ffffff55; border-radius: 50%; background: #211b2a; box-shadow: inset 0 1px 2px #000a, 0 1px 1px #fff5; pointer-events: none; }
.hole-one { left: 24%; top: 24%; }
.hole-two { right: 24%; top: 24%; }
.hole-three { left: 24%; bottom: 24%; }
.hole-four { right: 24%; bottom: 24%; }
.button-name { position: relative; z-index: 2; margin-top: 3px; color: #fff; font-size: clamp(.43rem, 1.55vw, .72rem); font-weight: 900; letter-spacing: .055em; text-shadow: 0 1px 4px #161122d9; white-space: nowrap; }
.traybox { max-width: 790px; margin: 18px auto 0; padding: 12px 14px 14px; border: 1px solid #d9bc7547; border-radius: 16px; background: #14121bbd; }
.tray-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 5px 12px; color: #f0e1bd; font-weight: 850; }
.tray-head > span { font-size: 1.25rem; line-height: 1.2; }
.tray-head small { color: #b8abbc; font-size: .72rem; font-weight: 650; }
.tray { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); align-items: center; justify-items: center; gap: 5px; min-height: 66px; padding-top: 11px; }
.tray-button { position: relative; display: grid; place-items: center; width: min(100%, 57px); min-width: 0; aspect-ratio: 1; height: auto; border: 1px solid #fff8; border-radius: 50% 50% 48% 52%; background: radial-gradient(circle at 30% 24%, var(--button-light), transparent 32%), radial-gradient(circle at 52% 54%, var(--button-color) 0 58%, var(--button-dark) 100%); box-shadow: inset -4px -5px 7px #100c2755, 0 3px 7px #07060b7a; animation: reveal .22s ease-out; }
.tray-button span { overflow: hidden; max-width: 96%; color: white; font-size: clamp(.36rem, 1.05vw, .52rem); font-weight: 950; letter-spacing: .01em; text-overflow: clip; text-shadow: 0 1px 3px #100c27; white-space: nowrap; }
.empty-slot { width: min(100%, 57px); min-width: 0; aspect-ratio: 1; height: auto; border: 1px dashed #a9977c8a; border-radius: 50% 50% 48% 52%; background: #ffffff04; }
.message { min-height: 25px; margin: 13px 0 4px; color: #eee3ce; text-align: center; font-size: .83rem; font-weight: 700; line-height: 1.45; }
.actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 9px; margin: 12px auto 0; }
.action { appearance: none; min-height: 42px; padding: 10px 17px; border: 1px solid #c9b07188; border-radius: 10px; background: #ffffff08; color: #f2e8d5; font-size: .84rem; font-weight: 800; cursor: pointer; touch-action: manipulation; }
.action.primary { border-color: #d5b565; background: linear-gradient(145deg, #dfc274, #a77c36); color: #211a26; }
.action:hover:not(:disabled) { filter: brightness(1.1); }
.action:focus-visible { outline: 3px solid #fff0bc; outline-offset: 2px; }
.action:disabled { opacity: .4; cursor: default; }
.footer { margin: 13px 0 0; color: #aa9eb0; text-align: center; font-size: .72rem; }
.overlay { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 18px; background: #100d19d9; backdrop-filter: blur(7px); }
.overlay[hidden] { display: none; }
.dialog { width: min(440px, 100%); padding: 28px 23px; border: 1px solid #d9bc7590; border-radius: 21px; background: linear-gradient(145deg, #302a39, #1a1721); text-align: center; box-shadow: 0 20px 70px #07060bbd; }
.win-mark { color: var(--gold); font-size: 1.5rem; }
.dialog h2 { margin: 5px 0; color: #fff5da; font-family: Georgia, serif; font-size: 2.25rem; font-weight: 600; }
.dialog p { color: #cfc2d3; font-weight: 650; }
.dialog .action { margin-top: 8px; }
@keyframes reveal { from { opacity: .55; transform: translateY(-6px) scale(.93); } to { opacity: 1; transform: translateY(0) scale(1); } }
@media (min-width: 700px) {
  .game-shell { padding-top: 30px; }
  .board { grid-template-columns: repeat(4, minmax(0, 1fr)); min-height: 540px; }
  .pile { height: 215px; margin-bottom: -47px; }
}
@media (max-width: 390px) {
  .game-shell { padding: 15px 9px 24px; }
  .play-panel { padding: 10px 8px 14px; }
  .board-frame { padding: 9px 3px 13px; }
  .board { gap: 0; min-height: 355px; }
  .pile { height: 150px; margin-bottom: -35px; }
  .scorebar { justify-content: center; text-align: center; }
  .tray { gap: 4px; }
}

.tray-button.match-ready { animation: matchReady .75s ease-in-out; box-shadow: 0 0 0 3px #fff4b8, 0 0 20px #f8d365; }
@keyframes matchReady { 0%, 100% { transform: scale(1); } 45% { transform: scale(1.13); } 78% { transform: scale(.88); opacity: .72; } }
