:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #17120d;
  color: #fff8e8;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    linear-gradient(90deg, rgba(86, 54, 29, 0.16) 1px, transparent 1px) 0 0 / 18px 18px,
    linear-gradient(0deg, rgba(255, 236, 188, 0.04) 1px, transparent 1px) 0 0 / 18px 18px,
    radial-gradient(circle at 16% 12%, rgba(196, 139, 54, 0.22), transparent 25%),
    radial-gradient(circle at 84% 9%, rgba(34, 102, 112, 0.2), transparent 26%),
    linear-gradient(180deg, #241a12 0%, #17120d 58%, #090806 100%);
}

button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 850;
  letter-spacing: 0;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease, border-color 120ms ease, background 120ms ease;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

.app {
  width: min(100%, 540px);
  min-height: 100vh;
  padding: 12px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
  gap: 10px;
}

.masthead {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.masthead-actions {
  display: flex;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 3px;
  color: #e8bd73;
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  color: #fff4d6;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 8vw, 44px);
  line-height: 0.95;
}

h2 {
  font-size: 34px;
  line-height: 1;
}

.icon-button {
  width: 48px;
  min-width: 48px;
  border: 1px solid rgba(255, 248, 232, 0.16);
  background: rgba(15, 13, 10, 0.68);
  color: #fff4d6;
  font-size: 26px;
}

.icon-button.is-muted {
  opacity: 0.65;
  color: #cdbd9a;
}

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

.scorebar > div {
  min-width: 0;
  min-height: 58px;
  padding: 9px 10px;
  border: 1px solid rgba(255, 248, 232, 0.13);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 248, 232, 0.035) 1px, transparent 1px) 0 0 / 8px 8px,
    rgba(19, 13, 9, 0.78);
}

.scorebar span {
  display: block;
  color: #cdbd9a;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.scorebar strong {
  display: block;
  margin-top: 3px;
  color: #d6a645;
  font-size: 23px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

#comboPanel.is-hot,
#scoreText.is-hot {
  animation: comboHudPop 520ms ease;
}

#comboPanel.is-hot {
  border-color: rgba(214, 166, 69, 0.42);
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 224, 148, 0.16), transparent 60%),
    linear-gradient(90deg, rgba(255, 248, 232, 0.035) 1px, transparent 1px) 0 0 / 8px 8px,
    rgba(41, 25, 12, 0.92);
}

.board-shell {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
}

.board {
  width: min(100%, calc(100vh - 296px));
  max-width: 516px;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  gap: 0;
  overflow: hidden;
  border: 3px solid #4a3420;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(105, 63, 32, 0.35) 0 2px, transparent 2px 100%) 0 0 / 18px 100%,
    linear-gradient(180deg, rgba(255, 231, 178, 0.09) 0 1px, transparent 1px 100%) 0 0 / 100% 18px,
    #2b2015;
  box-shadow: 0 20px 55px rgba(0, 0, 0, 0.36);
  touch-action: manipulation;
}

.board.weaving {
  animation: weavePulse 320ms ease;
}

.board.combo-2 {
  box-shadow: 0 20px 55px rgba(0, 0, 0, 0.36), 0 0 0 3px rgba(214, 166, 69, 0.22);
}

.board.combo-3,
.board.combo-4,
.board.combo-5 {
  box-shadow:
    0 20px 55px rgba(0, 0, 0, 0.36),
    0 0 0 4px rgba(214, 166, 69, 0.28),
    0 0 38px rgba(214, 166, 69, 0.24);
}

.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(255, 248, 232, 0.085);
  border-right-color: rgba(255, 248, 232, 0.055);
  border-bottom-color: rgba(255, 248, 232, 0.055);
  background:
    linear-gradient(135deg, rgba(255, 239, 196, 0.025) 25%, transparent 25%) 0 0 / 10px 10px,
    #21180f;
}

.cell:nth-child(3n) {
  border-right-color: rgba(214, 166, 69, 0.5);
}

.cell:nth-child(n + 19):nth-child(-n + 27),
.cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom-color: rgba(214, 166, 69, 0.5);
}

.cell.filled::before,
.mini-cell.filled::before {
  content: "";
  position: absolute;
  inset: 9%;
  border-radius: 6px;
  background:
    var(--tile-pattern),
    linear-gradient(90deg, rgba(255, 244, 214, 0.12) 1px, transparent 1px) 0 0 / 7px 7px,
    linear-gradient(135deg, var(--tile-a), var(--tile-b));
  box-shadow:
    inset 0 0 0 1px rgba(255, 244, 214, 0.22),
    inset 0 -7px 0 rgba(0, 0, 0, 0.14),
    0 5px 10px rgba(0, 0, 0, 0.26);
}

.cell.filled::after,
.mini-cell.filled::after {
  content: "";
  position: absolute;
  inset: 24% 18%;
  border-radius: 999px;
  border: 2px solid rgba(255, 248, 232, 0.2);
  box-shadow: 10px 0 0 rgba(255, 248, 232, 0.08), -10px 0 0 rgba(255, 248, 232, 0.08);
  opacity: 0.62;
}

.cell.preview::before {
  content: "";
  position: absolute;
  inset: 9%;
  border-radius: 6px;
  background: rgba(214, 166, 69, 0.34);
  border: 2px dashed rgba(255, 248, 232, 0.78);
}

.cell.invalid::before {
  content: "";
  position: absolute;
  inset: 9%;
  border-radius: 6px;
  background: rgba(217, 79, 65, 0.42);
  border: 2px dashed rgba(255, 248, 232, 0.72);
}

