:root {
  --table: #28704f;
  --table-dark: #174a39;
  --table-deep: #102a2a;
  --panel: #172627;
  --panel-2: #263637;
  --panel-3: #354242;
  --cream: #fff7e8;
  --card: #fffdf5;
  --card-shadow: #233333;
  --ink: #f7f2df;
  --dark-ink: #1c2530;
  --muted: #b7c1b8;
  --red: #ff4a43;
  --red-dark: #b8272c;
  --orange: #ff9b17;
  --blue: #1398f2;
  --gold: #f7bd3d;
  --green: #37b978;
  --locked: #475354;
  --locked-2: #3c4748;
  --shadow: rgba(7, 18, 20, 0.55);
  --pile-column-height: 612px;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
}

@keyframes cardHoverLift {
  0% {
    transform: translateY(0) rotate(0deg);
  }
  45% {
    transform: translateY(-3px) rotate(-0.7deg);
  }
  100% {
    transform: translateY(-2px) rotate(-0.35deg);
  }
}

@keyframes buttonHoverPop {
  0% {
    transform: translateY(0) scale(1);
  }
  55% {
    transform: translateY(-2px) scale(1.018);
  }
  100% {
    transform: translateY(-1px) scale(1.01);
  }
}

@keyframes invalidShake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-5px);
  }
  40% {
    transform: translateX(5px);
  }
  60% {
    transform: translateX(-3px);
  }
  80% {
    transform: translateX(3px);
  }
}

