:root {
  --ink: #30293a;
  --muted: #726a7a;
  --cream: #fffaf0;
  --purple: #4a2b68;
  --purple-dark: #2e193f;
  --mint: #8de0c2;
  --mint-dark: #397c68;
  --gold: #ffd464;
  --red: #e95667;
  --card-radius: 10px;
  font-family: "M PLUS Rounded 1c", system-ui, sans-serif;
  color: var(--ink);
  background: #f3ecdf;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-width: 320px;
  background:
    radial-gradient(circle at 12% 6%, rgba(255, 255, 255, .9) 0 5%, transparent 22%),
    linear-gradient(135deg, #fffaf1, #eee5d7);
}

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

button {
  color: inherit;
}

.topbar {
  min-height: 64px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 8px max(16px, env(safe-area-inset-left)) 8px max(16px, env(safe-area-inset-right));
  color: #fff;
  background: var(--purple-dark);
  border-bottom: 4px solid var(--gold);
}

.home-link {
  width: fit-content;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.mini-logo {
  width: 150px;
}

.mini-logo img {
  width: 100%;
  height: auto;
  display: block;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, .22));
}

.topbar-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
}

.coin-pill {
  min-width: 90px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 999px;
  background: rgba(255, 255, 255, .1);
  font-size: 15px;
}

.coin-pill img {
  width: 23px;
  height: 23px;
}

.sound-toggle {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(118, 190, 224, .46);
  border-radius: 12px;
  color: #29483e;
  background: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .9), 0 3px 7px rgba(0, 0, 0, .16);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, opacity .12s;
}

.sound-toggle.muted {
  opacity: .72;
  background: #e9f0ed;
}

.sound-toggle:active {
  transform: translateY(2px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .9), 0 1px 3px rgba(0, 0, 0, .16);
}

.sound-toggle:focus-visible {
  outline: 3px solid #ffe88c;
  outline-offset: 2px;
}

main {
  width: min(940px, 100%);
  margin: 0 auto;
  padding: 26px 20px calc(30px + env(safe-area-inset-bottom));
}

.title-screen {
  min-height: calc(100dvh - 68px);
  display: grid;
  place-items: start center;
  padding: 12px 20px calc(20px + env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 18% 22%, rgba(141, 224, 194, .38) 0 4%, transparent 18%),
    radial-gradient(circle at 83% 77%, rgba(255, 212, 100, .38) 0 5%, transparent 20%);
}

.title-screen[hidden],
main[hidden] {
  display: none;
}

.title-card {
  width: min(620px, 100%);
  padding: 18px 30px 22px;
  border: 5px solid var(--purple);
  border-radius: 30px;
  background: rgba(255, 250, 240, .96);
  box-shadow: 0 12px 0 #d6c9b7, 0 22px 45px rgba(70, 44, 84, .22);
  text-align: center;
}

.title-eyebrow {
  margin: 0 0 4px;
  color: var(--mint-dark);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .14em;
}

.title-logo {
  width: min(100%, 360px);
  margin-inline: auto;
}

.title-logo img {
  width: 100%;
  height: auto;
  display: block;
  filter: drop-shadow(0 5px 2px rgba(74, 43, 104, .18));
}

.title-character {
  width: min(100%, 280px);
  height: auto;
  display: block;
  margin: -8px auto 0;
  filter: drop-shadow(0 7px 4px rgba(74, 43, 104, .15));
}

.title-copy {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: clamp(15px, 2.4vw, 18px);
}

.title-copy b {
  color: var(--red);
  font-size: 1.25em;
}

.title-rules {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.title-rules div {
  min-width: 0;
  padding: 10px 8px;
  border: 2px solid #ded3c3;
  border-radius: 16px;
  background: #fff;
}

.title-rules span {
  min-height: 32px;
  display: grid;
  place-items: center;
  color: var(--red);
  font-size: clamp(20px, 4vw, 26px);
  font-weight: 900;
}

.title-rules p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.55;
}

.title-rules b {
  color: var(--purple);
}

.title-note {
  margin: 12px 0 8px;
  color: var(--purple);
  font-size: 12px;
  font-weight: 900;
}

.title-actions {
  width: min(340px, 100%);
  display: grid;
  gap: 7px;
  margin: 0 auto;
}

.title-start,
.title-new {
  min-height: 50px;
  padding: 8px 22px;
  border: 0;
  border-radius: 15px;
  font-weight: 900;
  cursor: pointer;
}

.title-start {
  color: #fff;
  background: var(--red);
  box-shadow: 0 5px 0 #a83249;
  font-size: 16px;
}

