:root {
  --paper: #f7edda;
  --paper-bright: #fff8ea;
  --paper-deep: #ead7b8;
  --ink: #30281f;
  --ink-soft: #756756;
  --line: #4b3928;
  --gold: #f2bd32;
  --orange: #e88724;
  --coral: #e99579;
  --moss: #78805a;
  --cardboard: #c99a5e;
  --shadow: rgba(83, 55, 27, 0.15);
  --display: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", sans-serif;
  --body: "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: #ede0ca; }
body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 5%, rgba(255,255,255,.7), transparent 25rem),
    radial-gradient(circle at 91% 88%, rgba(196,147,83,.18), transparent 28rem),
    var(--paper);
  font-family: var(--body);
}
button { color: inherit; font: inherit; }
button, .cat-card, .board { -webkit-tap-highlight-color: transparent; }

.paper-grain {
  position: fixed; inset: 0; z-index: 100; pointer-events: none; opacity: .2;
  background-image:
    repeating-radial-gradient(circle at 20% 30%, rgba(80,49,22,.18) 0 .55px, transparent .7px 4px),
    repeating-linear-gradient(102deg, transparent 0 8px, rgba(90,61,30,.035) 9px 10px);
  mix-blend-mode: multiply;
}

.app-shell { width: min(1440px, calc(100% - 40px)); margin: 0 auto; padding: 18px 0 16px; }
.topbar {
  min-height: 68px; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center;
  gap: 16px; border-bottom: 2px solid var(--ink);
}
.brand { width: max-content; position: relative; color: var(--ink); text-decoration: none; white-space: nowrap; font: 800 31px/1 var(--display); letter-spacing: .04em; }
.brand i { position: absolute; right: -9px; top: -7px; width: 7px; height: 7px; border-radius: 50%; background: var(--ink); box-shadow: -6px -4px 0 -1px var(--ink), 0 -7px 0 -1px var(--ink), 6px -4px 0 -1px var(--ink); transform: rotate(10deg); }
.title-lockup { display: grid; gap: 1px; text-align: center; }
.title-lockup small { color: var(--ink-soft); font: 700 9px/1 var(--display); letter-spacing: .22em; }
.title-lockup strong { white-space: nowrap; font: 800 20px/1.2 var(--display); letter-spacing: .08em; }
.topbar-actions { justify-self: end; display: flex; align-items: center; gap: 8px; }
.mini-button { min-height: 38px; padding: 0 14px; border: 2px solid var(--ink); border-radius: 999px; background: rgba(255,248,234,.76); white-space: nowrap; font: 700 12px/1 var(--display); box-shadow: 2px 3px 0 var(--shadow); cursor: pointer; }
.sound-button[aria-pressed="true"] { color: var(--ink-soft); background: rgba(234,215,184,.72); box-shadow: none; }

.game-shell { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 18px; padding-top: 16px; }
.game-panel { min-width: 0; overflow: hidden; border: 2px solid var(--ink); border-radius: 26px; background: rgba(255,248,234,.58); box-shadow: 6px 8px 0 rgba(75,57,40,.09); }
.game-heading { min-height: 90px; padding: 15px 21px 13px; display: flex; align-items: end; justify-content: space-between; gap: 24px; border-bottom: 2px dashed rgba(75,57,40,.36); }
.game-heading > div { min-width: 0; }
.eyebrow { margin: 0 0 4px; color: var(--orange); white-space: nowrap; font: 800 10px/1 var(--display); letter-spacing: .16em; }
h1 { margin: 0; display: flex; flex-wrap: wrap; gap: 0 .35em; font: 800 clamp(23px, 2.3vw, 36px)/1.2 var(--display); letter-spacing: .02em; }
h1 span, h1 em { white-space: nowrap; }
h1 em { color: var(--orange); font-style: normal; }
.stage-copy { max-width: 15rem; margin: 0; color: var(--ink-soft); text-align: right; font-size: 13px; line-height: 1.6; }

