:root {
  --paper: #fffaf2;
  --cream: #fff0d5;
  --ink: #11100f;
  --orange: #eb922d;
  --yellow: #f3bd43;
  --aqua: #78c7cf;
  --green: #88a95b;
  --coral: #eb8065;
  --pink: #e8b5b0;
  --purple: #9970a9;
  --red: #e52b34;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; min-height: 100%; background: var(--paper); color: var(--ink); }

body {
  min-height: 100svh;
  overflow-x: hidden;
  font-family: Huninn, "Hannotate TC", "HanziPen TC", Klee, DFKai-SB, BiauKai, cursive;
  background-image:
    radial-gradient(circle at 18% 9%, rgba(235,146,45,.055) 0 1px, transparent 1.5px),
    radial-gradient(circle at 78% 65%, rgba(17,16,15,.04) 0 1px, transparent 1.4px),
    linear-gradient(92deg, transparent 0 49%, rgba(184,130,69,.025) 50%, transparent 51%);
  background-size: 16px 18px, 23px 25px, 100% 7px;
}

button { font: inherit; color: inherit; }

.app {
  width: min(100%, 440px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 17px max(17px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
}

.topbar {
  position: relative;
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 9px 7px 7px;
  background: var(--cream);
  border-top: 2px solid var(--ink);
  border-bottom: 4px solid var(--orange);
}

.brand { display: flex; align-items: center; min-width: 0; gap: 7px; flex: 1; }
.brand h1 { margin: 0 0 3px; font-size: clamp(1.12rem, 4.8vw, 1.48rem); letter-spacing: .03em; font-weight: 800; white-space: nowrap; }
.brand p { margin: 0; color: #5d574e; font-size: .79rem; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }

.mascot-wrap {
  width: 94px;
  height: 88px;
  flex: 0 0 auto;
  overflow: visible;
  display: grid;
  place-items: end center;
}
.mascot-wrap img {
  width: 104px;
  height: 104px;
  object-fit: contain;
  object-position: center bottom;
  transform: translate(-2px, 4px);
  transform-origin: 50% 80%;
  filter: drop-shadow(2px 3px 0 rgba(17,16,15,.18));
}
.mascot-wrap img.pleased { animation: catNod .44s ease; }
.mascot-wrap img.pounce { animation: catPounce .55s cubic-bezier(.2,.9,.3,1.2); }

.icon-button {
  width: 39px;
  height: 39px;
  flex: 0 0 auto;
  border: 2px solid var(--ink);
  border-radius: 14px 7px 13px 8px;
  background: var(--paper);
  font-size: 1.15rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
}

.status { position: relative; z-index: 2; display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 8px; }
.score-card, .paw-card {
  min-height: 57px;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 14px 7px 16px 9px;
  padding: 7px 10px;
  box-shadow: 3px 4px 0 var(--ink);
}
.score-card:nth-child(1) { background: #fff3dd; }
.score-card:nth-child(2) { background: #f6dfd5; }
.paw-card { background: #e8f0d8; }
.score-card span, .paw-card span { display: block; font-size: .69rem; color: #5c574f; letter-spacing: .12em; }
.score-card strong { display: block; margin-top: 1px; font-size: 1.13rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.paw-top { display: flex; justify-content: space-between; align-items: baseline; }
.paw-top strong { color: #b96715; font-size: 1.12rem; }
.meter { height: 7px; margin-top: 9px; border: 1.5px solid var(--ink); border-radius: 9px 5px 8px 6px; background: var(--paper); overflow: hidden; }
.meter i { display: block; width: 0; height: 100%; background: var(--orange); transition: width .35s ease; }

.board-shell { position: relative; width: 100%; }
#floatScore { position: absolute; z-index: 8; left: 50%; top: -8px; color: #bd6314; font-size: 1.2rem; font-weight: 800; opacity: 0; pointer-events: none; text-shadow: 2px 2px 0 var(--paper); }
#floatScore.go { animation: floatScore .7s ease-out; }

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  padding: 10px;
  border: 3px solid var(--ink);
  border-radius: 18px 9px 20px 11px;
  background: #e9a64c;
  box-shadow: 6px 7px 0 var(--ink);
  touch-action: none;
  user-select: none;
  overflow: hidden;
}
.board::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .22;
  background:
    radial-gradient(circle at 20% 30%, var(--ink) 0 1px, transparent 1.4px),
    radial-gradient(circle at 77% 68%, var(--paper) 0 1px, transparent 1.6px);
  background-size: 19px 22px, 27px 25px;
}
.cells, .tiles { position: absolute; inset: 10px; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); gap: 8px; }
.cells i { background: rgba(255,250,242,.42); border: 2px solid rgba(17,16,15,.28); border-radius: 13px 7px 15px 9px; }

.tile {
  position: relative;
  z-index: 2;
  min-width: 0;
  border: 2px solid var(--ink);
  border-radius: 13px 7px 15px 9px;
  padding: 1px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--tile-bg);
  color: var(--tile-color, var(--ink));
  box-shadow: 3px 4px 0 var(--ink);
  overflow: hidden;
  cursor: default;
}
.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .12;
  background: repeating-linear-gradient(8deg, transparent 0 8px, currentColor 9px 10px);
}
.tile-art {
  position: relative;
  z-index: 1;
  display: block;
  width: 118%;
  height: 96%;
  object-fit: contain;
  object-position: center 46%;
  pointer-events: none;
  filter: drop-shadow(1px 2px 0 rgba(17,16,15,.08));
  transform: scale(1.24);
}
.tile .label {
  position: absolute;
  z-index: 2;
  left: 3px;
  right: 3px;
  bottom: 2px;
  padding: 1px 2px;
  border-radius: 5px;
  background: rgba(255,250,242,.84);
  font-size: clamp(.5rem, 2.05vw, .66rem);
  line-height: 1.15;
  text-align: center;
  white-space: nowrap;
  letter-spacing: 0;
}
.tile.new { animation: tileIn .25s cubic-bezier(.2,.8,.2,1.18); }
.tile.merge { animation: tileMerge .34s cubic-bezier(.2,.9,.3,1.35); z-index: 3; }
.board.paw-mode .tile { cursor: pointer; animation: pawReady .78s ease-in-out infinite alternate; }

.l1 { --tile-bg:#fffaf2; }
.l2 { --tile-bg:#fff1dd; }
.l3 { --tile-bg:#ffe5d5; }
.l4 { --tile-bg:#f8d46f; }
.l5 { --tile-bg:#d9eef0; }
.l6 { --tile-bg:#f7d7ca; }
.l7 { --tile-bg:#f7e8bc; }
.l8 { --tile-bg:#dce9c8; }
.l9 { --tile-bg:#d9eeea; }
.l10 { --tile-bg:#f7d1bd; }
.l11 { --tile-bg:#f5dda0; }
.l12 { --tile-bg:#fff3d6; box-shadow: 3px 4px 0 var(--ink), 0 0 0 4px rgba(243,189,67,.3); }
.l13 { --tile-bg:#f4dec9; }
.l14 { --tile-bg:#dceac4; }
.l15 { --tile-bg:#d7ecee; }
.l16 { --tile-bg:#e3edc9; }
.l17 { --tile-bg:#dcecf0; }
.l18 { --tile-bg:#f7dda0; }
.l19 { --tile-bg:#c9dce1; }
.l20 { --tile-bg:#fff0c7; box-shadow: 3px 4px 0 var(--ink), 0 0 0 5px rgba(243,189,67,.42); }

.controls { display: grid; grid-template-columns: .9fr 1.2fr .95fr; gap: 8px; }
.controls button {
  min-height: 46px;
  border: 2px solid var(--ink);
  border-radius: 14px 7px 15px 9px;
  background: var(--paper);
  font-weight: 800;
  font-size: .86rem;
  cursor: pointer;
  box-shadow: 3px 4px 0 var(--ink);
}
.controls button:active, .icon-button:active { transform: translate(2px, 2px); box-shadow: 1px 2px 0 var(--ink); }
.controls button:disabled { opacity: .42; cursor: default; }
.controls .paw-button { background: var(--yellow); }
.controls .paw-button span { display: inline-grid; place-items: center; width: 22px; height: 22px; margin-right: 2px; border-radius: 50%; background: var(--ink); color: var(--paper); font-size: .76rem; }
.controls .paw-button.active { background: var(--aqua); box-shadow: 3px 4px 0 var(--ink), 0 0 0 4px rgba(120,199,207,.28); }
.hint { margin: -1px 0 0; text-align: center; color: #5d574e; font-size: .76rem; letter-spacing: .035em; }

.modal { position: fixed; z-index: 30; inset: 0; padding: 20px; display: grid; place-items: center; background: rgba(17,16,15,.38); backdrop-filter: blur(3px); }
.modal[hidden] { display: none; }
.dialog { width: min(100%, 340px); padding: 25px 22px 21px; border: 3px solid var(--ink); border-radius: 18px 9px 20px 11px; text-align: center; background: var(--paper); box-shadow: 7px 8px 0 var(--ink); }
.dialog-mark { display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; background: var(--yellow); border: 2px solid var(--ink); color: var(--ink); font-size: 1.5rem; }
.dialog h2 { margin: 9px 0 8px; font-size: 1.35rem; }
.dialog p { margin: 0 0 18px; color: #5d574e; line-height: 1.6; font-size: .94rem; }
.dialog-actions { display: grid; gap: 9px; }
.dialog-actions button { min-height: 46px; border-radius: 13px 7px 14px 8px; border: 2px solid var(--ink); background: var(--paper); font-weight: 800; cursor: pointer; box-shadow: 3px 3px 0 var(--ink); }
.dialog-actions button.primary { background: var(--orange); }

#toast { position: fixed; z-index: 40; left: 50%; bottom: max(25px, env(safe-area-inset-bottom)); transform: translate(-50%, 18px); padding: 10px 16px; border: 2px solid var(--ink); border-radius: 14px 7px 15px 9px; background: var(--ink); color: var(--paper); font-size: .86rem; opacity: 0; pointer-events: none; transition: .25s ease; white-space: nowrap; box-shadow: 3px 4px 0 var(--orange); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes tileIn { from { opacity:0; transform:scale(.4) rotate(-5deg); } }
@keyframes tileMerge { 50% { transform:scale(1.16) rotate(1deg); } }
@keyframes pawReady { to { transform: translateY(-2px) rotate(.5deg); box-shadow: 4px 6px 0 var(--ink); } }
@keyframes catNod { 40% { transform:translateY(8px) rotate(4deg) scale(1.04); } }
@keyframes catPounce { 40% { transform:translateY(2px) scale(1.12) rotate(-4deg); } }
@keyframes floatScore { 0% { opacity:0; transform:translate(-50%,8px) scale(.8); } 25% { opacity:1; } 100% { opacity:0; transform:translate(-50%,-25px) scale(1.08); } }

@media (max-height: 710px) {
  .app { gap: 8px; padding-top: max(7px, env(safe-area-inset-top)); }
  .topbar { min-height: 76px; padding-top: 4px; padding-bottom: 4px; }
  .mascot-wrap { width: 74px; height: 68px; }
  .mascot-wrap img { width: 84px; height: 84px; transform: translate(-2px, 2px); }
  .score-card, .paw-card { min-height: 49px; padding-top: 5px; padding-bottom: 5px; }
  .meter { margin-top: 6px; }
  .controls button { min-height: 41px; }
  .hint { font-size: .69rem; }
}

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

.rooms{display:flex;gap:10px;font-size:14px}.rooms a{padding:7px 13px;border:1px solid #355c7540;border-radius:20px;color:#355c75;text-decoration:none}.rooms a[aria-current]{background:#355c75;color:white}

.rooms{flex-wrap:wrap}
