:root {
  --ink: #10211f;
  --muted: #365853;
  --panel: #fffaf0;
  --panel-strong: #fff0be;
  --felt: #146057;
  --felt-dark: #0a3732;
  --accent: #c83f31;
  --gold: #e4b84e;
  --blue: #2f80ed;
  --jade: #12b886;
  --tile: #fffdf2;
  --tile-edge: #d7c38d;
  --shadow: rgba(16, 33, 31, 0.24);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  background:
    radial-gradient(circle at 18% 10%, rgba(228, 184, 78, 0.22), transparent 18rem),
    radial-gradient(circle at 84% 8%, rgba(47, 128, 237, 0.2), transparent 15rem),
    linear-gradient(150deg, #061b23 0%, #10211f 48%, #271812 100%);
}

button {
  font: inherit;
}

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

.topbar,
.control-panel {
  border: 1px solid rgba(255, 250, 240, 0.22);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(11, 40, 37, 0.94), rgba(6, 25, 30, 0.92));
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.3);
  color: #fffaf0;
}

.topbar {
  min-height: 0;
  padding: 10px;
  display: grid;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 52px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 2px solid var(--tile-edge);
  border-radius: 7px;
  color: #f5d978;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.26);
  background: linear-gradient(145deg, #fffef7, #f6e3ad);
  box-shadow: 0 6px 0 #b59d63, 0 12px 20px rgba(0, 0, 0, 0.18);
  font-size: 25px;
  font-weight: 800;
}

h1,
p {
  margin: 0;
}

h1 {
  font-size: 25px;
  line-height: 1.05;
  letter-spacing: 0;
  color: #fffaf0;
}

.brand p {
  margin-top: 4px;
  color: #c9dfd7;
  font-size: 14px;
  font-weight: 700;
}

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

.stat {
  min-height: 50px;
  padding: 7px 8px;
  border: 1px solid #dfc06c;
  border-radius: 8px;
  color: #fffaf0;
  background: linear-gradient(180deg, #164a44, #0e302c);
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), inset 0 -3px 0 rgba(0, 0, 0, 0.22);
}

.stat span {
  display: block;
  color: #f1d486;
  font-size: 13px;
  font-weight: 800;
}

.stat strong {
  display: block;
  margin-top: 2px;
  font-size: 23px;
  line-height: 1;
}

.table-wrap {
  min-height: 0;
  display: grid;
}

.table-felt {
  position: relative;
  overflow: hidden;
  border: 5px solid #473119;
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 0 12%, rgba(255, 217, 132, 0.18) 12% 13%, transparent 13% 87%, rgba(255, 217, 132, 0.18) 87% 88%, transparent 88%),
    radial-gradient(circle at 50% 34%, rgba(255, 223, 125, 0.2), transparent 10rem),
    linear-gradient(180deg, #0d5760 0%, #09323c 48%, #071f25 100%);
  box-shadow: inset 0 0 32px rgba(0, 0, 0, 0.34), 0 24px 60px rgba(0, 0, 0, 0.24);
}

.table-felt::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(245, 217, 120, 0.28);
  border-radius: 5px;
  pointer-events: none;
  z-index: 2;
}

.table-felt::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(3, 14, 18, 0.04), rgba(3, 14, 18, 0.28));
  pointer-events: none;
  z-index: 1;
}

.scene3d {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  z-index: 0;
}

.scene3d-fallback .scene3d {
  display: none;
}

.board {
  position: relative;
  z-index: 3;
  width: 100%;
  height: var(--board-height, 390px);
  min-height: 0;
}

.tile {
  position: absolute;
  --layer-x: calc(var(--layer) * -2px);
  --layer-y: calc(var(--layer) * -4px);
  width: var(--tile-width, 36px);
  height: var(--tile-height, 45px);
  border: 0;
  border-radius: 8px;
  color: #123b36;
  background: transparent;
  filter: drop-shadow(0 6px 7px rgba(0, 0, 0, 0.28));
  cursor: pointer;
  pointer-events: none;
  display: grid;
  place-items: center;
  transform: translate(var(--layer-x), var(--layer-y));
  transition: filter 120ms ease, opacity 160ms ease, transform 120ms ease;
  user-select: none;
}

.tile::before,
.tile::after {
  display: none;
}

.tile-image {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  object-fit: fill;
  image-rendering: auto;
  transition: filter 120ms ease, opacity 120ms ease;
}

.tile.free {
  filter: drop-shadow(0 7px 8px rgba(0, 0, 0, 0.3)) brightness(1.03) saturate(1.06);
}

.tile.free:hover,
.tile.selected {
  filter: drop-shadow(0 8px 9px rgba(0, 0, 0, 0.34)) brightness(1.08) saturate(1.12);
}

.tile.selected {
  animation: selectLift 150ms ease-out;
}

.tile.selected .tile-image {
  filter: sepia(0.65) saturate(1.65) hue-rotate(122deg) brightness(1.14);
}

.tile.locked {
  cursor: not-allowed;
  filter: drop-shadow(0 5px 6px rgba(0, 0, 0, 0.2));
}

.tile.locked .tile-image {
  filter: saturate(0.58) brightness(0.78);
  opacity: 0.86;
}

.tile.hint {
  animation: pulse 700ms ease-in-out 3;
}

.tile.removing {
  opacity: 0;
  pointer-events: none;
  filter: drop-shadow(0 0 16px rgba(255, 216, 87, 0.9)) brightness(1.35);
  transform: scale(0.68) translate(var(--layer-x), calc(var(--layer-y) - 8px));
  transition: filter 180ms ease, opacity 340ms ease, transform 340ms ease;
}