.title-new {
  color: var(--purple);
  background: #e7ddcf;
  box-shadow: 0 4px 0 #cfc1af;
  font-size: 13px;
}

.title-start:hover,
.title-new:hover {
  transform: translateY(-1px);
}

.title-start:active,
.title-new:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #a83249;
}

.title-start:focus-visible,
.title-new:focus-visible {
  outline: 4px solid var(--gold);
  outline-offset: 3px;
}

.title-small {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.game-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin: 0 4px 18px;
}

.eyebrow,
.modal-kicker {
  margin: 0 0 3px;
  color: var(--mint-dark);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .18em;
}

h1 {
  margin: 0;
  color: var(--purple);
  font-size: clamp(30px, 5vw, 48px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -.04em;
}

h1 strong {
  display: inline-block;
  color: var(--red);
  font-size: 1.35em;
  transform: rotate(-5deg);
}

.game-title-logo {
  width: min(360px, 48vw);
  height: auto;
  display: block;
  filter: drop-shadow(0 4px 2px rgba(74, 43, 104, .16));
}

.rule-lead {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.rule-lead b {
  color: var(--purple);
}

.quick-stats {
  display: flex;
  gap: 10px;
  margin: 0;
}

.quick-stats div {
  min-width: 92px;
  padding: 8px 13px;
  border: 2px solid #ded3c3;
  border-radius: 12px;
  background: rgba(255, 255, 255, .7);
}

.quick-stats dt {
  color: var(--muted);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .12em;
}

.quick-stats dd {
  margin: 0;
  color: var(--purple);
  font-size: 22px;
  font-weight: 900;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

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

.table-wrap {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: 15px;
  border: 5px solid #674c76;
  border-radius: 24px;
  background:
    radial-gradient(circle at 50% -20%, rgba(255, 255, 255, .12), transparent 46%),
    repeating-linear-gradient(45deg, rgba(255,255,255,.018) 0 2px, transparent 2px 8px),
    var(--purple);
  box-shadow: 0 12px 0 #d6c9b7, 0 18px 30px rgba(70, 44, 84, .22);
}

.table-top {
  min-height: 38px;
  display: grid;
  grid-template-columns: 1fr minmax(220px, 2fr) 1fr;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-size: 13px;
}

.stock-view,
.shuffle-view {
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.shuffle-view {
  justify-content: flex-end;
}

.stock-view b,
.shuffle-view b {
  color: var(--gold);
  font-size: 17px;
}

.tiny-card {
  width: 19px;
  aspect-ratio: 5 / 7;
  border: 2px solid #fff;
  border-radius: 3px;
  background: var(--red);
  box-shadow: 2px 2px 0 rgba(255, 255, 255, .4);
}

.message {
  min-height: 30px;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 5px 12px;
  border-radius: 999px;
  color: var(--purple-dark);
  background: var(--gold);
  font-weight: 900;
  text-align: center;
}

.message.good {
  background: var(--mint);
}

.message.warn {
  color: #fff;
  background: var(--red);
}

.board {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  padding: 13px 3px 4px;
}

.card-slot {
  min-width: 0;
  aspect-ratio: 127 / 178;
  padding: 0;
  border: 2px dashed rgba(255, 255, 255, .2);
  border-radius: var(--card-radius);
  background: rgba(25, 10, 37, .17);
}

.playing-card {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: var(--card-radius);
  background: #fff;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(27, 13, 37, .35), 0 8px 14px rgba(16, 7, 25, .22);
  transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}

.playing-card img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: var(--card-radius);
  object-fit: cover;
  pointer-events: none;
  user-select: none;
}

.playing-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 0 rgba(27, 13, 37, .32), 0 12px 18px rgba(16, 7, 25, .22);
}

.playing-card:focus-visible {
  outline: 4px solid var(--gold);
  outline-offset: 3px;
}

.playing-card.selected {
  z-index: 2;
  outline: 5px solid var(--gold);
  outline-offset: 1px;
  transform: translateY(-7px) rotate(-1deg);
}

.playing-card.hint {
  animation: hint-pulse .7s ease-in-out 2;
}

.playing-card.clearing {
  pointer-events: none;
  animation: clear-card .34s ease forwards;
}

.playing-card.dealing {
  animation: deal-card .32s cubic-bezier(.2, .9, .35, 1.2) both;
}

.combo-pop {
  position: absolute;
  z-index: 40;
  top: 52%;
  left: 50%;
  color: var(--gold);
  font-size: clamp(32px, 8vw, 64px);
  font-weight: 900;
  white-space: nowrap;
  text-shadow: 0 4px 0 var(--purple-dark), 0 7px 18px rgba(0, 0, 0, .35);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(.7) rotate(-6deg);
}

.combo-pop.show {
  animation: combo-pop .7s ease-out;
}

.controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 24px auto 0;
  max-width: 620px;
}

.controls button {
  min-height: 64px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1px;
  padding: 7px 10px;
  border: 0;
  border-radius: 14px;
  color: var(--purple);
  background: #fff;
  box-shadow: 0 5px 0 #d8cdbd;
  cursor: pointer;
}

.controls button:hover {
  transform: translateY(-1px);
}

.controls button:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #d8cdbd;
}

