@font-face {
  font-family: "Noto Sans Thai";
  src: url("assets/fonts/NotoSansThai-variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #FFF5E8;
  --surface: #FFFCF6;
  --ink: #34283F;
  --muted: #706678;
  --primary: #6540A8;
  --pressed: #4F3187;
  --selected: #E9DEFA;
  --mint: #60CDB4;
  --coral: #F48378;
  --sunny: #F6BF58;
  --outline: #D9CCE6;
  --scrim: #34283fa6;
  --cell: 36px;
  --tap: 90ms;
  --snap: 180ms cubic-bezier(.2,.9,.25,1.2);
  --bounce: 320ms cubic-bezier(.3,1.45,.55,1);
  --sheet: 280ms;
  --shadow: 0 3px 10px #34283f1a, 0 1px 2px #34283f12;
  --shadow-high: 0 16px 40px #34283f38;
  font-family: "Noto Sans Thai", "Leelawadee UI", Thonburi, Tahoma, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body, .game { width: 100%; height: 100%; height: 100dvh; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  min-width: 320px;
  background: linear-gradient(180deg, #fff5e838, #fff5e88f), url("assets/generated/bg-club-calm-portrait-v2.png") center / cover no-repeat, var(--bg);
  user-select: none;
  -webkit-user-select: none;
}
button { min-width: 48px; min-height: 48px; padding: 0; border: 0; color: inherit; font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, [role="button"]:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
button:disabled { cursor: default; opacity: .46; }
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { display: block; width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; pointer-events: none; }

.game { display: grid; grid-template-rows: calc(62px + env(safe-area-inset-top)) minmax(0, 1fr); }
.hud {
  position: relative;
  z-index: 80;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 48px;
  align-items: center;
  gap: 10px;
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 4px max(12px, env(safe-area-inset-left));
}
.level-chip {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 5px;
  min-width: 78px;
  height: 48px;
  padding: 9px 11px;
  border: 1px solid var(--outline);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.level-chip span { color: var(--muted); font-size: 13px; font-weight: 650; }
.level-chip strong { font-size: 17px; line-height: 1.5; }
.progress-cluster { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 0; }
.progress-cluster strong { font-size: 14px; line-height: 1.4; font-weight: 800; white-space: nowrap; }
.paw-progress { display: flex; justify-content: center; gap: clamp(3px, 1.4vw, 7px); width: 100%; }
.paw-progress span { width: clamp(10px, 3.5vw, 15px); height: 5px; border-radius: 99px; background: var(--outline); transition: background var(--snap), transform var(--snap); }
.paw-progress span.filled { background: var(--primary); transform: translateY(-1px); }
.icon-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--outline);
  border-radius: 16px;
  color: var(--primary);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.icon-button:active { background: var(--selected); transform: translateY(1px); }

.gameplay {
  position: relative;
  min-height: 0;
  isolation: isolate;
  overflow: hidden;
  touch-action: none;
  --rack-height: clamp(134px, 21dvh, 160px);
  --rack-bottom: max(68px, calc(env(safe-area-inset-bottom) + 68px));
}
.play-stage {
  position: absolute;
  z-index: 3;
  top: 3px;
  bottom: calc(var(--rack-height) + var(--rack-bottom) + 66px);
  left: 50%;
  width: min(calc(100vw - 8px), 680px);
  transform: translateX(-50%);
}
.cushion-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: .07; filter: blur(12px); pointer-events: none; }
.board-layer { position: absolute; z-index: 4; transform: translate(-50%, -50%); touch-action: none; }
.board-silhouette, .board-cell, .ghost-cell, .piece-visual, .piece-cell, .cat-art-frame { position: absolute; }
.board-silhouette { inset: 0; z-index: 0; overflow: visible; pointer-events: none; }
.board-cell {
  z-index: 2;
  width: var(--cell);
  height: var(--cell);
  border: 1px dashed #6540a86b;
  border-radius: 22%;
  background: #fffcf626;
  opacity: .48;
  transition: opacity var(--tap), border-color var(--tap);
}
.gameplay.is-dragging .board-cell { border-color: #6540a8a0; opacity: .68; }
.board-cell.occupied { border-color: transparent; opacity: .03; }
.ghost-cell {
  z-index: 30;
  width: var(--cell);
  height: var(--cell);
  border: 3px solid #2d9b80;
  border-radius: 20%;
  background: #60cdb466;
  box-shadow: 0 0 0 3px #fffcf677;
  pointer-events: none;
}
.ghost-cell.invalid { border-style: dashed; border-color: var(--coral); background: #f4837840; box-shadow: none; }
.hint-cell {
  position: absolute;
  z-index: 24;
  width: var(--cell);
  height: var(--cell);
  border: 2px dashed #237d67;
  border-radius: 20%;
  background: #60cdb455;
  pointer-events: none;
}
.piece-visual { z-index: 10; cursor: grab; touch-action: none; transform-origin: center; transition: filter var(--tap), opacity var(--tap), transform var(--snap); }
.piece-visual:active { cursor: grabbing; }
.piece-visual.selected { filter: drop-shadow(0 0 5px #fffcf6) drop-shadow(0 7px 7px #34283f38); }
.board-layer .piece-visual.reaction { animation: catSettle 420ms cubic-bezier(.2,1.2,.3,1); }
@keyframes catSettle { 0% { transform: scale(.88) rotate(-3deg); } 65% { transform: scale(1.06) rotate(2deg); } 100% { transform: scale(1) rotate(0); } }
.piece-cell {
  z-index: 0;
  width: var(--piece-cell);
  height: var(--piece-cell);
  border: 1px solid color-mix(in srgb, var(--piece-color) 58%, var(--primary));
  border-radius: calc(var(--piece-cell) * .2);
  background: color-mix(in srgb, var(--piece-color) 46%, var(--surface));
  box-shadow: inset 0 3px 7px #6540a81f, 0 3px 5px #34283f20;
  opacity: .62;
  pointer-events: none;
}
.cat-art-frame { z-index: 2; left: 50%; top: 50%; pointer-events: none; }
.piece-art, .cat-face-layer { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.cat-face-layer {
  z-index: 1;
  -webkit-mask-image: radial-gradient(ellipse var(--face-rx) var(--face-ry) at var(--face-x) var(--face-y), #000 34%, transparent 100%);
  mask-image: radial-gradient(ellipse var(--face-rx) var(--face-ry) at var(--face-x) var(--face-y), #000 34%, transparent 100%);
  transform-origin: var(--face-x) var(--face-y);
}
.cat-art-frame[data-mood="blink"] .cat-face-layer { animation: faceBlink 420ms ease-in-out both; }
.cat-art-frame[data-mood="look"] .cat-face-layer { animation: faceLook 550ms ease-in-out both; }
.cat-art-frame[data-mood="happy"] .cat-face-layer { animation: faceHappy 450ms ease-out both; }
.cat-art-frame[data-mood="grumpy"] .cat-face-layer { animation: faceGrumpy 600ms ease-in-out both; }
.cat-art-frame[data-mood="look"] .piece-art { animation: catIdleSway 550ms ease-in-out both; }
.cat-art-frame[data-mood="happy"] .piece-art { animation: catHappyHop 450ms ease-out both; }
.cat-art-frame[data-mood="grumpy"] .piece-art { animation: catGrumpyShake 600ms ease-in-out both; }
@keyframes catIdleSway { 0%,100% { transform: none; } 50% { transform: translateY(-2px) rotate(.8deg); } }
@keyframes catHappyHop { 0%,100% { transform: none; } 50% { transform: translateY(-3px) scale(1.025); } }
@keyframes catGrumpyShake { 0%,100% { transform: none; } 30% { transform: translateX(-2px); } 65% { transform: translateX(2px); } }
@keyframes faceBlink { 0%,100% { transform: scaleY(1); } 43%,55% { transform: scaleY(.91) translateY(1%); } }
@keyframes faceLook { 0%,100% { transform: translate(0,0) rotate(0); } 50% { transform: translate(2px, -3px) rotate(2deg); } }
@keyframes faceHappy { 0% { transform: translateY(2%) scale(.98); } 55% { transform: translateY(-3%) scale(1.045); } 100% { transform: none; } }
@keyframes faceGrumpy { 0%,100% { transform: translateX(0) rotate(0); } 25% { transform: translateX(-2.5%) rotate(-2deg); } 65% { transform: translateX(2%) rotate(1.5deg); } }
.cat-mood-mark {
  position: absolute;
  z-index: 3;
  left: var(--face-x);
  top: var(--face-y);
  display: grid;
  place-items: center;
  width: clamp(13px, calc(var(--piece-cell) * .48), 23px);
  height: clamp(13px, calc(var(--piece-cell) * .48), 23px);
  border: 1px solid #fff;
  border-radius: 50%;
  color: #9b4476;
  background: #fff8e9;
  box-shadow: 0 2px 4px #34283f38;
  font: 900 clamp(10px, calc(var(--piece-cell) * .32), 17px)/1 Arial, sans-serif;
  opacity: 0;
  transform: translate(-50%, -145%) scale(.4);
  pointer-events: none;
}
.cat-art-frame[data-mood="happy"] .cat-mood-mark::before { content: "♥"; }
.cat-art-frame[data-mood="grumpy"] .cat-mood-mark::before { content: "!"; }
.cat-art-frame[data-mood="happy"] .cat-mood-mark,
.cat-art-frame[data-mood="grumpy"] .cat-mood-mark { animation: catMoodPop 560ms ease-out both; }
.cat-art-frame[data-mood="grumpy"] .cat-mood-mark { color: #aa4450; }
@keyframes catMoodPop { 0% { opacity: 0; transform: translate(-50%, -130%) scale(.4); } 22%,70% { opacity: 1; transform: translate(-50%, -155%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -175%) scale(.8); } }
.no-idle .piece-art, .no-idle .cat-face-layer, .no-idle .cat-mood-mark,
.gameplay.is-dragging .board-layer .piece-art, .gameplay.is-dragging .board-layer .cat-face-layer { animation: none !important; }
.piece-tag { display: none; }

.coach-card {
  position: absolute;
  z-index: 22;
  left: 50%;
  bottom: calc(var(--rack-height) + var(--rack-bottom) + 6px);
  width: min(calc(100vw - 30px), 430px);
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px;
  transform: translateX(-50%);
  border: 1px solid var(--outline);
  border-radius: 15px;
  color: var(--ink);
  background: #fffcf6ed;
  box-shadow: var(--shadow);
  pointer-events: none;
}
.coach-portrait {
  width: 43px;
  height: 43px;
  flex: none;
  border: 2px solid #fff;
  border-radius: 12px;
  background: var(--selected);
  box-shadow: 0 0 0 1px var(--outline);
  object-fit: cover;
}
.coach-portrait[data-mood="happy"] { box-shadow: 0 0 0 2px #efb5d6, 0 2px 8px #9b44764d; }
.coach-portrait[data-mood="grumpy"] { box-shadow: 0 0 0 2px #ed9b9c, 0 2px 8px #aa44504d; }
.coach-copy { min-width: 0; display: flex; flex-direction: column; gap: 1px; line-height: 1.25; }
.coach-copy strong { font-size: 13px; font-weight: 850; }
.coach-copy span { color: var(--muted); font-size: 12px; font-weight: 700; }
.coach-card.feedback-success { border-color: #67bda1; background: #effbf3; }
.coach-card.feedback-success .coach-copy span { color: #176d56; }
.coach-card.feedback-error { border-color: #e08a91; background: #fff2f1; }
.coach-card.feedback-error .coach-copy span { color: #a63748; }
.face-I { object-position: 100% 50%; }
.face-O { object-position: 35% 35%; }
.face-T { object-position: 50% 20%; }
.face-S { object-position: 75% 15%; }
.face-Z { object-position: 20% 15%; }
.face-J { object-position: 20% 0%; }
.face-L { object-position: 75% 0%; }
.active-cat-zone {
  position: absolute;
  z-index: 18;
  left: 50%;
  bottom: var(--rack-bottom);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 3px;
  width: min(calc(100vw - 16px), 530px);
  height: var(--rack-height);
  padding: 7px;
  transform: translateX(-50%);
  border: 1px solid var(--outline);
  border-radius: 22px;
  background: #fffcf6e8;
  box-shadow: 0 7px 22px #34283f25;
}
.active-cat-zone.empty::after { content: "แมวครบแล้ว!"; align-self: center; justify-self: center; grid-column: 1 / -1; color: var(--muted); font-size: 14px; }
.active-piece {
  position: relative;
  min-width: 48px;
  min-height: 48px;
  border: 1.5px solid var(--outline);
  border-radius: 14px;
  background: #fff7edb8;
  touch-action: none;
}
.active-piece.is-selected { border: 2px solid var(--primary); background: var(--selected); box-shadow: inset 0 0 0 2px #fffcf6, 0 2px 5px #6540a82b; }
.active-piece .piece-visual { left: 50%; top: 50%; transform: translate(-50%, -50%); }
.active-piece.reaction { animation: activeBounce 480ms cubic-bezier(.3,1.45,.55,1); }
@keyframes activeBounce { 0%,100% { transform: translateX(0) rotate(0); } 24% { transform: translateX(-9px) rotate(-3deg); } 52% { transform: translateX(8px) rotate(3deg); } 76% { transform: translateX(-4px) rotate(-1deg); } }
.drag-layer { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
.drag-proxy { position: fixed; z-index: 101; filter: drop-shadow(0 18px 14px #34283f45) drop-shadow(0 0 6px #fffcf6); transition: none; }
.drag-source { opacity: .14; }

.action-bar {
  position: absolute;
  z-index: 45;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  height: 52px;
  max-width: 522px;
  margin: 0 auto;
}
.action-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  height: 52px;
  padding: 0 6px;
  border: 1px solid var(--outline);
  border-radius: 15px;
  color: var(--primary);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}
.action-button .icon { width: 19px; height: 19px; }
.action-button:active:not(:disabled) { transform: translateY(1px); background: var(--selected); }
.action-hint { color: var(--ink); background: #fff2d2; border-color: #edcf85; }
.action-hint:active:not(:disabled) { background: #f9e2aa; }

.sheet-layer, .complete-modal { position: fixed; inset: 0; z-index: 150; }
.sheet-layer[hidden] { display: none; }
.sheet-scrim { position: absolute; inset: 0; width: 100%; height: 100%; background: var(--scrim); }
.bottom-sheet {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  max-height: calc(100dvh - 20px);
  overflow-y: auto;
  padding: 11px 18px max(22px, calc(env(safe-area-inset-bottom) + 16px));
  border: 1px solid #fffcf6;
  border-radius: 28px 28px 0 0;
  background: var(--surface);
  box-shadow: var(--shadow-high);
  animation: sheetIn var(--sheet) cubic-bezier(.2,.8,.2,1);
}
@keyframes sheetIn { from { transform: translateY(100%); } }
.sheet-handle { width: 42px; height: 5px; margin: 0 auto 14px; border-radius: 99px; background: var(--outline); }
.sheet-eyebrow, .complete-eyebrow { margin: 0; color: var(--primary); font-size: 12px; font-weight: 850; letter-spacing: .06em; text-align: center; }
.bottom-sheet h2 { margin: 1px 0 2px; font-size: 26px; font-weight: 850; line-height: 1.35; text-align: center; }
.sheet-description { margin: 0 0 17px; color: var(--muted); font-size: 13px; text-align: center; }
.primary-button { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 54px; border-radius: 15px; color: #fff; background: var(--primary); box-shadow: 0 4px 0 var(--pressed), var(--shadow); font-size: 17px; font-weight: 850; }
.primary-button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--pressed); background: var(--pressed); }
.sheet-primary { width: min(100%, 520px); margin: 0 auto 14px; }
.sheet-actions, .setting-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; max-width: 520px; margin: 0 auto; }
.sheet-actions button, .setting-row button {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  min-height: 54px;
  padding: 7px 10px;
  border: 1px solid var(--outline);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 750;
  text-align: left;
}
.sheet-actions button .icon, .setting-row button .icon { width: 20px; height: 20px; color: var(--primary); }
.sheet-actions button.armed { border-color: var(--coral); color: #a4444d; background: #fff0ec; }
.hint-action { display: flex; align-items: center; justify-content: center; gap: 8px; width: min(100%, 520px); min-height: 50px; margin: 10px auto 0; border: 1px solid var(--outline); border-radius: 14px; color: var(--primary); background: var(--selected); font-size: 14px; font-weight: 800; }
.hint-action .icon { width: 20px; height: 20px; }
.setting-row { margin-top: 10px; }
.setting-row button { background: #f9f5fd; }
.setting-row strong { margin-left: auto; color: var(--primary); font-size: 13px; }

.complete-modal {
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--scrim);
  opacity: 0;
  pointer-events: none;
  backdrop-filter: blur(6px);
  transition: opacity 240ms ease;
}
.complete-modal.show { opacity: 1; pointer-events: auto; }
.complete-card {
  width: min(354px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 18px 20px 20px;
  border: 1px solid #fff;
  border-radius: 26px;
  background: var(--surface);
  box-shadow: var(--shadow-high);
  text-align: center;
  transform: translateY(18px) scale(.94);
  transition: transform 650ms cubic-bezier(.2,.9,.25,1.2);
}
.complete-modal.show .complete-card { transform: none; }
.victory-group-art { display: block; width: 100%; aspect-ratio: 3 / 2; max-height: min(31dvh, 210px); margin: 4px auto 12px; border: 2px solid #fff; border-radius: 18px; background: #f4e8fb; box-shadow: 0 5px 14px #34283f25; object-fit: cover; }
.complete-card h2 { margin: 3px 0 3px; font-size: 27px; font-weight: 850; line-height: 1.3; }
.complete-card p#completeCopy { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.complete-next { width: 100%; }
.complete-next .icon { width: 20px; height: 20px; }
.replay-button { display: flex; align-items: center; justify-content: center; gap: 7px; width: 100%; min-height: 48px; margin: 11px auto 0; border-radius: 13px; color: var(--primary); background: transparent; font-size: 14px; font-weight: 750; }
.replay-button .icon { width: 19px; height: 19px; }
.replay-button:active { background: var(--selected); }

.debug-card { position: absolute; z-index: 200; left: 8px; bottom: 70px; display: none; width: min(340px, calc(100vw - 16px)); padding: 12px; border-radius: 16px; color: #fff; background: #34283fed; box-shadow: var(--shadow-high); font: 12px/1.45 monospace; }
.debug-card div { display: flex; justify-content: space-between; gap: 12px; }
.debug-card button { width: 100%; margin-top: 8px; border-radius: 12px; background: #fff; }
.debug-mode .debug-card { display: block; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
@media (max-height: 600px) {
  .game { grid-template-rows: calc(56px + env(safe-area-inset-top)) minmax(0, 1fr); }
  .gameplay { --rack-height: 134px; }
  .coach-card { min-height: 52px; }
}
@media (min-width: 760px) { .gameplay { --rack-height: 170px; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