.play-area { min-width: 0; min-height: 610px; padding: 18px; display: grid; grid-template-columns: minmax(390px, 1fr) minmax(240px, 310px); align-items: stretch; gap: 18px; }
.board-wrap { min-width: 0; position: relative; display: grid; align-content: center; justify-items: center; padding: 54px 28px 28px; border: 2px solid var(--line); border-radius: 19px; background: #d1a56c; box-shadow: inset 0 0 0 7px rgba(109,69,31,.09), 4px 5px 0 var(--shadow); }
.board-wrap::before, .board-wrap::after { content: ""; position: absolute; top: 0; bottom: 0; width: 19px; opacity: .18; background: repeating-linear-gradient(90deg, transparent 0 4px, var(--line) 5px 6px); }
.board-wrap::before { left: 9px; }.board-wrap::after { right: 9px; }
.box-label { position: absolute; top: 15px; left: 28px; right: 28px; display: flex; justify-content: space-between; color: rgba(68,43,23,.68); font: 800 9px/1 var(--display); letter-spacing: .14em; }
.board {
  --cols: 4; --rows: 3;
  position: relative; width: min(100%, 570px); aspect-ratio: var(--cols) / var(--rows);
  border: 3px solid var(--ink); border-radius: 14px; background: #f5e7cf;
  box-shadow: inset 0 0 0 5px rgba(75,57,40,.08), 3px 4px 0 rgba(83,55,27,.2);
  overflow: hidden; touch-action: none;
}
.target-grid, .placed-layer, .placement-preview { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--cols), 1fr); grid-template-rows: repeat(var(--rows), 1fr); }
.target-cell { position: relative; border: 1px dashed rgba(75,57,40,.22); background: rgba(255,248,234,.48); }
.target-cell.is-void { background: repeating-linear-gradient(135deg, rgba(86,55,28,.08) 0 4px, rgba(86,55,28,.02) 4px 9px); border: 0; }
.target-cell:not(.is-void)::after { content: ""; position: absolute; inset: 13%; border: 1px dotted rgba(75,57,40,.19); border-radius: 10px; }
.target-cell.is-filled { border-color: transparent; background: rgba(255,248,234,.2); }
.target-cell.is-filled::after { display: none; }
.placed-layer { pointer-events: none; }
.placed-piece { position: absolute; z-index: 4; padding: 0; border: 0; background: transparent; cursor: pointer; pointer-events: auto; overflow: visible; }
.jelly-cat { display: block; width: 100%; height: 100%; object-fit: contain; user-select: none; pointer-events: none; filter: saturate(1.04) drop-shadow(2px 5px 2px rgba(65,42,20,.16)); transform-origin: 50% 76%; }
.placed-piece.is-squishing .jelly-cat { animation: cat-squish .62s cubic-bezier(.18,.86,.23,1.32); }
@keyframes cat-squish { 0% { transform: scale(.68,1.25); opacity: .42; filter: saturate(1.25) blur(2px) drop-shadow(1px 2px 1px rgba(65,42,20,.12)); } 42% { transform: scale(1.12,.88); } 68% { transform: scale(.96,1.06); } 100% { transform: scale(1); opacity: 1; } }
.placement-preview { display: block; z-index: 3; pointer-events: none; }
.preview-cell { position: absolute; border: 3px solid var(--moss); border-radius: 8px; background: rgba(120,128,90,.2); }
.placement-preview.is-invalid .preview-cell { border-color: var(--coral); background: rgba(233,149,121,.23); }
.board-note { margin: 13px 0 0; color: rgba(63,43,25,.72); font: 700 12px/1.4 var(--display); }

