:root {
  --bg: #f6f1e8;
  --ink: #20170f;
  --muted: #6f624f;
  --card: #fffaf1;
  --line: #e4d6bf;
  --brand: #b66d1d;
  --brand-2: #e2a53d;
  --danger: #a63b2a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  background:
    radial-gradient(circle at 10% 5%, #fff8e6 0%, transparent 35%),
    radial-gradient(circle at 95% 10%, #f3deb6 0%, transparent 28%),
    var(--bg);
  color: var(--ink);
}

.wrap {
  width: min(1100px, 94vw);
  margin: 0 auto;
}

.topbar {
  padding: 1.2rem 0 0.8rem;
}

.home-link {
  color: #7e4c18;
  text-decoration: none;
  font-size: 0.92rem;
}

h1 {
  margin: 0.3rem 0 0;
  font-size: clamp(1.8rem, 5vw, 2.8rem);
}

.subtitle {
  margin: 0.3rem 0 0;
  color: #473729;
}

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1rem;
  padding-bottom: 2rem;
}

.panel {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 16px;
  padding: 0.9rem;
  box-shadow: 0 10px 24px rgba(80, 57, 24, 0.08);
}

h2 {
  margin: 0;
  font-size: 1.2rem;
}

.stat-list {
  margin-top: 0.7rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.stat-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fffdf8;
  padding: 0.5rem;
}

.stat-item span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.stat-item strong {
  display: block;
  margin-top: 0.2rem;
  font-size: 1.08rem;
}

.actions {
  margin-top: 0.8rem;
}

.actions.secondary {
  display: flex;
  gap: 0.45rem;
}

.btn {
  width: 100%;
  border: 1px solid #cfb694;
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.6rem 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.btn.primary {
  border: none;
  color: #fff;
  background: linear-gradient(120deg, var(--brand), var(--brand-2));
}

.btn.danger {
  border: none;
  color: #fff;
  background: var(--danger);
}

.btn:active {
  transform: translateY(1px) scale(0.99);
}

.btn.shake {
  animation: shake 220ms linear;
}

.muted,
.hint {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.lucky-wrap {
  margin-top: 0.7rem;
}

.lucky-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.86rem;
  color: #62441e;
}

.lucky-head strong {
  font-size: 0.84rem;
}

.lucky-meter {
  margin-top: 0.3rem;
  height: 12px;
  border-radius: 999px;
  border: 1px solid #d3b896;
  background: #fff4dd;
  overflow: hidden;
}

.lucky-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #f09f2d, #f4d23f, #d061ee);
  transition: width 160ms ease;
}

.card-modal {
  position: fixed;
  inset: 0;
  background: rgba(25, 16, 8, 0.58);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 1rem;
}

.card-modal.hidden {
  display: none;
}

.card-modal-inner {
  width: min(760px, 96vw);
  background: #fff9ef;
  border: 1px solid #dec8a5;
  border-radius: 16px;
  padding: 0.9rem;
  box-shadow: 0 16px 44px rgba(24, 14, 7, 0.35);
}

.card-choices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.65rem;
}

