:root {
  --washi: #f6efe3; --washi2: #efe4d1; --ink: #3b2c2a; --ai: #2f3f72; --shu: #d9472b; --sakura: #f7c9d8; --matcha: #9cbf6b;
  --wood: #c9925c; --wood2: #a8713f; --gold: #e9b949;
  --fs: clamp(11px, calc(min(2.1vh, 1.5vw) + 4px), 19px);
  font-size: var(--fs);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--washi); color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", "Meiryo", "Noto Sans JP", sans-serif;
  touch-action: manipulation; user-select: none; -webkit-user-select: none; }
body { background-color: var(--washi);
  background-image: radial-gradient(rgba(160, 120, 80, .07) 1px, transparent 1.4px), radial-gradient(rgba(160, 120, 80, .05) 1px, transparent 1.6px);
  background-size: 7px 9px, 13px 11px; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
a.big { font: inherit; cursor: pointer; }
.hide { display: none !important; }
#app { position: fixed; inset: 0; display: grid; grid-template-columns: 1fr minmax(17rem, 44%); grid-template-rows: auto 1fr;
  grid-template-areas: "top top" "stage panel"; }

/* header: indigo noren strip with a seigaiha edge */
#top { grid-area: top; display: flex; align-items: center; gap: .5rem; padding: .3rem .55rem; background: var(--ai); color: #fff;
  position: relative; z-index: 3; min-height: 2.6rem; box-shadow: 0 2px 0 #23305a; }
#top::after { content: ""; position: absolute; left: 0; right: 0; bottom: -6px; height: 6px;
  background: radial-gradient(circle at 6px 0, var(--ai) 5px, transparent 5.5px) 0 0/12px 6px repeat-x; }
#brand { font-weight: 800; letter-spacing: .04em; white-space: nowrap; font-size: 1.15rem; }
#brand .b1 { color: var(--sakura); } #brand .b2 { color: #fff; }
#modeChip { font-size: .82rem; background: rgba(255,255,255,.16); border-radius: 99px; padding: .15rem .6rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#modeChip:empty { display: none; }
#icons { margin-left: auto; display: flex; gap: .3rem; }
.ic { width: 2.15rem; height: 2.15rem; border-radius: .6rem; display: grid; place-items: center; background: rgba(255,255,255,.12); color: #fff; flex: none; }
.ic svg { width: 62%; height: 62%; }
.ic:active { transform: scale(.92); }
.ic .x { display: none; } .ic.off .x { display: inline; } .ic.off .w { display: none; } .ic.off { opacity: .6; }

/* stage */
#stage { grid-area: stage; position: relative; overflow: hidden; background: #e9dcc6; }
#bg { position: absolute; inset: 0; background-size: cover; background-position: center 70%; transition: opacity .25s; }
#dollWrap { position: absolute; left: 0; right: 0; bottom: 1.6rem; top: 2.2rem; display: flex; justify-content: center; pointer-events: none; }
#doll { height: 100%; width: 100%; filter: drop-shadow(0 6px 4px rgba(60, 30, 20, .22)); overflow: visible; }
#doll.pop { animation: pop .28s ease-out; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.035, .975); } 100% { transform: scale(1); } }
#you { position: absolute; left: 50%; bottom: .35rem; transform: translateX(-50%); background: #fff; color: var(--shu); font-weight: 800;
  font-size: .8rem; padding: .12rem .7rem; border-radius: .3rem; border: 2px solid var(--shu); white-space: nowrap; box-shadow: 0 2px 0 rgba(0,0,0,.12); }
#you::before { content: "▲"; position: absolute; left: 50%; top: -.85rem; transform: translateX(-50%); font-size: .6rem; color: var(--shu); }
#hint { position: absolute; left: 50%; top: .55rem; transform: translateX(-50%); background: rgba(255, 252, 245, .92); padding: .22rem .75rem;
  border-radius: 99px; font-size: .78rem; white-space: nowrap; max-width: 96%; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
#task { position: absolute; left: .5rem; top: 2.4rem; width: min(15.5rem, 46%); background: rgba(255, 252, 245, .95); border-radius: .6rem; padding: .45rem .55rem;
  font-size: .76rem; box-shadow: 0 2px 6px rgba(0,0,0,.18); border-top: .35rem solid var(--shu); }
