:root {
  --ink: #2b2a4c; --washi: #fbf3e4; --washi2: #f3e3c7; --lacquer: #6e2a20; --lacquer2: #4e1c16; --gold: #d9a63a; --shu: #e2553d;
  --font: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", "Noto Sans JP", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --num: "Trebuchet MS", "Arial Rounded MT Bold", "Hiragino Maru Gothic ProN", system-ui, sans-serif;
  --tdur: 110ms;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; font-family: var(--font); color: var(--ink);
  background: #f6ead3 url(img/bg.webp) center / cover no-repeat;
  user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center;
  padding: max(6px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom)); }
#app > * { width: 100%; max-width: 600px; }
button { font-family: inherit; color: inherit; cursor: pointer; }
.sp { flex: 1; }
header { display: flex; align-items: center; gap: 8px; padding: 2px 0 6px; }
#logo { display: flex; flex-direction: column; line-height: 1; }
#logo span { font-family: var(--num); font-weight: 900; font-size: 40px; color: var(--shu); letter-spacing: 1px;
  text-shadow: 0 3px 0 var(--lacquer2); }
#logo small { font-size: 12px; font-weight: 800; color: var(--lacquer); margin-top: 3px; letter-spacing: 1px; }
.score { min-width: 76px; padding: 5px 10px 6px; border-radius: 12px; background: var(--lacquer); color: #fff; text-align: center;
  border: 2px solid var(--gold); box-shadow: 0 3px 0 var(--lacquer2); position: relative; }
.score.best { background: var(--ink); }
.score b { display: block; font-size: 11px; color: #f7d98e; letter-spacing: 1px; }
.score span { display: block; font-family: var(--num); font-weight: 900; font-size: 21px; }
.score .plus { position: absolute; left: 0; right: 0; top: 8px; font-family: var(--num); font-weight: 900; color: var(--gold); font-size: 18px;
  animation: plus .8s ease-out forwards; pointer-events: none; text-shadow: 0 1px 0 #000; }
@keyframes plus { from { opacity: 1; transform: translateY(0) } to { opacity: 0; transform: translateY(-34px) } }
#bar { display: flex; align-items: center; gap: 6px; padding: 0 0 4px; }
#modeTag, #timer { padding: 5px 11px; border-radius: 999px; background: var(--washi); border: 2px solid var(--ink); font-weight: 800; font-size: 13px; white-space: nowrap; }
#timer { font-family: var(--num); font-size: 16px; background: #fff1c9; }
#timer.warn { background: var(--shu); color: #fff; animation: beat 1s infinite; }
@keyframes beat { 50% { transform: scale(1.08) } }
.ib { flex: none; height: 38px; min-width: 38px; border-radius: 11px; border: 2px solid var(--ink); background: var(--washi);
  box-shadow: 0 3px 0 var(--ink); display: flex; align-items: center; justify-content: center; gap: 3px; padding: 0 6px; }
.ib.wide { padding: 0 9px; font-weight: 900; font-family: var(--num); font-size: 16px; }
.ib:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.ib:disabled { opacity: .45; }
.ib svg { width: 20px; height: 20px; }
.ib .slash { display: none; }
.ib.off { opacity: .6; } .ib.off .slash { display: block; }
#tipbar { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding-bottom: 4px; }
#mascot { width: 46px; height: 46px; object-fit: contain; flex: none; filter: drop-shadow(0 2px 0 rgba(0,0,0,.15)); }
#mascot.bump { animation: bump .5s; }
#mascot.sad { filter: grayscale(.3); }
@keyframes bump { 0% { transform: scale(1) } 35% { transform: scale(1.3) rotate(-10deg) translateY(-6px) } 100% { transform: scale(1) } }
#tip { background: rgba(255,250,240,.94); border: 2px solid var(--ink); border-radius: 14px; padding: 5px 12px; font-size: 14px; font-weight: 800; line-height: 1.25;
  box-shadow: 0 3px 0 rgba(43,42,76,.3); }
#stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#board { position: relative; border-radius: 16px; background: linear-gradient(160deg, #8a3a2b, var(--lacquer) 45%, var(--lacquer2));
  box-shadow: 0 0 0 3px var(--gold), 0 0 0 6px var(--lacquer2), 0 10px 24px rgba(78,28,22,.35); touch-action: none; }
#cells, #tiles, #fx { position: absolute; inset: 0; }
#fx { pointer-events: none; overflow: visible; }
.cell { position: absolute; border-radius: 10px; background: rgba(251,243,228,.2); box-shadow: inset 0 2px 4px rgba(0,0,0,.25); }
.tile { position: absolute; left: 0; top: 0; transition: transform var(--tdur) ease-in-out; will-change: transform; }
.tile .in { width: 100%; height: 100%; border-radius: 10px; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden;
  font-family: var(--num); font-weight: 900; box-shadow: inset 0 -4px 0 rgba(0,0,0,.16), inset 0 2px 0 rgba(255,255,255,.45); }