.lucky-card-btn {
  border: 1px solid #d4b084;
  background: linear-gradient(180deg, #fffef9, #fff5e5);
  color: #322414;
  border-radius: 12px;
  padding: 0.7rem;
  text-align: left;
  cursor: pointer;
}

.lucky-card-btn h3 {
  margin: 0;
  font-size: 1rem;
}

.lucky-card-btn p {
  margin: 0.4rem 0 0;
  font-size: 0.84rem;
  color: #67553f;
}

.rebirth-wrap {
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px dashed #d9c5a5;
}

.rebirth-wrap h3 {
  margin: 0;
  font-size: 1.02rem;
}

.rebirth-grid {
  margin-top: 0.55rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.48rem;
}

.rebirth-btn {
  margin-top: 0.55rem;
  border: none;
  color: #fff;
  background: linear-gradient(120deg, #7e39b7, #cb68d8);
}

.meta-upgrades {
  margin-top: 0.55rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.45rem;
}

.seo-copy {
  margin: 0 auto 2rem;
  line-height: 1.65;
}

.seo-copy h2 {
  font-size: 1.38rem;
}

.seo-copy h3 {
  margin-top: 0.9rem;
  margin-bottom: 0.2rem;
  font-size: 1.06rem;
}

.seo-copy p,
.seo-copy ul,
.seo-copy ol {
  margin: 0.4rem 0;
}

.board-panel {
  position: relative;
  overflow: hidden;
}

.feedback {
  min-height: 1.3rem;
  color: #83531d;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.6rem;
}

.burst-banner {
  min-height: 1.5rem;
  margin-bottom: 0.5rem;
  font-weight: 900;
  letter-spacing: 0.02em;
  color: #c92d2d;
  text-shadow: 0 1px 0 #ffe9c9, 0 0 14px rgba(214, 72, 72, 0.35);
}

.burst-banner.hidden {
  visibility: hidden;
}

.burst-banner.show {
  visibility: visible;
  animation: burstPop 320ms ease-out;
}

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.5rem;
}

.cell {
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  border: 1px dashed #d5c2a2;
  background: #fdf7eb;
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.05rem;
  color: #8a6f4b;
  user-select: none;
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.cell.has-block {
  cursor: pointer;
  border-style: solid;
  border-color: #ccb08a;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
  box-shadow: 0 5px 14px rgba(50, 30, 10, 0.18);
}

.cell.has-block:active {
  transform: scale(0.96);
}

.cell.spawn {
  animation: popIn 220ms ease-out;
}

.cell.merge-pop {
  animation: mergePulse 360ms ease-out;
}

.cell.lucky-aura {
  box-shadow: 0 0 0 3px rgba(235, 210, 84, 0.7), 0 8px 22px rgba(227, 123, 255, 0.45);
}

.cell.milestone::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 10px;
  pointer-events: none;
  animation: milestonePulse 2s ease-in-out infinite;
}

.cell.milestone::after {
  content: "";
  position: absolute;
  inset: -35%;
  pointer-events: none;
  opacity: 0.22;
  transform: rotate(0deg);
  animation: milestoneSpin 5s linear infinite;
}

.cell.milestone-1::before {
  box-shadow: inset 0 0 0 2px rgba(255, 246, 164, 0.85), 0 0 14px rgba(255, 224, 89, 0.42);
}

.cell.milestone-1::after {
  background: conic-gradient(from 0deg, rgba(255, 250, 176, 0.95), rgba(255, 196, 61, 0.1), rgba(255, 250, 176, 0.95));
}

.cell.milestone-2::before {
  box-shadow: inset 0 0 0 2px rgba(181, 246, 255, 0.92), 0 0 14px rgba(118, 219, 245, 0.45);
}

.cell.milestone-2::after {
  background: conic-gradient(from 0deg, rgba(182, 244, 255, 0.95), rgba(101, 177, 255, 0.12), rgba(182, 244, 255, 0.95));
}

.cell.milestone-3::before {
  box-shadow: inset 0 0 0 2px rgba(246, 198, 255, 0.95), 0 0 14px rgba(220, 137, 255, 0.42);
}

.cell.milestone-3::after {
  background: conic-gradient(from 0deg, rgba(245, 205, 255, 0.95), rgba(245, 120, 214, 0.12), rgba(245, 205, 255, 0.95));
}

.cell.selected {
  outline: 3px solid #2d9f5a;
  outline-offset: 1px;
  filter: saturate(1.2);
}

.effects-layer {
  pointer-events: none;
  position: absolute;
  inset: 0;
}

.float-text {
  position: absolute;
  transform: translate(-50%, -50%);
  color: #a65b19;
  font-weight: 800;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
  animation: floatUp 680ms ease-out forwards;
}

.float-text.lucky {
  color: #b244c9;
}

.float-text.crit {
  color: #d12c2c;
  font-size: 1.05rem;
  text-shadow: 0 1px 0 rgba(255, 238, 190, 0.75);
  animation: critFloat 1450ms ease-out forwards;
}

.board-panel.flash {
  animation: flash 240ms ease-out;
}

@keyframes floatUp {
  from {
    opacity: 0.95;
    transform: translate(-50%, -50%) scale(0.95);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -150%) scale(1.06);
  }
}

@keyframes critFloat {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.88) rotate(-3deg);
  }
  35% {
    transform: translate(-50%, -66%) scale(1.2) rotate(3deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -170%) scale(1.02) rotate(0);
  }
}

@keyframes burstPop {
  0% {
    transform: scale(0.92);
    opacity: 0.25;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes popIn {
  0% {
    transform: scale(0.7);
  }
  70% {
    transform: scale(1.07);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes mergePulse {
  0% {
    transform: scale(0.88);
    filter: brightness(0.95);
  }
  45% {
    transform: scale(1.12);
    filter: brightness(1.2);
  }
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

@keyframes flash {
  0% {
    box-shadow: inset 0 0 0 0 rgba(255, 199, 92, 0.4);
  }
  100% {
    box-shadow: inset 0 0 0 18px rgba(255, 199, 92, 0);
  }
}

@keyframes milestonePulse {
  0% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.5;
  }
}

@keyframes milestoneSpin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes shake {
  0% { transform: translateX(0); }
  30% { transform: translateX(-3px); }
  60% { transform: translateX(3px); }
  100% { transform: translateX(0); }
}

@media (max-width: 920px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .board {
    gap: 0.34rem;
  }

  .cell {
    font-size: 0.94rem;
  }

  .actions.secondary {
    flex-wrap: wrap;
  }

  .actions.secondary .btn {
    min-width: 140px;
  }

  .card-choices {
    grid-template-columns: 1fr;
  }
}