#task h3 { margin: 0 0 .25rem; font-size: .88rem; color: var(--shu); }
#task ul { list-style: none; margin: 0; padding: 0; }
#task li { display: flex; gap: .3rem; align-items: flex-start; line-height: 1.3; margin: .12rem 0; }
#task li i { flex: none; width: 1.05rem; height: 1.05rem; border-radius: .25rem; border: 2px solid #b9a690; display: grid; place-items: center; font-style: normal; font-size: .7rem; color: #fff; }
#task li.ok i { background: var(--matcha); border-color: #6f9a43; }
#task li.ok { color: #557a2f; }
#bJudge { position: absolute; right: .6rem; bottom: .6rem; }
#fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.spark { position: absolute; width: 1rem; height: 1rem; animation: spark .8s ease-out forwards; }
@keyframes spark { 0% { transform: translate(0,0) scale(.4) rotate(0); opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(1.1) rotate(160deg); opacity: 0; } }
.flash { position: absolute; inset: 0; background: #fff; animation: flash .45s ease-out forwards; pointer-events: none; }
@keyframes flash { from { opacity: .9; } to { opacity: 0; } }

/* panel: wooden tansu with drawers */
#panel { grid-area: panel; display: grid; grid-template-columns: 4.2rem 1fr; min-height: 0; background: linear-gradient(90deg, var(--wood2), var(--wood) 30%, var(--wood)); padding: .45rem .45rem .45rem .35rem; gap: .4rem; }
#cats { display: flex; flex-direction: column; gap: .25rem; min-height: 0; }
.cat { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .05rem;
  background: linear-gradient(#e2b483, #d29c66); border-radius: .4rem; box-shadow: inset 0 -3px 0 rgba(90, 50, 20, .35), 0 1px 0 rgba(255,255,255,.3);
  color: #5a3416; font-size: .66rem; font-weight: 700; position: relative; padding: .1rem 0; overflow: hidden; }
.cat svg { width: 1.25rem; height: 1.25rem; flex: none; }
.cat svg path { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.cat .kn { position: absolute; right: .2rem; top: .15rem; font-size: .5rem; opacity: .55; }
.cat.on { background: linear-gradient(#fff6ea, #f6e3cb); color: var(--shu); box-shadow: inset 0 0 0 2px var(--shu); }
.cat span { white-space: nowrap; }
#content { min-height: 0; min-width: 0; display: flex; flex-direction: column; background: var(--washi); border-radius: .55rem; padding: .4rem; gap: .3rem;
  box-shadow: inset 0 0 0 2px rgba(120, 70, 30, .25); }
#sub { font-size: .74rem; font-weight: 700; color: var(--ai); display: flex; justify-content: space-between; gap: .4rem; white-space: nowrap; overflow: hidden; }
#sub em { font-style: normal; color: #8a7a6a; font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
#itemsBox { flex: 1 1 auto; min-height: 0; position: relative; }
#items { position: absolute; inset: 0; display: grid; gap: .3rem; align-content: start; justify-content: center; }
.tile { border-radius: .5rem; background: #fffdf8; box-shadow: 0 1px 0 rgba(0,0,0,.12), inset 0 0 0 1.5px #e3d5c1; position: relative; overflow: hidden; display: grid; place-items: center; }
.tile svg { width: 92%; height: 92%; }
.tile .lb { position: absolute; left: 0; right: 0; bottom: 0; font-size: .56rem; text-align: center; background: rgba(255, 253, 248, .86); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 .1rem; }
.tile.on { box-shadow: inset 0 0 0 3px var(--shu); background: #fff1ec; }
.tile.on::after { content: "✓"; position: absolute; right: .15rem; top: .1rem; width: 1rem; height: 1rem; border-radius: 50%; background: var(--shu); color: #fff; font-size: .62rem; display: grid; place-items: center; font-weight: 800; }
.tile.kf { outline: 2px dashed var(--ai); outline-offset: -5px; }
.tile.bgt { background-size: cover; background-position: center; }
.tile:active { transform: scale(.95); }
#pager { display: flex; align-items: center; justify-content: center; gap: .6rem; font-size: .72rem; color: #7a6a5a; }
#pager button { width: 2.4rem; height: 1.6rem; border-radius: .4rem; background: var(--ai); color: #fff; font-size: 1.05rem; line-height: 1; }
#pager button:disabled { opacity: .3; }
#colors { display: flex; flex-direction: column; gap: .28rem; }
#sw { display: grid; gap: .26rem; justify-content: center; }
#sw .swc { width: var(--sw, 1.75rem); height: var(--sw, 1.75rem); }
#pats { display: flex; flex-wrap: wrap; gap: .26rem; justify-content: center; }
.swc { width: 1.75rem; height: 1.75rem; border-radius: 50%; box-shadow: inset 0 0 0 2px rgba(0,0,0,.18); position: relative; flex: none; }
.swc.on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--shu); }
.swl { font-size: .62rem; color: #8a7a6a; align-self: center; margin-right: .1rem; }
.pat { width: 2.35rem; height: 1.6rem; border-radius: .35rem; overflow: hidden; box-shadow: inset 0 0 0 1.5px #d8c8b2; position: relative; flex: none; }
.pat svg { width: 100%; height: 100%; display: block; }
.pat span { position: absolute; inset: auto 0 0 0; font-size: .5rem; background: rgba(255,255,255,.8); text-align: center; line-height: 1.2; }
.pat.on { box-shadow: 0 0 0 2px var(--shu); }

/* buttons */
.big { background: var(--shu); color: #fff; font-weight: 800; font-size: 1rem; padding: .55rem 1.1rem; border-radius: .7rem; box-shadow: 0 3px 0 #9e2f19;
  white-space: nowrap; text-decoration: none; display: inline-block; text-align: center; }
.big.alt { background: #fff; color: var(--ai); box-shadow: 0 3px 0 #b7a993, inset 0 0 0 2px var(--ai); }
.big:active { transform: translateY(2px); box-shadow: 0 1px 0 #9e2f19; }
#bJudge { font-size: 1.15rem; padding: .6rem 1.4rem; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-3px); } }

/* overlays */
.ov { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(47, 63, 114, .55); padding: .6rem; }
.card { background: var(--washi); border-radius: 1rem; box-shadow: 0 8px 30px rgba(0,0,0,.3); padding: 1rem 1.1rem; max-height: calc(100vh - 1.2rem); max-width: 100%;
  border: 3px solid #fff; outline: 2px solid var(--shu); outline-offset: -8px; display: flex; flex-direction: column; min-height: 0; }
.startCard { flex-direction: row; gap: 1rem; align-items: center; width: min(44rem, 100%); }
.sc-left { flex: 0 0 34%; align-self: stretch; display: flex; align-items: flex-end; justify-content: center; background: radial-gradient(circle at 50% 60%, #fff 0, #fbe3ea 55%, transparent 70%); min-height: 0; }
#startDoll { width: 100%; height: 100%; max-height: 22rem; }
.sc-right { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .7rem; }
.logo small { display: block; color: var(--shu); font-weight: 700; letter-spacing: .12em; font-size: .8rem; }
.logo b { display: block; font-size: 2.3rem; line-height: 1.05; color: var(--ai); letter-spacing: .04em; }
.intro { margin: 0; font-size: .92rem; line-height: 1.55; }
.btns { display: flex; gap: .6rem; flex-wrap: wrap; }
.btns .big { font-size: 1.12rem; padding: .7rem 1.2rem; }
.keys { display: flex; flex-wrap: wrap; gap: .25rem .7rem; font-size: .72rem; color: #6e5e50; }
kbd { display: inline-block; min-width: 1.3em; padding: 0 .3em; margin: 0 .12em; border-radius: .25em; background: #fff; border: 1px solid #cdbca5; box-shadow: 0 1.5px 0 #cdbca5; font: inherit; font-size: .9em; text-align: center; }
.lvCard { width: min(46rem, 100%); }
.lvCard h2, .resCard h2 { margin: 0; color: var(--ai); font-size: 1.35rem; }
.lvSub { margin: .25rem 0 .5rem; font-size: .82rem; }
#lvGrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .45rem; overflow-y: auto; min-height: 0; padding: .15rem; }
.lv { position: relative; border-radius: .6rem; overflow: hidden; aspect-ratio: 16 / 10; background-size: cover; background-position: center; box-shadow: 0 2px 0 rgba(0,0,0,.18), inset 0 0 0 2px #fff; text-align: left; }
.lv b { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(255, 252, 245, .92); font-size: .74rem; padding: .2rem .35rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lv .hm { position: absolute; right: .25rem; top: .25rem; display: flex; gap: 1px; }
.lv .hm svg { width: 1.15rem; height: 1.15rem; }
.lv .no { position: absolute; left: .3rem; top: .25rem; background: var(--shu); color: #fff; font-size: .66rem; font-weight: 800; border-radius: .3rem; padding: 0 .3rem; }
.foot { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; margin-top: .6rem; flex: none; }
.resCard { width: min(30rem, 100%); }
.resTop { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; justify-content: center; }
#resTitle { font-weight: 800; color: var(--ai); font-size: 1.05rem; width: 100%; text-align: center; }
#resScore { font-size: 2.4rem; font-weight: 900; color: var(--shu); line-height: 1; }
#resScore small { font-size: .9rem; margin-left: .15rem; }
#stamps { display: flex; gap: .3rem; }
#stamps svg { width: 3.1rem; height: 3.1rem; opacity: 0; transform: scale(2.2) rotate(-25deg); }
#stamps svg.in { animation: stampIn .32s cubic-bezier(.3, 1.6, .5, 1) forwards; }
#stamps svg.empty { opacity: .22; transform: none; filter: grayscale(1); }
@keyframes stampIn { to { opacity: 1; transform: scale(1) rotate(-8deg); } }
#resList { margin-top: .5rem; font-size: .8rem; overflow-y: auto; min-height: 0; }
#resList div { display: flex; justify-content: space-between; gap: .6rem; border-bottom: 1px dashed #d8c8b2; padding: .2rem 0; }
#resList div b { color: var(--ai); white-space: nowrap; }
#resList div.neg b { color: var(--shu); }
#resList .best { color: #8a7a6a; justify-content: center; border: 0; }
.phCard { align-items: center; width: min(26rem, 100%); }
#phImg { max-height: calc(100vh - 9rem); max-width: 100%; border-radius: .4rem; box-shadow: 0 2px 8px rgba(0,0,0,.25); min-height: 0; object-fit: contain; }
.phHint { margin: .4rem 0 0; font-size: .74rem; color: #6e5e50; }

/* portrait: stage on top, drawers as a row */
@media (max-aspect-ratio: 1/1) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr) minmax(0, 1.05fr); grid-template-areas: "top" "stage" "panel"; }
  #panel { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); padding: .35rem; gap: .35rem; }
  #cats { flex-direction: row; }
  .cat { height: 3rem; }
  #brand { font-size: .95rem; }
  .startCard { flex-direction: column; }
  .sc-left { flex: none; height: 11rem; width: 100%; }
  #lvGrid { grid-template-columns: repeat(2, 1fr); }
  #task { top: 2.3rem; width: min(13.5rem, 60%); }
}
@media (max-aspect-ratio: 1/1) and (max-width: 420px) {
  #brand { font-size: .88rem; letter-spacing: 0; }
  .ic { width: 1.9rem; height: 1.9rem; }
  #icons { gap: .22rem; }
  #modeChip { display: none; }
}
/* short frames (store page embed 794x447, 640x360, phone landscape) */
@media (max-height: 560px) {
  :root { --fs: clamp(11px, calc(min(2.3vh, 1.45vw) + 3px), 15px); }
  #top { min-height: 2.2rem; padding: .2rem .45rem; }
  .ic { width: 1.85rem; height: 1.85rem; }
  .card { padding: .65rem .8rem; }
  .startCard { width: min(40rem, 100%); }
  .logo b { font-size: 1.8rem; }
  .sc-right { gap: .45rem; }
  #startDoll { max-height: 15rem; }
  .lv { aspect-ratio: 16 / 8; }
  .lvSub { margin: .1rem 0 .3rem; }
  #hint { font-size: .72rem; top: .45rem; }
  #task { top: 2.1rem; }
  .foot { margin-top: .4rem; }
  .swc { width: 1.5rem; height: 1.5rem; }
  .pat { height: 1.35rem; width: 2.1rem; }
}
@media (max-height: 420px) {
  .sc-left { display: none; }
  .intro { font-size: .82rem; }
  .keys { display: none; }
  #lvGrid { grid-template-columns: repeat(4, 1fr); gap: .3rem; }
  .lv { aspect-ratio: 16 / 7; }
  .lvSub { display: none; }
  .lvCard h2 { font-size: 1.05rem; }
  #resList { font-size: .72rem; }
  #resScore { font-size: 1.9rem; }
  #stamps svg { width: 2.4rem; height: 2.4rem; }
  .big { padding: .4rem .8rem; font-size: .9rem; }
  #task { font-size: .7rem; padding: .3rem .4rem; }
  #task li { margin: 0; }
  .swc { width: 1.35rem; height: 1.35rem; }
}