.controls button:focus-visible,
.wide-button:focus-visible,
.modal-actions button:focus-visible,
.close:focus-visible {
  outline: 4px solid var(--gold);
  outline-offset: 3px;
}

.controls button:disabled {
  cursor: not-allowed;
  filter: grayscale(1);
  opacity: .45;
}

.controls button > span {
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
}

.controls small {
  font-size: 11px;
  font-weight: 900;
}

.controls .primary {
  color: #fff;
  background: var(--red);
  box-shadow: 0 5px 0 #a83249;
}

.controls .primary:active {
  box-shadow: 0 1px 0 #a83249;
}

.best-record {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.best-record b {
  color: var(--purple);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.modal {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: none;
  place-items: center;
  overflow-y: auto;
  padding: 24px 18px;
  background: rgba(30, 17, 41, .72);
  backdrop-filter: blur(5px);
}

.modal.open {
  display: grid;
}

.modal-card {
  position: relative;
  width: min(520px, 100%);
  padding: 34px;
  border: 4px solid var(--purple);
  border-radius: 24px;
  background: var(--cream);
  box-shadow: 0 10px 0 rgba(25, 11, 37, .38);
}

.modal-card.compact {
  width: min(410px, 100%);
  text-align: center;
}

.modal-card h2 {
  margin: 0 0 14px;
  color: var(--purple);
  font-size: 26px;
  line-height: 1.35;
}

.modal-card p {
  line-height: 1.7;
}

.close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: #e7ddcf;
  font-size: 25px;
  font-weight: 900;
  cursor: pointer;
}

.rule-list {
  display: grid;
  gap: 14px;
  margin: 20px 0;
  padding: 0;
  list-style: none;
}

.rule-list li {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: start;
  gap: 10px;
}

.rule-list p {
  margin: 2px 0 0;
}

.rule-number {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--purple);
  font-weight: 900;
}

.pair-examples {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 18px 0;
}

.pair-examples span {
  padding: 8px 4px;
  border: 2px solid #ded3c3;
  border-radius: 9px;
  color: var(--red);
  background: #fff;
  font-size: 13px;
  font-weight: 900;
  text-align: center;
}

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

.wide-button,
.modal-actions button {
  min-height: 50px;
  padding: 10px 22px;
  border: 0;
  border-radius: 12px;
  font-weight: 900;
  cursor: pointer;
}

.wide-button {
  width: 100%;
  margin-top: 8px;
}

.accent {
  color: #fff;
  background: var(--red);
  box-shadow: 0 4px 0 #a83249;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 22px;
}

.modal-actions button:first-child {
  background: #e5dccf;
}

.modal-icon {
  margin: 0;
  color: var(--mint-dark);
  font-size: 48px;
}

.win-card {
  text-align: center;
}

.win-burst {
  margin: -8px 0 14px;
  color: var(--red);
  font-size: 24px;
  font-weight: 900;
  letter-spacing: .12em;
}

.reward-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 20px 0 12px;
  padding: 12px 16px;
  border-radius: 14px;
  background: #eee5d7;
  font-weight: 900;
}

.reward-total strong {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--purple);
  font-size: 27px;
}

.reward-total img {
  width: 30px;
  height: 30px;
}

.reward-details {
  display: grid;
  gap: 4px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 12px;
}

.reward-details div {
  display: flex;
  justify-content: space-between;
}

.text-link {
  display: inline-block;
  margin-top: 18px;
  color: var(--purple);
  font-size: 13px;
  font-weight: 900;
}

@keyframes deal-card {
  from { opacity: 0; transform: translateY(-24px) rotate(3deg) scale(.9); }
  to { opacity: 1; transform: none; }
}