.tile .in::before { content: ""; position: absolute; inset: 0; opacity: .18;
  background: radial-gradient(circle at 50% 120%, transparent 38%, rgba(255,255,255,.9) 39%, rgba(255,255,255,.9) 42%, transparent 43%, transparent 52%, rgba(255,255,255,.9) 53%, rgba(255,255,255,.9) 56%, transparent 57%); }
.tile .in img { position: absolute; width: 58%; height: 58%; right: -8%; bottom: -8%; opacity: .38; pointer-events: none; }
.tile .in span { position: relative; z-index: 1; }
.tile.new .in { animation: appear 180ms ease-out var(--tdur) backwards; }
.tile.pop .in { animation: pop 200ms ease-out var(--tdur) backwards; }
.tile.pop { z-index: 2; }
@keyframes appear { from { transform: scale(0); opacity: 0 } to { transform: scale(1); opacity: 1 } }
@keyframes pop { 0% { transform: scale(0) } 50% { transform: scale(1.2) } 100% { transform: scale(1) } }
.tile.gone { z-index: 0; }
.v2 .in { background: #fff8ec; color: #5b4636; }
.v4 .in { background: #fbdcd7; color: #6b3a3f; }
.v8 .in { background: #f7b68b; color: #fff; }
.v16 .in { background: #f08c4a; color: #fff; }
.v32 .in { background: #e5573c; color: #fff; }
.v64 .in { background: #c8385a; color: #fff; }
.v128 .in { background: #86ad4f; color: #fff; }
.v256 .in { background: #3f9a86; color: #fff; }
.v512 .in { background: #6c5bb0; color: #fff; }
.v1024 .in { background: #2f4c8f; color: #fff; }
.v2048 .in { background: linear-gradient(145deg, #ffe08a, #e2a62a 55%, #c27f17); color: #fff; text-shadow: 0 2px 0 rgba(120,60,0,.5);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.16), 0 0 18px 4px rgba(255,205,90,.7); }
.vbig .in { background: linear-gradient(145deg, #3a2b3e, #1f1726); color: #ffd56a; box-shadow: inset 0 -4px 0 rgba(0,0,0,.3), 0 0 0 2px #d9a63a inset; }
.petal { position: absolute; width: 14px; height: 14px; border-radius: 80% 0 80% 0; background: #f7a8b8; pointer-events: none; animation: fly 1s ease-out forwards; }
@keyframes fly { to { transform: translate(var(--dx), var(--dy)) rotate(260deg); opacity: 0 } }
.ov { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 14px;
  background: rgba(43,32,40,.42); }
.card { width: 100%; max-width: 420px; max-height: 100%; overflow: auto; background: var(--washi); border: 3px solid var(--ink); border-radius: 22px;
  box-shadow: 0 0 0 4px var(--gold) inset, 0 8px 0 var(--lacquer2); padding: 16px 18px 14px; text-align: center; }
.ptitle { display: flex; align-items: center; justify-content: center; gap: 10px; }
.ptitle img { width: 84px; height: 84px; object-fit: contain; }
.ptitle h1 { margin: 0; font-family: var(--num); font-size: 54px; line-height: 1; color: var(--shu); text-shadow: 0 4px 0 var(--lacquer2); }
.ptitle .sub { margin: 4px 0 0; font-weight: 900; color: var(--lacquer); letter-spacing: 2px; }
.intro { font-size: 13.5px; line-height: 1.55; margin: 8px 0 10px; font-weight: 600; }
.seg { display: flex; gap: 6px; margin: 0 0 8px; }
.seg button { flex: 1; padding: 9px 4px; border-radius: 12px; border: 2px solid var(--ink); background: #fff; font-weight: 900; font-size: 14px; box-shadow: 0 3px 0 var(--ink); }
.seg button.on { background: var(--ink); color: #fff; }
.pbest { margin: 2px 0 8px; font-weight: 800; font-size: 13px; color: var(--lacquer); }
.big { display: block; width: 100%; padding: 13px; border-radius: 16px; border: 3px solid var(--lacquer2); background: linear-gradient(#f0694e, var(--shu));
  color: #fff; font-size: 24px; font-weight: 900; letter-spacing: 3px; box-shadow: 0 5px 0 var(--lacquer2); }
.big:active, .small:active, .seg button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--lacquer2); }
.small { display: block; width: 100%; margin-top: 8px; padding: 9px; border-radius: 12px; border: 2px solid var(--ink); background: #fff; font-weight: 900; font-size: 15px; box-shadow: 0 3px 0 var(--ink); }
.ctl { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; }
.keys { display: grid; grid-template-columns: repeat(3, 28px); grid-template-rows: 28px 28px; gap: 3px; }
.k { display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 7px; background: #fff; font-weight: 900; font-size: 14px; box-shadow: 0 2px 0 var(--ink); }
.k.up { grid-column: 2; grid-row: 1; } .k.l { grid-column: 1; grid-row: 2; } .k.d { grid-column: 2; grid-row: 2; } .k.r { grid-column: 3; grid-row: 2; }
.ctltxt { font-size: 12.5px; font-weight: 700; text-align: left; line-height: 1.5; }
.small-card { max-width: 340px; }
.ovimg { width: 110px; height: 110px; object-fit: contain; }
.small-card h2 { margin: 2px 0 4px; font-size: 28px; color: var(--lacquer); }
.ovscore { margin: 0 0 6px; }
.ovscore span { display: block; font-family: var(--num); font-size: 44px; font-weight: 900; color: var(--shu); }
.ovscore small { font-weight: 800; }
.ovnew { margin: 0 0 8px; font-weight: 900; color: #fff; background: var(--gold); display: inline-block; padding: 3px 14px; border-radius: 999px; }
@media (max-width: 420px) { #bar { gap: 4px } .ib { min-width: 35px; height: 36px; padding: 0 4px } .ib.wide { padding: 0 6px } #modeTag, #timer { padding: 4px 8px; font-size: 12px } #timer { font-size: 15px } }
@media (max-height: 640px) { #tipbar { min-height: 36px } #mascot { width: 34px; height: 34px } #logo span { font-size: 32px } .ptitle img { width: 60px; height: 60px } .intro { margin: 4px 0 6px } }
@media (min-aspect-ratio: 1/1) { html, body { background-image: url(img/bg_wide.webp); } }
/* embed-fit: short landscape frame (store-page small window, 640x360 .. 908x511, phone landscape) */
@media (max-height: 560px) and (min-aspect-ratio: 5/4) {
  #app { display: grid; grid-template-columns: minmax(200px, 260px) minmax(0, 1fr); grid-template-rows: auto auto 1fr;
    column-gap: 16px; padding: max(8px, env(safe-area-inset-top)) 14px max(8px, env(safe-area-inset-bottom)); justify-content: center; }
  #app > * { max-width: none; }
  header { grid-column: 1; grid-row: 1; flex-wrap: wrap; gap: 6px; }
  header .sp { display: none; }
  #logo { width: 100%; flex-direction: row; align-items: baseline; gap: 8px; margin-bottom: 4px; }
  #logo span { font-size: 30px; }
  .score { flex: 1; min-width: 0; padding: 3px 8px 4px; }
  .score span { font-size: 19px; }
  #bar { grid-column: 1; grid-row: 2; flex-wrap: wrap; padding: 4px 0 6px; gap: 5px; }
  #modeTag, #timer { order: -1; }
  #bar .sp { flex-basis: 100%; height: 0; }
  .ib { height: 34px; min-width: 34px; }
  #tipbar { grid-column: 1; grid-row: 3; align-self: start; justify-content: flex-start; align-items: flex-start; }
  #tip { font-size: 13px; }
  #stage { grid-column: 2; grid-row: 1 / 4; align-self: stretch; }
  .ov { padding: 8px; }
  #panel .card { max-width: 660px; display: grid; grid-template-columns: 1fr 1.1fr; column-gap: 14px; align-items: center; padding: 12px 14px; }
  #panel .ptitle { grid-column: 1; grid-row: 1 / 3; }
  #panel .intro { grid-column: 1; grid-row: 3 / 5; font-size: 12.5px; line-height: 1.45; margin: 4px 0; }
  #panel .ctl { grid-column: 1; grid-row: 5 / 7; margin-top: 4px; }
  #panel .seg, #panel .pbest, #panel .big, #panel .small { grid-column: 2; }
  .ptitle h1 { font-size: 44px; }
  .big { padding: 10px; font-size: 21px; }
  .small { padding: 7px; font-size: 14px; margin-top: 6px; }
  .small-card { max-width: 520px; display: grid; grid-template-columns: auto 1fr; column-gap: 14px; align-items: center; padding: 12px 16px; }
  .small-card > * { grid-column: 2; }
  .small-card .ovimg { grid-column: 1; grid-row: 1 / 8; width: 96px; height: 96px; }
  .small-card h2 { font-size: 24px; }
  .ovscore span { font-size: 36px; }
}
@media (max-height: 420px) and (min-aspect-ratio: 5/4) {
  #logo small { display: none; }
  #logo span { font-size: 26px; }
  #mascot { width: 30px; height: 30px; }
  #tip { font-size: 12px; padding: 4px 9px; }
  .ptitle img { width: 52px; height: 52px; }
  .ptitle h1 { font-size: 38px; }
  .seg { margin-bottom: 6px; }
  .seg button { padding: 7px 4px; font-size: 13px; }
  .keys { grid-template-columns: repeat(3, 22px); grid-template-rows: 22px 22px; }
  .k { font-size: 12px; }
  .ctltxt { font-size: 11.5px; }
  .small-card .ovimg { width: 72px; height: 72px; }
  .small-card h2 { font-size: 21px; }
  .ovscore span { font-size: 30px; }
}