.cell.clearing::before {
  animation: clearPop 260ms ease both;
}

.tray {
  min-height: 118px;
  display: grid;
  align-items: center;
}

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

.piece-button {
  min-height: 112px;
  padding: 8px;
  border: 1px solid rgba(255, 248, 232, 0.12);
  border-radius: 8px;
  background: rgba(16, 14, 11, 0.75);
  color: #fff8e8;
}

.piece-button.selected {
  border-color: #d6a645;
  background:
    linear-gradient(90deg, rgba(255, 244, 214, 0.04) 1px, transparent 1px) 0 0 / 9px 9px,
    rgba(74, 47, 24, 0.9);
  box-shadow: 0 0 0 2px rgba(214, 166, 69, 0.22);
}

.piece-button.used {
  opacity: 0.28;
}

.piece-name {
  display: block;
  margin-top: 6px;
  color: #d9caab;
  font-size: 12px;
  line-height: 1.1;
}

.mini-grid {
  width: 72px;
  height: 72px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 2px;
}

.mini-cell {
  position: relative;
  border-radius: 4px;
}

.upcoming {
  display: grid;
  gap: 8px;
}

.upcoming-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.upcoming-head span {
  color: #cdbd9a;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.upcoming-head strong {
  color: #e8bd73;
  font-size: 12px;
  font-weight: 800;
}

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

.upcoming-card {
  min-height: 90px;
  padding: 8px 6px;
  border: 1px solid rgba(255, 248, 232, 0.12);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 244, 214, 0.04) 1px, transparent 1px) 0 0 / 9px 9px,
    rgba(20, 15, 11, 0.72);
}

.upcoming-card .mini-grid {
  width: 58px;
  height: 58px;
}

.upcoming-card .piece-name {
  margin-top: 5px;
  font-size: 11px;
  text-align: center;
}

.ad-slot {
  min-height: 72px;
  padding: 6px 0 2px;
  border-top: 1px solid rgba(255, 248, 232, 0.08);
  border-bottom: 1px solid rgba(255, 248, 232, 0.08);
}

.ad-slot .adsbygoogle {
  overflow: hidden;
  border-radius: 8px;
}

.mobile-only {
  display: none;
}

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

.primary {
  background: #d6a645;
  color: #24170a;
}

.secondary {
  border: 1px solid rgba(255, 248, 232, 0.15);
  background: rgba(255, 248, 232, 0.08);
  color: #fff8e8;
}

.message {
  min-height: 22px;
  margin: 0;
  color: #d9caab;
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
}

.combo-burst {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  min-width: 148px;
  padding: 14px 18px;
  border: 1px solid rgba(255, 236, 188, 0.24);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 35%, rgba(255, 225, 147, 0.26), transparent 62%),
    rgba(28, 19, 11, 0.94);
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.34);
  color: #fff1c6;
  font-weight: 900;
  font-size: 26px;
  line-height: 1;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.82);
}

.combo-burst::after {
  content: attr(data-detail);
  display: block;
  margin-top: 7px;
  color: #e5c88a;
  font-size: 12px;
  font-weight: 800;
}

.combo-burst.show {
  animation: comboBurstIn 720ms cubic-bezier(.19,.89,.27,1) both;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(7, 6, 5, 0.78);
}

.hidden {
  display: none;
}

.modal-panel {
  width: min(100%, 390px);
  padding: 22px;
  border: 1px solid rgba(255, 248, 232, 0.16);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(214, 166, 69, 0.1), transparent 40%),
    linear-gradient(90deg, rgba(255, 248, 232, 0.035) 1px, transparent 1px) 0 0 / 9px 9px,
    #19150f;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.55);
}

.modal-panel p {
  margin: 9px 0 0;
  color: #d9caab;
  line-height: 1.45;
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 18px 0;
}

.modal-ad-slot {
  min-height: 72px;
  margin: 4px 0 18px;
}

.modal-ad-slot .adsbygoogle {
  overflow: hidden;
  border-radius: 8px;
}

.stat {
  min-height: 58px;
  padding: 9px;
  border-radius: 8px;
  background: rgba(255, 248, 232, 0.08);
}

.stat span {
  display: block;
  color: #cdbd9a;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 4px;
  color: #fff8e8;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.modal-actions {
  display: grid;
  gap: 10px;
}

.modal-actions.has-secondary {
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 820px) {
  .mobile-only {
    display: block;
  }
}

@keyframes clearPop {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(1.45);
    opacity: 0;
  }
}

@keyframes weavePulse {
  0% {
    filter: saturate(1);
    transform: scale(1);
  }
  45% {
    filter: saturate(1.25) brightness(1.08);
    transform: scale(0.992);
  }
  100% {
    filter: saturate(1);
    transform: scale(1);
  }
}

@keyframes comboHudPop {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.14);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes comboBurstIn {
  0% {
    opacity: 0;
    transform: translate(-50%, -42%) scale(0.78);
  }
  18% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08);
  }
  72% {
    opacity: 1;
    transform: translate(-50%, -53%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -64%) scale(0.96);
  }
}

@media (max-width: 390px) {
  .app {
    padding: 8px;
    gap: 8px;
  }

  .board {
    width: min(100%, calc(100vh - 282px));
  }

  .piece-button {
    min-height: 104px;
    padding: 6px;
  }

  .mini-grid {
    width: 62px;
    height: 62px;
  }
}