@keyframes clear-card {
  45% { transform: translateY(-12px) rotate(-4deg) scale(1.06); filter: brightness(1.15); }
  to { opacity: 0; transform: translateY(-35px) rotate(7deg) scale(.78); }
}

@keyframes hint-pulse {
  50% { transform: translateY(-8px) scale(1.04); box-shadow: 0 0 0 6px var(--mint), 0 9px 0 rgba(27, 13, 37, .28); }
}

@keyframes combo-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.6) rotate(-8deg); }
  22% { opacity: 1; transform: translate(-50%, -50%) scale(1.08) rotate(2deg); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -75%) scale(1) rotate(0); }
}

@media (min-width: 681px) and (max-height: 680px) {
  .title-screen {
    padding-top: 8px;
  }

  .title-card {
    width: min(560px, 100%);
    padding: 10px 24px 12px;
  }

  .title-eyebrow {
    margin-bottom: 0;
    font-size: 10px;
  }

  .title-logo {
    width: 290px;
  }

  .title-character {
    width: 210px;
    margin: -6px auto -2px;
  }

  .title-copy {
    margin-bottom: 6px;
    font-size: 14px;
  }

  .title-rules div {
    padding: 5px 7px;
  }

  .title-rules span {
    min-height: 24px;
    font-size: 20px;
  }

  .title-rules p {
    margin-top: 1px;
    font-size: 10px;
    line-height: 1.35;
  }

  .title-note {
    margin: 6px 0 5px;
    font-size: 10px;
  }

  .title-actions {
    width: 300px;
    gap: 5px;
  }

  .title-start,
  .title-new {
    min-height: 40px;
    padding-block: 5px;
  }

  .title-small {
    margin-top: 4px;
    font-size: 10px;
  }
}

@media (max-width: 680px) {
  .topbar {
    min-height: 56px;
    grid-template-columns: 1fr auto;
  }

  .mini-logo {
    display: none;
  }

  .topbar-actions {
    gap: 6px;
  }

  .coin-pill {
    min-width: 72px;
    padding: 4px 7px;
  }

  .sound-toggle {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
    font-size: 18px;
  }

  main {
    padding: 18px 10px calc(24px + env(safe-area-inset-bottom));
  }

  .title-screen {
    min-height: calc(100dvh - 60px);
    padding: 10px 12px calc(20px + env(safe-area-inset-bottom));
  }

  .title-card {
    padding: 20px 16px;
    border-width: 4px;
    border-radius: 22px;
    box-shadow: 0 8px 0 #d6c9b7, 0 14px 28px rgba(70, 44, 84, .18);
  }

  .title-rules {
    gap: 6px;
  }

  .title-rules div {
    padding: 12px 5px;
    border-radius: 12px;
  }

  .title-rules p {
    font-size: 10px;
  }

  .game-heading {
    align-items: center;
    margin-inline: 4px;
  }

  .rule-lead {
    max-width: 220px;
    font-size: 12px;
    line-height: 1.5;
  }

  .quick-stats {
    gap: 5px;
  }

  .quick-stats div {
    min-width: 67px;
    padding: 6px 8px;
  }

  .quick-stats dd {
    font-size: 17px;
  }

  .table-wrap {
    padding: 9px;
    border-width: 4px;
    border-radius: 17px;
    box-shadow: 0 8px 0 #d6c9b7, 0 12px 20px rgba(70, 44, 84, .18);
  }

  .table-top {
    grid-template-columns: auto 1fr auto;
    font-size: 10px;
  }

  .tiny-card {
    display: none;
  }

  .stock-view,
  .shuffle-view {
    gap: 3px;
  }

  .stock-view b,
  .shuffle-view b {
    font-size: 13px;
  }

  .message {
    min-height: 27px;
    padding-inline: 7px;
    font-size: 10px;
  }

  .board {
    grid-template-columns: repeat(4, 1fr);
    gap: 7px;
    padding: 8px 0 2px;
  }

  .controls {
    gap: 7px;
    margin-top: 18px;
  }

  .controls button {
    min-height: 58px;
    padding-inline: 3px;
    border-radius: 11px;
  }

  .controls button > span {
    font-size: 21px;
  }

  .controls small {
    font-size: 10px;
  }

  .modal-card {
    padding: 28px 20px;
  }
}

@media (max-width: 390px) {
  h1 {
    font-size: 28px;
  }

  .eyebrow {
    font-size: 9px;
  }

  .quick-stats div {
    min-width: 62px;
  }
}

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

  .combo-pop.show {
    opacity: 1;
    animation: none !important;
    transform: translate(-50%, -50%) scale(1) rotate(0);
  }
}
