:root {
  color-scheme: light;
  --ink: #17243b;
  --muted: #6e7a8f;
  --panel: rgba(255, 255, 255, 0.86);
  --line: rgba(39, 62, 94, 0.12);
  --navy: #17243b;
  --navy-deep: #101a2d;
  --accent: #36cdbf;
  --accent-dark: #148d89;
  --surface: #edf2f8;
  --shadow: 0 10px 30px rgba(30, 48, 77, 0.12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-rounded, "SF Pro Rounded", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: #dfe7f1;
  overscroll-behavior: none;
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% -5%, rgba(90, 213, 200, 0.2), transparent 27rem),
    radial-gradient(circle at 100% 25%, rgba(102, 139, 225, 0.13), transparent 30rem),
    linear-gradient(165deg, #f8fafc 0%, #e9eff6 100%);
  user-select: none;
  -webkit-user-select: none;
}

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

button, input { font: inherit; }
button { touch-action: manipulation; }
button:focus-visible { outline: 3px solid rgba(54, 205, 191, 0.45); outline-offset: 3px; }

.app-shell {
  position: relative;
  width: min(100%, 720px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(14px + var(--safe-top)) 14px calc(16px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand-block { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 43px;
  aspect-ratio: 1;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: white;
  background: linear-gradient(145deg, #263a5d, #121d31);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.2), 0 7px 16px rgba(23,36,59,.23);
  transform: rotate(-3deg);
}
.brand-mark span { font-weight: 900; font-size: 16px; border-bottom: 3px solid var(--accent); line-height: 1.15; }
.eyebrow { margin: 0 0 2px; font-weight: 850; font-size: 8px; letter-spacing: .17em; color: #8090a5; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(21px, 6.2vw, 30px); line-height: 1; letter-spacing: -.045em; }

.modal-close {
  border: 1px solid rgba(255,255,255,.8);
  color: var(--ink);
  background: rgba(255,255,255,.75);
  box-shadow: 0 5px 16px rgba(30,48,77,.09);
}
.stats { display: grid; grid-template-columns: 1.35fr repeat(3, 1fr); gap: 6px; }
.stat-card {
  min-width: 0;
  padding: 9px 7px 8px;
  text-align: center;
  border: 1px solid rgba(255,255,255,.82);
  border-radius: 13px;
  background: var(--panel);
  box-shadow: 0 5px 15px rgba(30,48,77,.07);
  overflow: hidden;
}
.stat-card span { display: block; margin-bottom: 2px; color: var(--muted); font-weight: 760; font-size: 8px; text-transform: uppercase; letter-spacing: .08em; }
.stat-card strong { display: block; font-size: 16px; line-height: 1.15; font-variant-numeric: tabular-nums; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.stat-score { color: white; border-color: transparent; background: linear-gradient(145deg, #263c61, #17243b); box-shadow: 0 7px 17px rgba(23,36,59,.2); }
.stat-score span { color: rgba(255,255,255,.6); }
.stat-score.score-pop { animation: score-pop 300ms ease-out; }

.board-wrap {
  position: relative;
  padding: 10px 8px 8px;
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 25px;
  background: linear-gradient(150deg, rgba(230,237,246,.96), rgba(215,225,238,.96));
  box-shadow: inset 0 1px 0 white, 0 14px 35px rgba(30,48,77,.13);
}

.board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px 6px; }
.slot {
  position: relative;
  min-width: 0;
  height: clamp(142px, 41vw, 188px);
  padding: 15px 4px 5px;
  border: 1px solid rgba(35,55,85,.12);
  border-radius: 12px 12px 15px 15px;
  background-color: rgba(247,250,253,.64);
  background-image: repeating-linear-gradient(to top, transparent 0, transparent calc(10% - 1px), rgba(43,65,96,.095) calc(10% - 1px), rgba(43,65,96,.095) 10%);
  box-shadow: inset 0 2px 7px rgba(43,65,96,.09), 0 1px 0 rgba(255,255,255,.85);
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease, background-color 180ms ease;
}
.slot::after {
  content: "";
  position: absolute;
  inset: 5px 5px auto;
  height: 3px;
  border-radius: 99px;
  background: rgba(45,66,96,.09);
  transition: background 180ms ease;
}
.slot-number { position: absolute; top: 3px; left: 7px; color: rgba(55,75,103,.38); font-weight: 850; font-size: 7px; letter-spacing: .05em; }
.slot-stack { position: absolute; inset: 18px 4px 5px; display: grid; grid-template-rows: repeat(10, minmax(0, 1fr)); gap: 1px; pointer-events: none; }
.money-card {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  border-radius: 4px;
  color: white;
  font-size: clamp(8px, 2.55vw, 14px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-shadow: 0 1px 1px rgba(0,0,0,.18);
  background: linear-gradient(155deg, var(--card-light), var(--card-dark));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.32), 0 1px 2px rgba(18,32,54,.2);
  transition: transform 180ms cubic-bezier(.2,.8,.2,1), filter 180ms ease;
}
.money-card::before, .money-card::after { content: ""; position: absolute; top: 50%; width: 2px; height: 2px; border: 1px solid rgba(255,255,255,.7); border-radius: 50%; transform: translateY(-50%); }
.money-card::before { left: 5px; }
.money-card::after { right: 5px; }

.slot.is-selected { z-index: 2; transform: translateY(-3px); border-color: var(--accent); background-color: rgba(225,253,249,.8); box-shadow: inset 0 2px 7px rgba(43,65,96,.07), 0 0 0 3px rgba(54,205,191,.19), 0 9px 16px rgba(24,98,99,.12); }
.slot.is-selected::after { background: var(--accent); }
.slot.is-selected .money-card.is-picked { transform: translateY(-3px) scale(1.035); filter: brightness(1.06); }
.slot.is-arriving .money-card { animation: card-arrive 260ms cubic-bezier(.18,.9,.32,1.25) var(--deal-delay) both; }
.slot.is-merging .money-card { animation: merge-card 400ms cubic-bezier(.2,.9,.25,1.2) both; z-index: 3; }
.slot.is-invalid { animation: slot-shake 310ms ease; border-color: #e1676b; background-color: rgba(255,229,230,.85); }

.selection-hint { height: 22px; padding-top: 7px; text-align: center; color: #718096; font-size: 10px; font-weight: 650; letter-spacing: .01em; }
.selection-hint strong { color: var(--accent-dark); }

.actions { margin-top: auto; display: grid; gap: 9px; }
.deal-button {
  position: relative;
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 0;
  border-radius: 18px;
  color: white;
  background: linear-gradient(145deg, #2cd1c1, #138d89);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35), inset 0 -3px 0 rgba(0,71,71,.22), 0 10px 22px rgba(19,141,137,.28);
  overflow: hidden;
  transition: transform 120ms ease, filter 120ms ease;
}
.deal-button::before { content: ""; position: absolute; inset: 0; background: linear-gradient(105deg, transparent 22%, rgba(255,255,255,.22) 43%, transparent 60%); transform: translateX(-110%); }
.deal-button:active { transform: translateY(2px) scale(.992); filter: saturate(.9); }
.deal-button:active::before { animation: button-shine 450ms ease-out; }
.deal-button:disabled { filter: grayscale(.7); opacity: .55; }
.deal-button > span:not(.deal-spark) { font-weight: 950; letter-spacing: .13em; font-size: 19px; }
.deal-button small { justify-self: end; font-size: 8px; font-weight: 750; color: rgba(255,255,255,.7); text-transform: uppercase; letter-spacing: .06em; }
.deal-spark { justify-self: start; font-size: 17px; }

.secondary-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.secondary-button {
  min-height: 43px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid rgba(255,255,255,.88);
  border-radius: 13px;
  color: var(--ink);
  background: rgba(255,255,255,.72);
  box-shadow: 0 5px 15px rgba(30,48,77,.07);
  font-weight: 750;
  font-size: 11px;
}
.secondary-button:active { transform: translateY(1px); }
.secondary-button:disabled { opacity: .38; }
.secondary-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.secondary-button svg circle { vector-effect: non-scaling-stroke; }

.modal-backdrop {
  position: fixed;
  z-index: 20;
  inset: 0;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  display: grid;
  place-items: end center;
  background: rgba(11,20,35,.5);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  animation: fade-in 180ms ease both;
}
.modal-backdrop[hidden] { display: none; }
.modal-open { overflow: hidden; }
.modal {
  width: min(100%, 440px);
  padding: 22px;
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 25px;
  background: #f8fafc;
  box-shadow: 0 24px 60px rgba(9,18,33,.3);
  animation: modal-up 260ms cubic-bezier(.2,.85,.3,1) both;
}
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.modal h2 { margin-bottom: 15px; font-size: 25px; letter-spacing: -.04em; }
.modal-close { width: 36px; height: 36px; border-radius: 12px; font-size: 24px; line-height: 1; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 15px 0; border-top: 1px solid var(--line); }
.setting-row strong { display: block; margin-bottom: 3px; font-size: 14px; }
.setting-row span { display: block; color: var(--muted); font-size: 11px; line-height: 1.35; }
.switch { position: relative; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; }
.switch span { width: 48px; height: 28px; display: block; border-radius: 99px; background: #cbd3dd; transition: background 180ms ease; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; border-radius: 50%; background: white; box-shadow: 0 2px 7px rgba(20,35,56,.22); transition: transform 180ms ease; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.install-button, .primary-modal-button { width: 100%; min-height: 48px; border: 0; border-radius: 14px; color: white; background: linear-gradient(145deg, #263c61, #17243b); box-shadow: 0 8px 18px rgba(23,36,59,.2); font-weight: 850; }
.install-button { margin-top: 12px; }
.ios-install { margin: 15px 0 0; text-align: center; color: var(--muted); font-size: 10px; }

.game-over-modal { text-align: center; overflow: hidden; }
.game-over-orbit { width: 66px; height: 66px; margin: -2px auto 14px; display: grid; place-items: center; border-radius: 22px; color: white; font-size: 27px; background: linear-gradient(145deg, #45d9ca, #168d89); box-shadow: 0 12px 24px rgba(22,141,137,.25); transform: rotate(5deg); }
.game-over-modal h2 { margin-bottom: 18px; font-size: 30px; }
.game-over-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-bottom: 19px; }
.game-over-stats div { padding: 12px 5px; border-radius: 13px; background: #edf2f7; }
.game-over-stats span { display: block; margin-bottom: 3px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; font-size: 8px; font-weight: 750; }
.game-over-stats strong { font-size: 17px; }
.text-button { border: 0; color: var(--muted); background: transparent; font-weight: 750; }
.game-over-modal .text-button { margin-top: 13px; }
.confirm-modal p:not(.eyebrow) { margin-bottom: 20px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.confirm-actions { display: grid; grid-template-columns: .7fr 1.4fr; gap: 8px; }

.toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: calc(22px + var(--safe-bottom));
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 99px;
  color: white;
  background: rgba(23,36,59,.94);
  box-shadow: 0 8px 24px rgba(13,23,39,.25);
  font-size: 11px;
  font-weight: 750;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@keyframes card-arrive { from { opacity: 0; transform: translateY(-20px) scale(.82); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes merge-card { 0% { transform: scale(.75); filter: brightness(1.5); } 55% { transform: scale(1.14); filter: brightness(1.18); } 100% { transform: scale(1); filter: brightness(1); } }
@keyframes slot-shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 50% { transform: translateX(4px); } 75% { transform: translateX(-2px); } }
@keyframes score-pop { 0% { transform: scale(1); } 45% { transform: scale(1.08); filter: brightness(1.16); } 100% { transform: scale(1); } }
@keyframes button-shine { to { transform: translateX(110%); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-up { from { opacity: 0; transform: translateY(28px) scale(.97); } }

@media (min-width: 620px) {
  .app-shell { padding-left: 28px; padding-right: 28px; gap: 17px; }
  .board-wrap { padding: 15px 14px 10px; }
  .board { gap: 12px 9px; }
  .slot { border-radius: 15px 15px 18px 18px; }
  .money-card { border-radius: 6px; }
  .modal-backdrop { place-items: center; }
}

@media (max-height: 710px) {
  .app-shell { gap: 8px; padding-top: calc(8px + var(--safe-top)); }
  .brand-mark { width: 37px; border-radius: 12px; }
  .stats .stat-card { padding-top: 6px; padding-bottom: 6px; }
  .slot { height: min(34vw, 134px); }
  .selection-hint { height: 18px; padding-top: 5px; }
  .deal-button { min-height: 50px; }
  .secondary-button { min-height: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