@keyframes invalidFlash {
  0%,
  100% {
    border-color: #101819;
    background: linear-gradient(180deg, #314243, #1b2c2d);
  }
  30% {
    border-color: var(--red);
    background: linear-gradient(180deg, #5a2b31, #2d1c20);
  }
}

@keyframes cardPlace {
  0% {
    opacity: 0.35;
    transform: translateY(-18px) scale(0.98);
  }
  65% {
    opacity: 1;
    transform: translateY(3px) scale(1.01);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes statPop {
  0% {
    transform: scale(1);
  }
  42% {
    transform: scale(1.08);
    filter: brightness(1.18);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes roundClear {
  0%,
  100% {
    box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.06), 0 20px 48px var(--shadow);
  }
  45% {
    box-shadow:
      inset 0 0 0 3px rgba(255, 255, 255, 0.08),
      inset 0 0 0 8px rgba(247, 189, 61, 0.18),
      0 20px 48px var(--shadow);
  }
}

.invalid-shake {
  animation: invalidShake 280ms ease both;
}

.invalid-flash {
  animation: invalidFlash 420ms ease both;
}

.placed-card {
  animation: cardPlace 260ms ease-out both;
}

.stat-pop {
  animation: statPop 260ms ease-out both;
}

.round-clear {
  animation: roundClear 720ms ease-out both;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", "Microsoft JhengHei UI", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  font-weight: 700;
  letter-spacing: 0;
  background:
    radial-gradient(ellipse at 30% 30%, rgba(255, 255, 255, 0.07), transparent 18rem),
    radial-gradient(ellipse at 75% 18%, rgba(255, 255, 255, 0.06), transparent 22rem),
    linear-gradient(135deg, #0b2024, #123e34 45%, #0d2527);
}

button,
input {
  font: inherit;
}

.board {
  display: grid;
  grid-template-columns: 132px minmax(300px, 1fr) minmax(300px, 1fr) 250px;
  align-items: stretch;
  gap: 12px;
  width: min(1280px, calc(100vw - 20px));
  height: calc(100vh - 20px);
  height: calc(100dvh - 20px);
  min-height: 0;
  margin: 10px auto;
  padding: 12px;
  border: 4px solid #1b2a2b;
  border-radius: 8px;
  background:
    radial-gradient(ellipse at 20% 24%, rgba(255, 255, 255, 0.065), transparent 5rem),
    radial-gradient(ellipse at 70% 42%, rgba(255, 255, 255, 0.055), transparent 7rem),
    radial-gradient(ellipse at 38% 78%, rgba(255, 255, 255, 0.045), transparent 6rem),
    repeating-linear-gradient(32deg, rgba(255, 255, 255, 0.025) 0 18px, transparent 18px 42px),
    linear-gradient(145deg, var(--table), var(--table-dark));
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.06), 0 20px 48px var(--shadow);
}

.left-panel,
.play-grid,
.goal-area,
.side-panel {
  min-height: 0;
  border: 4px solid #101819;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow: 7px 7px 0 rgba(10, 20, 22, 0.65), inset 0 2px 0 rgba(255, 255, 255, 0.08);
}

.play-grid,
.goal-area {
  display: grid;
  align-content: center;
  grid-template-rows: auto auto;
  overflow: hidden;
}

.left-panel {
  display: grid;
  align-content: center;
  grid-template-rows: auto auto auto auto auto auto;
  overflow: hidden;
}

.pink {
  color: #fff8e8;
  background: linear-gradient(180deg, var(--orange), #b77300);
}

.cyan {
  background: linear-gradient(180deg, #edf5ed, #c7d8d1);
}

.label {
  display: grid;
  place-items: center;
  min-height: 58px;
  border-bottom: 4px solid #101819;
  color: #fff8e8;
  font-size: 28px;
  line-height: 1;
  font-weight: 800;
  text-shadow: 2px 2px 0 #263232;
}

.current-card,
.number {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 0;
  border: 0;
  border-bottom: 4px solid #101819;
  color: var(--dark-ink);
  font-size: 72px;
  line-height: 1;
  font-weight: 800;
  text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.55);
}

.current-card {
  position: relative;
  width: calc(100% - 18px);
  aspect-ratio: 5 / 7;
  min-height: 0;
  justify-self: center;
  margin: 9px 0;
  cursor: pointer;
  overflow: hidden;
  border: 7px solid #f7f2e4;
  border-radius: 4px;
  background:
    radial-gradient(circle at 50% 46%, rgba(255, 74, 67, 0.08), transparent 2.7rem),
    linear-gradient(90deg, var(--red) 0 6px, transparent 6px calc(100% - 6px), var(--red) calc(100% - 6px)),
    linear-gradient(180deg, #fffef8, #e9edf0);
  box-shadow:
    inset 0 0 0 2px #d5dde0,
    inset 0 0 0 7px rgba(255, 255, 255, 0.5),
    6px 7px 0 var(--card-shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: color 140ms ease, transform 140ms ease;
}

.number {
  min-height: 118px;
  max-height: 144px;
}

.current-card::after {
  content: "";
  position: absolute;
  inset: 9px;
  border: 2px dashed rgba(255, 74, 67, 0.28);
  border-radius: 5px;
  pointer-events: none;
}

.current-card::before {
  content: attr(data-rank);
  position: absolute;
  top: 10px;
  left: 12px;
  color: var(--red);
  font-size: 19px;
  line-height: 1;
  text-shadow: none;
}

.current-card.rank-wide {
  font-size: 58px;
}

.current-card.rank-wide::before {
  font-size: 16px;
  letter-spacing: -1px;
}

.current-card:hover,
.current-card.active {
  color: var(--red);
}

.current-card:hover {
  transform: translateY(-1px);
}

.current-card.empty {
  color: rgba(247, 242, 223, 0.58);
  cursor: default;
  border-color: #687273;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.04) 0 10px, transparent 10px 20px),
    linear-gradient(180deg, var(--locked), var(--locked-2));
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.08),
    4px 5px 0 rgba(18, 30, 31, 0.75);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35);
}

.current-card.empty::before {
  content: "";
}

.current-card.empty::after {
  border-color: rgba(247, 242, 223, 0.26);
}

.current-card.empty:hover {
  color: rgba(247, 242, 223, 0.58);
  transform: none;
}

.headers {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px;
}

.tab {
  position: relative;
  min-height: 42px;
  border: 3px solid #d7c79d;
  border-radius: 8px;
  color: #fff8e8;
  cursor: pointer;
  overflow: hidden;
  font-size: 21px;
  line-height: 1;
  font-weight: 800;
  text-shadow: 2px 2px 0 #101819;
  background: linear-gradient(180deg, #55706b, #2f4947);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.2),
    inset 0 -4px 0 rgba(0, 0, 0, 0.2),
    0 4px 0 #101819,
    0 0 0 1px rgba(255, 248, 232, 0.12);
  transition: filter 140ms ease, transform 140ms ease;
}

.tab::before {
  content: none;
}

.tab::after {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(255, 248, 232, 0.12);
  border-radius: 5px;
  pointer-events: none;
}

.tab:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(58px, 1fr));
  gap: 8px;
  padding: 0 10px 12px;
}

.stack-grid {
  align-items: start;
  max-height: 100%;
  overflow: auto;
}

.goal-grid {
  align-items: start;
  max-height: 100%;
  overflow: hidden;
}

.cell {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 34px;
  border: 3px solid #d7dce0;
  border-radius: 7px;
  color: var(--dark-ink);
  background: rgba(255, 255, 255, 0.12);
  font-size: 26px;
  line-height: 1;
  font-weight: 800;
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.45);
  cursor: default;
}

.stack-column {
  position: relative;
  min-height: var(--pile-column-height);
  border: 3px dashed rgba(230, 238, 238, 0.72);
  border-radius: 8px;
  padding: 8px 6px 10px;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

.stack-placeholder {
  width: 100%;
  height: 48px;
  border: 3px solid rgba(230, 238, 238, 0.78);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.stack-card,
.goal-card {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 96px;
  border: 5px solid #f7f2e4;
  border-radius: 8px;
  color: var(--dark-ink);
  background:
    radial-gradient(circle at 50% 50%, rgba(19, 152, 242, 0.08), transparent 1.9rem),
    linear-gradient(90deg, var(--red) 0 5px, transparent 5px calc(100% - 5px), var(--red) calc(100% - 5px)),
    linear-gradient(180deg, #fffef8, #e7edf0);
  box-shadow:
    inset 0 0 0 2px #d6dde0,
    inset 0 0 0 6px rgba(255, 255, 255, 0.46),
    5px 6px 0 var(--card-shadow);
  font-size: 30px;
  font-weight: 800;
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.45);
  cursor: default;
  z-index: calc(var(--i) + 1);
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.stack-card {
  margin-top: -68px;
}

.stack-card:first-child {
  margin-top: 0;
}

.stack-card span,
.goal-card span {
  position: relative;
  z-index: 2;
  min-width: 1.35em;
  text-align: center;
  font-size: 1.16em;
}

.stack-card.rank-wide span,
.goal-card.rank-wide span {
  font-size: 0.95em;
  letter-spacing: -1px;
}

.stack-card::before,
.goal-card::before {
  content: attr(data-rank);
  position: absolute;
  top: 7px;
  left: 8px;
  color: var(--red);
  font-size: 13px;
  line-height: 1;
  text-shadow: none;
  z-index: 2;
}

.stack-card.rank-wide::before,
.goal-card.rank-wide::before,
.stack-card.rank-wide::after,
.goal-card.rank-wide::after {
  font-size: 10px;
  letter-spacing: -0.5px;
}

.stack-card::after,
.goal-card::after {
  content: attr(data-rank);
  position: absolute;
  right: 8px;
  bottom: 7px;
  color: var(--blue);
  font-size: 13px;
  line-height: 1;
  text-shadow: none;
  transform: rotate(180deg);
  z-index: 2;
}

.stack-card.top-card {
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.stack-card.top-card:hover,
.stack-card.selected {
  border-color: var(--gold);
  box-shadow: 5px 6px 0 var(--card-shadow), 0 0 0 4px rgba(247, 189, 61, 0.35);
  transform: translateY(-2px);
}

.goal-column {
  position: relative;
  min-height: var(--pile-column-height);
  border: 3px dashed rgba(230, 238, 238, 0.42);
  border-radius: 8px;
  padding: 8px 6px 10px;
  background: rgba(255, 255, 255, 0.035);
  cursor: pointer;
}

.goal-card {
  margin-top: -58px;
  cursor: pointer;
}

.goal-card:first-child {
  margin-top: 0;
}

.goal-card.locked {
  color: rgba(247, 242, 223, 0.55);
  border-color: #687273;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.04) 0 7px, transparent 7px 14px),
    linear-gradient(180deg, var(--locked), var(--locked-2));
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.08),
    3px 4px 0 rgba(18, 30, 31, 0.75);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35);
}

.goal-card.locked::before,
.goal-card.locked::after {
  color: rgba(247, 242, 223, 0.42);
}

.goal-card.done {
  border-color: #f7f2e4;
  background:
    radial-gradient(circle at 50% 50%, rgba(55, 185, 120, 0.16), transparent 1.9rem),
    linear-gradient(90deg, var(--green) 0 5px, transparent 5px calc(100% - 5px), var(--green) calc(100% - 5px)),
    linear-gradient(180deg, #f8fff5, #d7f1dd);
  color: #173023;
}

.drag-source {
  opacity: 0.42;
}

.drag-source-hidden {
  opacity: 0;
}

.drag-ghost {
  position: fixed !important;
  z-index: 9999;
  margin: 0 !important;
  pointer-events: none;
  cursor: grabbing;
  opacity: 0.96;
  transform: rotate(-1.2deg) scale(1.02);
  box-shadow:
    inset 0 0 0 2px #d6dde0,
    inset 0 0 0 6px rgba(255, 255, 255, 0.46),
    0 16px 28px rgba(0, 0, 0, 0.42) !important;
}

.stack-column.drop-available,
.goal-column.drop-available {
  border-color: rgba(247, 242, 223, 0.82);
  background: rgba(255, 248, 232, 0.055);
  box-shadow: inset 0 0 0 3px rgba(255, 248, 232, 0.08);
}

.stack-tab.drop-available,
.goal-tab.drop-available {
  border-color: #f0dfac;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.2),
    inset 0 -4px 0 rgba(0, 0, 0, 0.2),
    0 4px 0 #101819,
    0 0 0 4px rgba(255, 248, 232, 0.16);
}

.stack-column.drop-active,
.goal-column.drop-active,
.stack-tab.drop-active,
.goal-tab.drop-active {
  filter: brightness(1.16);
}

.side-panel {
  display: grid;
  grid-template-rows: auto auto auto auto 1fr;
  align-content: center;
  gap: 12px;
  padding: 12px;
}

.score-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-card {
  min-height: 88px;
  border: 4px solid #101819;
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  background: linear-gradient(180deg, var(--panel-3), var(--panel));
  box-shadow: 5px 5px 0 rgba(10, 20, 22, 0.65), inset 0 2px 0 rgba(255, 255, 255, 0.08);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 16px;
  text-shadow: 2px 2px 0 #101819;
}

.stat-card strong {
  display: block;
  margin-top: 2px;
  color: #fff8e8;
  font-size: 45px;
  line-height: 1;
  font-weight: 800;
  text-shadow: 4px 4px 0 #101819;
}

.stat-card.total {
  grid-column: 1 / -1;
}

.stat-card.total strong {
  color: var(--red);
  font-size: 58px;
}

.stat-card.total small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  text-shadow: 2px 2px 0 #101819;
}

.stat-card.total b {
  color: var(--gold);
  font-size: 20px;
}

.level-control {
  border: 4px solid #101819;
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: linear-gradient(180deg, #314243, #1b2c2d);
  box-shadow: 5px 5px 0 rgba(10, 20, 22, 0.65);
}

.settings-panel {
  padding: 10px;
}

.settings-panel summary {
  cursor: pointer;
  color: #fff8e8;
  font-size: 16px;
  text-shadow: 2px 2px 0 #101819;
}

.settings-panel summary::marker {
  color: var(--orange);
}

.level-control label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 16px;
  text-shadow: 2px 2px 0 #101819;
}

.level-control label strong {
  color: var(--orange);
  font-size: 32px;
  line-height: 1;
}

.difficulty-name {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  margin-top: 8px;
  border: 3px solid #101819;
  border-radius: 8px;
  padding: 4px 10px;
  color: #fff8e8;
  background: linear-gradient(180deg, var(--orange), #bd7100);
  font-size: 18px;
  text-shadow: 2px 2px 0 #101819;
  box-shadow: 3px 3px 0 rgba(10, 20, 22, 0.65);
}

.difficulty-easy {
  background: linear-gradient(180deg, #42d66b, #178942);
}

.difficulty-normal {
  background: linear-gradient(180deg, #8fdd4b, #4d9c2d);
}

.difficulty-hard {
  background: linear-gradient(180deg, #ffd34c, #d18b08);
}

.difficulty-expert {
  background: linear-gradient(180deg, #ff8d2b, #c24712);
}

.difficulty-challenge {
  background: linear-gradient(180deg, var(--red), var(--red-dark));
}

.level-control input {
  width: 100%;
  margin: 12px 0 8px;
  accent-color: var(--red);
}

.level-caption {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.hint-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 9px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 2px solid rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font-size: 14px;
  text-shadow: 2px 2px 0 #101819;
  cursor: pointer;
}

.hint-toggle input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--orange);
}

.seed-control {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 2px solid rgba(255, 255, 255, 0.08);
}

.seed-control label {
  margin-bottom: 6px;
}

.seed-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 6px;
}

.seed-row input,
.seed-row button {
  min-height: 34px;
  border: 3px solid #101819;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 800;
}

.seed-row input {
  min-width: 0;
  padding: 4px 8px;
  color: var(--dark-ink);
  background: linear-gradient(180deg, #fffef8, #dce8e0);
  text-transform: uppercase;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.55);
}

.seed-row button {
  padding: 4px 7px;
  color: #fff8e8;
  cursor: pointer;
  text-shadow: 2px 2px 0 #101819;
  background: linear-gradient(180deg, #55706b, #2f4947);
  box-shadow: 3px 3px 0 rgba(10, 20, 22, 0.65);
}

.seed-row button:hover {
  filter: brightness(1.08);
}

.controls {
  display: grid;
  gap: 10px;
}

.controls button {
  min-height: 58px;
  border: 0;
  border-radius: 8px;
  color: #fff8e8;
  cursor: pointer;
  font-size: 24px;
  font-weight: 800;
  text-shadow: 2px 2px 0 #101819;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.2), 0 5px 0 #101819, 0 8px 12px rgba(0, 0, 0, 0.24);
  transition: filter 140ms ease, transform 140ms ease;
}

.controls button:nth-child(1) {
  background: linear-gradient(180deg, var(--blue), #096fb7);
}

.controls button:nth-child(2) {
  background: linear-gradient(180deg, var(--red), var(--red-dark));
}

.controls button:nth-child(3) {
  background: linear-gradient(180deg, var(--orange), #bd7100);
}

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

.controls button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

#message {
  margin: 0;
  min-height: 86px;
  border: 4px solid #101819;
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  background: linear-gradient(180deg, #314243, #1b2c2d);
  font-size: 15px;
  line-height: 1.5;
  font-weight: 700;
  text-shadow: 2px 2px 0 #101819;
  box-shadow: 5px 5px 0 rgba(10, 20, 22, 0.65);
}

#message.stuck-message {
  border-color: var(--gold);
  background: linear-gradient(180deg, #4a3f27, #211f1a);
}

@media (max-width: 1080px) {
  :root {
    --pile-column-height: 574px;
  }

  .board {
    grid-template-columns: 104px minmax(320px, 1fr) minmax(320px, 1fr) 184px;
    gap: 8px;
    padding: 8px;
  }

  .label {
    min-height: 60px;
    font-size: 22px;
  }

  .current-card {
    font-size: 54px;
  }

  .number {
    min-height: 96px;
    max-height: 120px;
    font-size: 54px;
  }

  .headers,
  .grid {
    gap: 6px;
    padding-left: 8px;
    padding-right: 8px;
  }

  .tab {
    min-height: 40px;
    font-size: 18px;
  }

  .stack-column,
  .goal-column {
    padding-left: 5px;
    padding-right: 5px;
  }

  .stack-card,
  .goal-card {
    height: 88px;
    border-width: 4px;
    font-size: 27px;
  }

  .stack-card {
    margin-top: -63px;
  }

  .goal-card {
    margin-top: -53px;
  }

  .stat-card strong {
    font-size: 34px;
  }

  .stat-card.total strong {
    font-size: 46px;
  }

  .side-panel {
    gap: 8px;
    padding: 8px;
  }

  .stat-card {
    min-height: 76px;
    padding: 8px;
  }

  .stat-card span,
  .level-control label,
  #message {
    font-size: 13px;
  }

  .level-control {
    padding: 0;
  }

  .difficulty-name {
    min-height: 28px;
    font-size: 15px;
  }

  .controls button {
    min-height: 50px;
    font-size: 19px;
  }
}

@media (max-width: 820px) {
  .board {
    grid-template-columns: 104px 1fr 1fr;
  }

  .side-panel {
    grid-column: 1 / -1;
    grid-template-columns: 1.2fr 1fr 1fr;
    grid-template-rows: auto;
    align-content: stretch;
    align-items: stretch;
  }

  .score-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .stat-card.total {
    grid-column: auto;
  }
}

@media (max-width: 640px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow: auto;
  }

  .board {
    grid-template-columns: 1fr;
    width: 100%;
    min-height: 100dvh;
    height: auto;
    margin: 0;
    padding: 8px;
    gap: 10px;
    border-width: 0;
    border-radius: 0;
  }

  .left-panel {
    align-content: stretch;
    grid-template-columns: 0.8fr 1.1fr 0.8fr 1fr 0.8fr 1fr;
    grid-template-rows: 86px;
    align-items: stretch;
  }

  .label {
    min-height: 0;
    border-bottom: 0;
    border-right: 3px solid #101819;
    font-size: 20px;
  }

  .current-card,
  .number {
    min-height: 0;
    border-bottom: 0;
    border-right: 3px solid #101819;
    font-size: 42px;
  }

  .current-card {
    border-width: 5px;
  }

  .play-grid,
  .goal-area {
    align-content: stretch;
    grid-template-rows: auto auto;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .side-panel {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    align-content: stretch;
    gap: 10px;
  }

  .headers,
  .grid {
    min-width: 430px;
  }

  .headers {
    gap: 7px;
    padding: 8px;
  }

  .tab {
    min-height: 44px;
    font-size: 20px;
  }

  .grid {
    gap: 7px;
    padding: 0 8px 10px;
  }

  .stack-column,
  .goal-column {
    min-height: 374px;
    padding: 7px 5px 8px;
  }

  .stack-card,
  .goal-card {
    height: 82px;
    border-width: 4px;
    font-size: 25px;
  }

  .stack-card {
    margin-top: -61px;
  }

  .goal-card {
    margin-top: -55px;
  }

  .stack-card:first-child,
  .goal-card:first-child {
    margin-top: 0;
  }

  .stack-card::before,
  .goal-card::before,
  .stack-card::after,
  .goal-card::after {
    font-size: 11px;
  }

  .score-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .stat-card {
    min-height: 72px;
    padding: 8px;
  }

  .stat-card span {
    font-size: 13px;
  }

  .stat-card strong,
  .stat-card.total strong {
    font-size: 34px;
  }

  .stat-card.total {
    grid-column: auto;
  }

  .level-control {
    padding: 10px;
  }

  .controls {
    grid-template-columns: repeat(3, 1fr);
  }

  .controls button {
    min-height: 52px;
    font-size: 19px;
  }

  #message {
    min-height: 72px;
    font-size: 14px;
  }
}