.match-link {
  position: absolute;
  height: 0;
  z-index: 11990;
  pointer-events: none;
  transform-origin: left center;
}

.match-beam {
  position: absolute;
  left: 0;
  top: -2px;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 216, 87, 0), rgba(255, 244, 168, 0.96), rgba(18, 184, 134, 0.88), rgba(255, 216, 87, 0));
  box-shadow: 0 0 14px rgba(255, 216, 87, 0.85), 0 0 22px rgba(18, 184, 134, 0.45);
  transform: scaleX(0);
  transform-origin: left center;
  animation: linkBeam 520ms ease-out forwards;
}

.match-runner {
  position: absolute;
  left: -6px;
  top: -6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff4a8;
  box-shadow: 0 0 16px rgba(255, 244, 168, 0.95), 0 0 26px rgba(18, 184, 134, 0.72);
  animation: linkRunner 560ms ease-in-out forwards;
}

.link-score {
  position: absolute;
  top: -30px;
  color: #fff4a8;
  font-size: 18px;
  font-weight: 900;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.42);
  transform: translateX(-50%);
  animation: linkScore 720ms ease-out forwards;
}

.match-burst {
  position: absolute;
  width: 0;
  height: 0;
  z-index: 12000;
  pointer-events: none;
}

.match-burst i {
  position: absolute;
  left: -3px;
  top: -3px;
  width: 6px;
  height: 6px;
  border-radius: 2px;
  background: #ffd857;
  box-shadow: 0 0 10px rgba(255, 216, 87, 0.95);
  animation: burstSpark 620ms ease-out var(--delay) forwards;
}

.match-burst i:nth-child(3n) {
  background: #12b886;
  box-shadow: 0 0 10px rgba(18, 184, 134, 0.9);
}

.match-burst i:nth-child(4n) {
  background: #2f80ed;
  box-shadow: 0 0 10px rgba(47, 128, 237, 0.9);
}

.control-panel {
  padding: 10px;
  display: block;
  align-items: stretch;
}

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

.actions button {
  min-width: 0;
  height: 46px;
  border: 0;
  border-radius: 8px;
  color: white;
  background: linear-gradient(180deg, #17665d, #0f3f3a);
  font-weight: 900;
  font-size: 15px;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.22);
}

.actions button:hover {
  background: #0f5a51;
}

.actions button:nth-child(1) {
  background: linear-gradient(180deg, #2f80ed, #1756a7);
}

.actions button:nth-child(2) {
  background: linear-gradient(180deg, #d89922, #9d6111);
}

.actions button:nth-child(3) {
  background: linear-gradient(180deg, #cf3f31, #8d241d);
}

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

@keyframes pulse {
  50% {
    filter: drop-shadow(0 0 14px rgba(255, 216, 87, 0.95)) brightness(1.16);
  }
}

@keyframes linkBeam {
  0% {
    opacity: 0;
    transform: scaleX(0);
  }

  22% {
    opacity: 1;
  }

  72% {
    opacity: 1;
    transform: scaleX(1);
  }

  100% {
    opacity: 0;
    transform: scaleX(1);
  }
}

@keyframes linkRunner {
  0% {
    opacity: 0;
    transform: translateX(0) scale(0.7);
  }

  16% {
    opacity: 1;
  }

  82% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translateX(calc(var(--travel, 100px))) scale(1.15);
  }
}

@keyframes linkScore {
  0% {
    opacity: 0;
    transform: translate(-50%, 8px) scale(0.84);
  }

  20% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -22px) scale(1.08);
  }
}

@keyframes selectLift {
  0% {
    transform: translate(var(--layer-x), var(--layer-y));
  }

  55% {
    transform: translate(var(--layer-x), calc(var(--layer-y) - 4px));
  }

  100% {
    transform: translate(var(--layer-x), var(--layer-y));
  }
}

@keyframes scorePop {
  45% {
    transform: scale(1.14);
    color: #f5d978;
  }
}

@keyframes burstSpark {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.5) rotate(0deg);
  }

  16% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.15) rotate(170deg);
  }
}

.stat.pop strong {
  animation: scorePop 260ms ease;
}

@media (max-width: 760px) {
  .game-shell {
    min-height: 100svh;
  }
}

@media (min-width: 761px) {
  .game-shell {
    padding: 24px;
    gap: 16px;
  }

  .topbar {
    min-height: 92px;
    padding: 16px;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px;
  }

  .brand {
    gap: 14px;
  }

  .brand-mark {
    width: 56px;
    height: 68px;
    font-size: 32px;
  }

  h1 {
    font-size: 38px;
  }

  .brand p {
    font-size: 16px;
    margin-top: 6px;
  }

  .stat {
    min-height: 62px;
    padding: 9px 12px;
  }

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

  .stat strong {
    font-size: 24px;
    margin-top: 3px;
  }

  .table-wrap {
    min-height: 430px;
  }

  .table-felt {
    border-width: 10px;
  }

  .tile {
    --layer-x: calc(var(--layer) * -4px);
    --layer-y: calc(var(--layer) * -7px);
    filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.24));
    transform: translate(var(--layer-x), var(--layer-y));
  }

  .tile.free:hover,
  .tile.selected {
    transform: translate(var(--layer-x), var(--layer-y));
  }

  .tile.removing {
    transform: scale(0.68) translate(var(--layer-x), calc(var(--layer-y) - 10px));
  }

  .control-panel {
    padding: 14px;
    display: flex;
    justify-content: center;
  }

  .actions {
    display: flex;
  }

  .actions button {
    min-width: 86px;
  }
}