.tray-panel { min-width: 0; display: grid; grid-template-rows: auto 1fr auto; overflow: hidden; border: 2px solid var(--ink); border-radius: 19px; background: rgba(255,248,234,.78); }
.tray-heading { padding: 15px 16px 12px; display: flex; align-items: end; justify-content: space-between; border-bottom: 2px dashed rgba(75,57,40,.3); }
.tray-heading small { display: block; color: var(--orange); font: 800 9px/1 var(--display); letter-spacing: .14em; }
.tray-heading h2 { margin: 4px 0 0; font: 800 18px/1.2 var(--display); }
.tray-heading > span { padding: 5px 9px; border: 1.5px solid var(--ink); border-radius: 999px; background: var(--gold); font: 800 11px/1 var(--display); }
.cat-tray { padding: 12px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start; gap: 10px; overflow: auto; }
.cat-card { min-height: 124px; position: relative; display: grid; place-items: center; padding: 22px 5px 7px; border: 1.5px solid rgba(75,57,40,.5); border-radius: 15px; background: rgba(247,237,218,.78); cursor: grab; box-shadow: 2px 3px 0 rgba(83,55,27,.08); transition: transform .12s ease, background-color .12s ease; touch-action: none; }
.cat-card:hover { transform: translateY(-2px); background: var(--paper-bright); }
.cat-card.is-selected { outline: 3px solid var(--gold); outline-offset: 2px; background: #fff4cf; }
.cat-card.is-placed { display: none; }
.cat-card-name { position: absolute; top: 8px; left: 9px; color: var(--ink-soft); white-space: nowrap; font: 700 10px/1 var(--display); }
.piece-visual { --tile: 42px; position: relative; flex: none; overflow: visible; }
.piece-visual[data-span="3"] { --tile: 34px; }
.piece-visual[data-span="4"] { --tile: 27px; }
.drag-ghost .piece-visual { --tile: 38px; }
.cat-card.is-selected .jelly-cat { animation: jelly-ready 1.55s ease-in-out infinite; }
@keyframes jelly-ready { 0%,100% { transform: scale(1) rotate(0deg); } 35% { transform: scale(1.045,.965) rotate(-1.2deg); } 68% { transform: scale(.975,1.035) rotate(.8deg); } }
.selected-tools { padding: 11px 12px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; border-top: 2px dashed rgba(75,57,40,.3); background: rgba(239,224,196,.52); }
.selected-tools p { min-width: 0; margin: 0; display: grid; }
.selected-tools p span { overflow: hidden; font: 800 12px/1.2 var(--display); text-overflow: ellipsis; white-space: nowrap; }
.selected-tools p small { color: var(--ink-soft); font-size: 10px; }
.selected-tools button { min-height: 39px; padding: 0 12px; border: 2px solid var(--ink); border-radius: 12px; background: var(--gold); font: 800 12px/1 var(--display); cursor: pointer; box-shadow: 2px 2px 0 rgba(48,40,31,.18); }
.selected-tools button:disabled { cursor: default; opacity: .4; filter: grayscale(1); }
.tray-heading h2, .tray-heading > span, .board-note, .stage-number,
.fill-status > div:first-child, .action-card button, .selected-tools button,
.primary-button, .share-button, .text-button { white-space: nowrap; }

.info-column { display: grid; align-content: start; gap: 13px; }
.stage-card, .action-card, .memo-card { border: 2px solid var(--ink); border-radius: 18px; background: rgba(255,248,234,.78); box-shadow: 3px 4px 0 var(--shadow); }
.stage-card { overflow: hidden; }
.stage-number { min-height: 92px; padding: 13px 15px; display: flex; align-items: baseline; justify-content: center; border-bottom: 2px dashed rgba(75,57,40,.3); }
.stage-number small { align-self: flex-start; margin-top: 7px; font: 800 9px/1 var(--display); letter-spacing: .16em; }
.stage-number strong { margin-left: auto; font: 800 48px/.9 var(--display); }
.stage-number span { margin-left: 4px; color: var(--ink-soft); font: 700 13px/1 var(--display); }
.fill-status { padding: 14px; }
.fill-status > div:first-child { display: flex; align-items: baseline; justify-content: space-between; font-size: 12px; }
.fill-status strong { font: 800 16px/1 var(--display); }
.fill-track { height: 12px; margin-top: 8px; overflow: hidden; border: 1.5px solid var(--ink); border-radius: 999px; background: var(--paper-deep); }
.fill-track i { display: block; width: 0%; height: 100%; border-radius: inherit; background: repeating-linear-gradient(110deg, var(--gold) 0 9px, #f7cb55 9px 13px); transition: width .25s ease; }
.action-card { padding: 11px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.action-card button { min-height: 43px; border: 2px solid var(--ink); border-radius: 12px; font: 800 12px/1 var(--display); cursor: pointer; }
.hint-button { background: var(--moss); color: #fffbea; }.reset-button { background: var(--paper-bright); }
.memo-card { position: relative; margin-top: 8px; padding: 28px 18px 18px; transform: rotate(1deg); background: #fff0bc; }
.memo-card .tape { position: absolute; width: 74px; height: 19px; top: -9px; left: calc(50% - 37px); background: rgba(232,135,36,.58); transform: rotate(-3deg); }
.memo-card p { margin: 0 0 9px; color: var(--orange); font: 800 10px/1 var(--display); letter-spacing: .13em; }
.memo-card strong { display: block; font: 800 18px/1.55 var(--display); }
.memo-card small { display: block; margin-top: 13px; color: var(--ink-soft); font-size: 11px; line-height: 1.6; }

.footer-note { min-height: 48px; display: flex; align-items: center; justify-content: space-between; color: var(--ink-soft); font-size: 11px; }
.footer-note span { font: 800 10px/1 var(--display); letter-spacing: .2em; }
.footer-note p { margin: 0; }

.game-dialog { width: min(470px, calc(100% - 32px)); padding: 29px; border: 2px solid var(--ink); border-radius: 23px; color: var(--ink); background: var(--paper-bright); box-shadow: 8px 10px 0 rgba(48,40,31,.2); }
.game-dialog::backdrop { background: rgba(48,40,31,.47); backdrop-filter: blur(3px); }
.game-dialog h2 { margin: 4px 0 20px; font: 800 25px/1.35 var(--display); }
.dialog-close { position: absolute; top: 13px; right: 13px; width: 36px; height: 36px; border: 0; background: transparent; font: 500 27px/1 var(--display); cursor: pointer; }
.game-dialog ol { margin: 0 0 22px; padding: 0; display: grid; gap: 10px; list-style: none; }
.game-dialog li { display: grid; grid-template-columns: 40px 1fr; align-items: center; gap: 11px; }
.game-dialog li > span { display: grid; place-items: center; width: 38px; height: 38px; border: 2px solid var(--ink); border-radius: 50%; background: var(--gold); font: 800 14px/1 var(--display); }
.game-dialog li p { margin: 0; display: grid; }.game-dialog li strong { font: 800 14px/1.4 var(--display); }.game-dialog li small { color: var(--ink-soft); font-size: 12px; }
.primary-button { width: 100%; min-height: 48px; border: 2px solid var(--ink); border-radius: 14px; background: var(--orange); color: #fff9ec; font: 800 14px/1 var(--display); box-shadow: 3px 4px 0 rgba(48,40,31,.18); cursor: pointer; }
.clear-dialog { text-align: center; overflow: hidden; }.clear-dialog .eyebrow { margin: 14px 0 4px; }.clear-dialog h2 { margin-bottom: 8px; }.clear-dialog > p:not(.eyebrow):not(.clear-stage) { margin: 0 0 21px; color: var(--ink-soft); font-size: 13px; }
.clear-illustration { display: block; width: calc(100% + 58px); max-width: none; height: auto; margin: -29px -29px 0; border-bottom: 2px solid var(--ink); }
.clear-stage { margin: 0 0 3px; color: var(--orange); font: 800 16px/1.2 var(--display); letter-spacing: .08em; }
.share-button { display: grid; place-items: center; width: 100%; min-height: 46px; margin-top: 10px; border: 2px solid var(--ink); border-radius: 14px; background: var(--ink); color: #fff9ec; font: 800 14px/1 var(--display); text-decoration: none; box-shadow: 3px 4px 0 rgba(48,40,31,.18); }
.text-button { margin-top: 11px; border: 0; background: transparent; color: var(--ink-soft); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.toast { position: fixed; z-index: 200; left: 50%; bottom: 25px; transform: translate(-50%, 18px); padding: 10px 15px; border: 2px solid var(--ink); border-radius: 999px; background: var(--paper-bright); font: 700 12px/1.3 var(--display); box-shadow: 3px 4px 0 var(--shadow); opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.drag-ghost { position: fixed; z-index: 300; pointer-events: none; opacity: .84; transform: translate(-50%, -50%) rotate(-2deg); filter: drop-shadow(5px 7px 3px rgba(48,40,31,.2)); }
.hint-flash { animation: hint-flash .9s ease 2; }
@keyframes hint-flash { 50% { filter: brightness(1.15); box-shadow: inset 0 0 0 6px rgba(242,189,50,.58), 0 0 0 5px rgba(242,189,50,.28); } }

button:focus-visible, .share-button:focus-visible, .cat-card:focus-visible, .board:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; transition-duration: .001ms !important; } }

@media (max-width: 1050px) {
  .game-shell { grid-template-columns: 1fr; }
  .info-column { grid-template-columns: 1fr 1fr; }
  .memo-card { display: none; }
  .play-area { min-height: 590px; }
}
@media (max-width: 760px) {
  .app-shell { width: min(100% - 20px, 680px); padding-top: 8px; }
  .topbar { min-height: 58px; grid-template-columns: auto 1fr auto; gap: 8px; }.brand { font-size: 25px; }.title-lockup { min-width: 0; }.title-lockup small { display: none; }.title-lockup strong { font-size: 17px; }.topbar-actions { gap: 5px; }.mini-button { min-height: 34px; padding: 0 9px; font-size: 11px; }
  .game-heading { min-height: 78px; padding: 13px 15px; }.stage-copy { display: none; }
  h1 { font-size: clamp(20px, 5.7vw, 28px); }
  .play-area { min-height: 0; padding: 10px; grid-template-columns: 1fr; gap: 10px; }
  .board-wrap { min-height: 390px; padding: 49px 18px 24px; }
  .box-label { left: 18px; right: 18px; }.box-label span:last-child { display: none; }
  .tray-panel { min-height: 260px; }.cat-tray { grid-template-columns: repeat(3, minmax(0,1fr)); max-height: 310px; }
  .cat-card { min-height: 112px; }.piece-visual { --tile: 36px; }
  .info-column { grid-template-columns: 1fr; }.stage-card { display: grid; grid-template-columns: 110px 1fr; }.stage-number { min-height: 82px; border-right: 2px dashed rgba(75,57,40,.3); border-bottom: 0; }.stage-number strong { font-size: 40px; }
  .footer-note { justify-content: center; }.footer-note p { display: none; }
}
@media (max-width: 430px) {
  .title-lockup { display: none; }
  .game-panel { border-radius: 20px; }.game-heading .eyebrow { font-size: 8px; }
  .board-wrap { min-height: 320px; padding-left: 12px; padding-right: 12px; }.board-note { font-size: 11px; }
  .cat-tray { grid-template-columns: repeat(2, minmax(0,1fr)); }.cat-card { min-height: 106px; }.piece-visual { --tile: 34px; }
}
