:root {
  color-scheme: dark;
  --gold: #e7bd65;
  --gold-soft: #f4dca5;
  --ink: #eaf7f0;
  --muted: #91aa9e;
  --felt: #073d2c;
  --felt-dark: #04271d;
  --panel: rgba(4, 24, 18, .82);
  --danger: #f07878;
  --viewport-width: 100vw;
  --viewport-height: 100dvh;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  font-family: Inter, "Noto Sans JP", "Yu Gothic UI", sans-serif;
  background:
    radial-gradient(circle at 50% -20%, #176247 0, transparent 44%),
    linear-gradient(145deg, #020906, #071812 55%, #020b08);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .16;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='90' viewBox='0 0 90 90'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.23'/%3E%3C/svg%3E");
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.ambient {
  position: fixed;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  filter: blur(110px);
  opacity: .13;
  pointer-events: none;
}
.ambient-one { background: #32d693; top: 8%; left: -180px; }
.ambient-two { background: #d8aa4e; right: -190px; bottom: 0; }

.shell { width: min(1040px, 100%); margin: 0 auto; padding: 24px 18px 28px; position: relative; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  display: grid; place-items: center; width: 46px; height: 46px; border: 1px solid rgba(231,189,101,.55);
  color: var(--gold); font-family: Georgia, serif; font-size: 25px; border-radius: 13px;
  background: linear-gradient(145deg, rgba(231,189,101,.17), rgba(255,255,255,.02));
  box-shadow: inset 0 0 18px rgba(231,189,101,.08);
}
.eyebrow { margin: 0 0 2px; color: var(--gold); letter-spacing: .24em; font-size: 9px; font-weight: 800; }
h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(20px, 4vw, 27px); letter-spacing: .13em; font-weight: 500; }

.player-chip { display: flex; align-items: center; gap: 10px; min-width: 158px; padding: 8px 13px 8px 8px; border: 1px solid rgba(255,255,255,.1); border-radius: 999px; background: rgba(2,14,10,.72); backdrop-filter: blur(12px); }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; color: #102219; background: linear-gradient(145deg, var(--gold-soft), #a87a2f); font-weight: 900; }
.player-chip strong, .player-chip small { display: block; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-chip strong { font-size: 12px; }
.player-chip small { margin-top: 2px; color: var(--gold-soft); font-size: 11px; }

.notice { padding: 18px; border-radius: 16px; display: grid; gap: 6px; margin: 40px auto; max-width: 620px; }
.error-notice { color: #ffd9d9; border: 1px solid rgba(240,120,120,.35); background: rgba(87,20,20,.55); }

.table {
  position: relative;
  min-height: 720px;
  overflow: hidden;
  padding: 20px clamp(14px, 4vw, 38px) 26px;
  border: 1px solid rgba(231,189,101,.28);
  border-radius: 34px;
  background:
    radial-gradient(ellipse at 50% 35%, rgba(25,116,78,.44), transparent 56%),
    linear-gradient(160deg, rgba(9,76,53,.96), rgba(3,38,27,.98));
  box-shadow: 0 38px 90px rgba(0,0,0,.48), inset 0 0 90px rgba(0,0,0,.28), inset 0 1px rgba(255,255,255,.08);
}
.table::after { content: ""; position: absolute; inset: 11px; border: 1px solid rgba(231,189,101,.13); border-radius: 25px; pointer-events: none; }
.table-glow { position: absolute; width: 70%; height: 260px; left: 15%; top: 18%; background: #38c991; filter: blur(100px); opacity: .08; pointer-events: none; }
.deck-zone {
  position: absolute;
  z-index: 7;
  top: 48px;
  right: 32px;
  width: 45px;
  height: 65px;
  pointer-events: none;
  transform: rotate(5deg);
  filter: drop-shadow(0 9px 8px rgba(0,0,0,.34));
}
.deck-card {
  position: absolute;
  inset: 0;
  border: 2px solid #e9e1ca;
  border-radius: 6px;
  background: repeating-linear-gradient(45deg, #173e31 0 4px, #0c291f 4px 8px);
  box-shadow: inset 0 0 0 2px rgba(231,189,101,.35);
}
.deck-card:nth-child(1) { transform: translate(-4px, 4px); opacity: .68; }
.deck-card:nth-child(2) { transform: translate(-2px, 2px); opacity: .84; }
.deck-front::after {
  content: "M";
  position: absolute;
  inset: 6px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(231,189,101,.55);
  color: var(--gold);
  font: 18px Georgia, serif;
}
.deck-zone.shuffling .deck-card:nth-child(1) { animation: shuffle-left .56s cubic-bezier(.4,0,.2,1); }
.deck-zone.shuffling .deck-card:nth-child(2) { animation: shuffle-right .56s cubic-bezier(.4,0,.2,1); }
.deck-zone.shuffling .deck-front { animation: shuffle-center .56s cubic-bezier(.4,0,.2,1); }
.deck-zone.dealing-out { animation: deck-pulse .32s ease-out 2; }
@keyframes shuffle-left {
  0%, 100% { transform: translate(-4px,4px) rotate(0); }
  35% { transform: translate(-38px,1px) rotate(-13deg); }
  68% { transform: translate(9px,-3px) rotate(7deg); }
}
@keyframes shuffle-right {
  0%, 100% { transform: translate(-2px,2px) rotate(0); }
  35% { transform: translate(34px,-4px) rotate(12deg); }
  68% { transform: translate(-10px,1px) rotate(-6deg); }
}
@keyframes shuffle-center {
  0%, 100% { transform: translate(0); }
  42% { transform: translateY(-12px) rotate(-4deg); }
  72% { transform: translateY(3px) rotate(3deg); }
}
@keyframes deck-pulse { 50% { transform: rotate(5deg) translateY(-4px) scale(1.04); } }
.rules-strip { position: relative; z-index: 1; display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 26px; color: rgba(234,247,240,.52); font-size: 9px; letter-spacing: .13em; }
.rules-strip b { color: var(--gold); font-weight: 700; }

.hand { position: relative; z-index: 2; width: min(660px, 100%); margin-inline: auto; }
.dealer-hand { margin-top: 32px; min-height: 192px; }
.player-hand { min-height: 205px; margin-top: 10px; }
.hand-heading { display: flex; justify-content: center; align-items: center; gap: 10px; margin-bottom: 14px; color: rgba(234,247,240,.68); font-size: 10px; font-weight: 800; letter-spacing: .18em; }
.score { display: grid; place-items: center; min-width: 29px; height: 25px; padding: 0 7px; border: 1px solid rgba(231,189,101,.3); border-radius: 8px; color: var(--gold-soft); background: rgba(1,17,12,.5); font-size: 12px; letter-spacing: 0; }
.cards { display: flex; justify-content: center; min-height: 139px; padding-left: 22px; perspective: 900px; }
.card {
  position: relative; width: 88px; height: 128px; margin-left: -22px; flex: 0 0 auto;
  border-radius: 10px; color: #151a17; background: linear-gradient(150deg, #fffef9, #e5e5dc);
  box-shadow: 0 13px 23px rgba(0,0,0,.35), inset 0 0 0 1px rgba(0,0,0,.1);
  transform-origin: 50% 120%;
}
.card.red { color: #a9292f; }
.card .corner { position: absolute; left: 9px; top: 6px; display: grid; justify-items: center; font-family: Georgia, serif; font-weight: 700; font-size: 20px; line-height: .9; }
.card .corner small { font-size: 15px; margin-top: 3px; }
.card .suit-center { position: absolute; inset: 0; display: grid; place-items: center; font-size: 42px; opacity: .9; }
.card.hidden { overflow: hidden; border: 4px solid #e9e1ca; background: repeating-linear-gradient(45deg, #173e31 0 5px, #0c291f 5px 10px); }
.card.hidden::after { content: "M"; position: absolute; inset: 8px; display: grid; place-items: center; border: 1px solid rgba(231,189,101,.55); color: var(--gold); font: 30px Georgia, serif; }
.card.dealing { animation: deal-card .55s cubic-bezier(.16,.8,.24,1.08) both; animation-delay: var(--delay, 0ms); }
@keyframes deal-card {
  from { opacity: .72; transform: translate(var(--deal-x, 130px), var(--deal-y, -100px)) rotate(var(--deal-rotate, 12deg)) scale(.52); }
  to { opacity: 1; transform: translate(0,0) rotate(0) scale(1); }
}
.card-skeleton {
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.08);
  box-shadow: none;
}
.card-skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(100deg, transparent 20%, rgba(255,255,255,.14) 50%, transparent 80%);
  animation: skeleton-shimmer 1.25s ease-in-out infinite;
}
@keyframes skeleton-shimmer { to { transform: translateX(100%); } }
.is-loading { cursor: wait; }
.table.is-loading .controls { opacity: .42; }
.player-chip.is-loading strong, .player-chip.is-loading small { color: transparent; }
.player-chip.is-loading strong, .player-chip.is-loading small {
  border-radius: 999px;
  background: rgba(255,255,255,.1);
}

.result-banner { position: relative; z-index: 4; width: min(500px, 94%); margin: -5px auto 5px; padding: 12px 18px; text-align: center; border-block: 1px solid rgba(231,189,101,.28); background: linear-gradient(90deg, transparent, rgba(1,22,15,.82), transparent); animation: result-in .5s ease both; }
.result-banner p { margin: 0; color: var(--gold); font: 25px Georgia, serif; letter-spacing: .18em; }
.result-banner strong, .result-banner span { display: block; }
.result-banner strong { margin-top: 4px; font-size: 12px; }
.result-banner span { margin-top: 3px; color: var(--gold-soft); font-size: 12px; }
@keyframes result-in { from { opacity: 0; transform: scale(.9); filter: blur(8px); } to { opacity: 1; transform: scale(1); filter: blur(0); } }

.controls { position: relative; z-index: 5; width: min(540px, 100%); margin: 8px auto 0; padding: 18px; border: 1px solid rgba(255,255,255,.09); border-radius: 20px; background: var(--panel); box-shadow: 0 14px 35px rgba(0,0,0,.25); backdrop-filter: blur(14px); }
.controls > label { display: block; margin-bottom: 8px; color: var(--gold); font-size: 9px; letter-spacing: .2em; text-align: center; font-weight: 900; }
.bet-entry { display: grid; grid-template-columns: 62px minmax(0, 1fr) 62px; gap: 8px; }
.adjust, .quick-bets button { border: 1px solid rgba(255,255,255,.1); color: var(--ink); background: rgba(255,255,255,.045); border-radius: 10px; cursor: pointer; }
.adjust:hover, .quick-bets button:hover { border-color: rgba(231,189,101,.48); color: var(--gold-soft); }
.amount-wrap { display: grid; grid-template-columns: minmax(0, 1fr) auto; min-width: 0; overflow: hidden; border: 1px solid rgba(231,189,101,.22); border-radius: 11px; background: rgba(0,0,0,.24); }
.amount-wrap:focus-within { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(231,189,101,.1); }
.amount-wrap input { min-width: 0; width: 100%; height: 44px; padding: 0 9px; border: 0; outline: none; color: white; background: transparent; text-align: right; font-size: 18px; font-weight: 750; }
.amount-wrap span { display: flex; align-items: center; max-width: 8em; padding: 0 10px 0 8px; overflow: hidden; border-left: 1px solid rgba(231,189,101,.12); color: var(--muted); font-size: 11px; white-space: nowrap; text-overflow: ellipsis; }
.quick-bets { display: grid; grid-template-columns: repeat(5,1fr); gap: 6px; margin-top: 8px; }
.quick-bets button { min-height: 30px; font-size: 10px; }
.primary-action { width: 100%; height: 53px; margin-top: 12px; border: 0; border-radius: 12px; cursor: pointer; color: #142218; background: linear-gradient(145deg, #f0d28e, #b88638); box-shadow: 0 8px 24px rgba(190,140,58,.2); font-weight: 900; letter-spacing: .1em; }
.primary-action small { display: block; margin-top: 1px; font-size: 8px; letter-spacing: .08em; opacity: .67; }
.primary-action:disabled, .game-action:disabled { cursor: wait; filter: grayscale(.5); opacity: .6; }

.action-controls { padding: 13px 16px 16px; }
.current-bet { margin-bottom: 10px; color: var(--muted); font-size: 10px; letter-spacing: .16em; text-align: center; }
.current-bet strong { color: var(--gold-soft); }
.action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.game-action { min-height: 58px; border-radius: 13px; color: white; cursor: pointer; font-weight: 900; letter-spacing: .12em; }
.game-action span { display: block; margin-top: 3px; font-size: 8px; letter-spacing: .04em; opacity: .62; }
.game-action.hit { border: 1px solid rgba(66,204,155,.45); background: linear-gradient(145deg, rgba(21,124,87,.9), rgba(8,72,50,.95)); }
.game-action.stand { border: 1px solid rgba(231,189,101,.45); background: linear-gradient(145deg, rgba(132,94,32,.86), rgba(72,48,16,.95)); }
.play-again { position: relative; z-index: 5; display: block; width: min(260px, 80%); height: 44px; margin: 12px auto 0; border: 1px solid rgba(231,189,101,.45); border-radius: 999px; color: var(--gold-soft); background: rgba(2,20,14,.72); cursor: pointer; }

footer { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 17px; color: #698076; font-size: 10px; letter-spacing: .08em; }
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: #52d6a3; box-shadow: 0 0 9px #52d6a3; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: 24px; width: min(420px, calc(100% - 28px)); padding: 13px 17px; border: 1px solid rgba(240,120,120,.4); border-radius: 12px; color: #ffe4e4; background: rgba(57,14,14,.94); box-shadow: 0 16px 38px rgba(0,0,0,.42); text-align: center; font-size: 12px; opacity: 0; transform: translate(-50%, 20px); pointer-events: none; transition: .25s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
[hidden] { display: none !important; }

@media (max-width: 900px), (pointer: coarse) {
  html, body {
    position: fixed;
    inset: 0;
    width: var(--viewport-width);
    height: var(--viewport-height);
    min-height: 0;
    overflow: hidden;
    overscroll-behavior: none;
  }
  .shell {
    position: fixed;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: var(--viewport-height);
    max-height: var(--viewport-height);
    overflow: hidden;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }
  .topbar { flex: 0 0 auto; min-height: 38px; margin-bottom: 6px; gap: 8px; }
  .brand { gap: 8px; }
  .brand-mark { width: 36px; height: 36px; border-radius: 10px; font-size: 20px; }
  .eyebrow { font-size: 7px; }
  h1 { font-size: 18px; }
  .player-chip { min-width: 0; padding-right: 9px; }
  .avatar { width: 30px; height: 30px; }
  .player-chip strong, .player-chip small { max-width: 105px; }
  .table {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    height: auto;
    overflow: hidden;
    padding: 8px 10px 9px;
    border-radius: 24px;
  }
  .table::after { inset: 6px; border-radius: 19px; }
  .deck-zone { top: 31px; right: 17px; width: 31px; height: 45px; }
  .deck-front::after { inset: 4px; font-size: 13px; }
  .rules-strip { flex: 0 0 auto; gap: 3px 10px; font-size: 7px; line-height: 1.15; }
  .hand { display: flex; flex: 1 1 0; flex-direction: column; min-height: 0; }
  .dealer-hand { margin-top: 7px; min-height: 0; }
  .player-hand { min-height: 0; margin-top: 2px; }
  .hand-heading { flex: 0 0 auto; margin-bottom: 3px; font-size: 8px; }
  .score { min-width: 25px; height: 21px; font-size: 10px; }
  .cards { flex: 1 1 auto; align-items: center; min-height: 0; padding-left: 16px; }
  .card {
    width: var(--mobile-card-width, 70px);
    height: var(--mobile-card-height, 102px);
    margin-left: var(--mobile-card-overlap, -17px);
    border-radius: 8px;
  }
  .card .corner { font-size: 17px; }
  .card .corner small { font-size: 12px; }
  .card .suit-center { font-size: 34px; }
  .result-banner { flex: 0 0 auto; margin: 0 auto; padding: 6px 12px; }
  .result-banner p { font-size: 20px; }
  .result-banner strong, .result-banner span { font-size: 10px; }
  .controls { flex: 0 0 auto; margin-top: 3px; padding: 8px 10px; border-radius: 14px; }
  .controls > label { margin-bottom: 3px; }
  .bet-entry { grid-template-columns: 54px minmax(0, 1fr) 54px; gap: 6px; }
  .amount-wrap input { height: 36px; font-size: 16px; }
  .amount-wrap span { padding-inline: 7px; font-size: 10px; }
  .quick-bets { margin-top: 4px; }
  .quick-bets button { min-height: 26px; }
  .primary-action { height: 42px; margin-top: 6px; }
  .action-controls { padding: 8px 10px 10px; }
  .current-bet { margin-bottom: 5px; }
  .game-action { min-height: 48px; }
  .play-again { flex: 0 0 auto; height: 38px; margin-top: 5px; }
  footer { display: none; }
}

@media (max-width: 900px) and (max-height: 700px), (pointer: coarse) and (max-height: 700px) {
  .topbar { min-height: 32px; margin-bottom: 4px; }
  .brand-mark { width: 32px; height: 32px; }
  .eyebrow, .rules-strip { display: none; }
  h1 { font-size: 16px; }
  .player-chip { padding-block: 4px; }
  .dealer-hand { margin-top: 2px; }
  .controls { padding-block: 6px; }
  .quick-bets button { min-height: 23px; }
  .primary-action { height: 37px; }
}

@media (max-width: 900px) and (max-height: 560px), (pointer: coarse) and (max-height: 560px) {
  .topbar { min-height: 28px; }
  .brand-mark { width: 28px; height: 28px; font-size: 17px; }
  .player-chip { padding: 2px 7px 2px 4px; }
  .avatar { width: 26px; height: 26px; }
  .hand-heading { margin-bottom: 1px; }
  .controls > label, .quick-bets { display: none; }
  .primary-action { margin-top: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
