:root {
  --navy: #2d3a64; --navy2: #46568c; --cream: #fffaf2; --paper: #fbf1e4; --rose: #f7b9cc; --rose2: #ef8fb0; --gold: #d9ab45; --sage: #a9c7a4;
  font-size: clamp(11px, calc(min(2.1vh, 1.35vw) + 5px), 27px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); }
body { font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif; color: var(--navy); user-select: none; -webkit-user-select: none; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
.hide { display: none !important; }
#app { position: fixed; inset: 0; display: grid; grid-template-rows: auto 1fr; grid-template-columns: 1fr clamp(290px, 42vw, 820px); grid-template-areas: "top top" "stage panel"; }

/* header: navy + marinière stripe */
#top { grid-area: top; display: flex; align-items: center; gap: .6rem; padding: .35rem .7rem .55rem; background: var(--navy); color: #fff; position: relative; z-index: 3; }
#top::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: .32rem; background: repeating-linear-gradient(90deg, #fff 0 .9rem, var(--rose) .9rem 1.8rem); }
#brand { font-family: Georgia, "Times New Roman", serif; font-style: italic; font-weight: 700; font-size: 1.35rem; letter-spacing: .02em; white-space: nowrap; }
#brand .b2 { color: var(--rose); margin-left: .25rem; }
#modes { display: flex; gap: .3rem; flex: 1; justify-content: center; min-width: 0; }
.mode { display: flex; align-items: center; gap: .3rem; padding: .35rem .7rem; border-radius: 999px; font-weight: 700; font-size: .95rem; color: #fff; background: rgba(255,255,255,.1); border: 2px solid transparent; white-space: nowrap; }
.mode svg { width: 1.25rem; height: 1.25rem; flex: none; }
.mode.on { background: var(--rose); color: var(--navy); border-color: #fff; }
.mode:hover { background: rgba(255,255,255,.22); } .mode.on:hover { background: var(--rose); }
#icons { display: flex; gap: .3rem; }
.ic { width: 2.3rem; height: 2.3rem; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.14); color: #fff; }
.ic svg { width: 1.3rem; height: 1.3rem; }
.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; min-height: 0; }
#bg { position: absolute; inset: 0; background: #f6e7d8 center / cover no-repeat; transition: opacity .3s; }
#frame { position: absolute; left: 50%; bottom: 3%; transform: translateX(-50%); height: 86%; aspect-ratio: .62; border-radius: 50% 50% 46% 46% / 40% 40% 12% 12%; background: radial-gradient(ellipse at 50% 35%, rgba(255,250,242,.82), rgba(255,250,242,.38) 70%); border: .32rem solid var(--gold); box-shadow: 0 0 0 .22rem #fff inset, 0 .5rem 1.4rem rgba(45,58,100,.22); pointer-events: none; }
#model, #hand { position: absolute; left: 0; right: 0; top: 2.6rem; bottom: 1.9rem; width: 100%; height: calc(100% - 4.5rem); }
#hand { background: rgba(255,250,242,.0); }
#hand .nail { cursor: pointer; }
#hand .nail.sel > path:first-child { stroke: var(--rose2); stroke-width: 4; }
#you { position: absolute; left: 50%; bottom: .35rem; transform: translateX(-50%); background: var(--navy); color: #fff; padding: .2rem .8rem; border-radius: 999px; font-size: .85rem; white-space: nowrap; box-shadow: 0 2px 0 rgba(0,0,0,.15); }
#you b { color: var(--rose); letter-spacing: .05em; }
#hint { position: absolute; left: 50%; top: .45rem; transform: translateX(-50%); background: rgba(255,250,242,.95); border: 2px solid var(--navy); border-radius: 999px; padding: .25rem .9rem; font-weight: 700; font-size: .9rem; white-space: nowrap; max-width: 96%; overflow: hidden; text-overflow: ellipsis; z-index: 2; }
#task { position: absolute; left: .5rem; top: 2.7rem; width: min(13rem, 34%); background: #fff; border: 2px solid var(--navy); border-radius: .8rem; padding: .45rem .55rem; font-size: .8rem; line-height: 1.25; box-shadow: .25rem .25rem 0 var(--rose); z-index: 2; }
#task b { display: block; font-family: Georgia, serif; font-style: italic; font-size: .98rem; margin-bottom: .15rem; }
#bShow { position: absolute; right: .6rem; bottom: .5rem; z-index: 2; font-size: 1rem; padding: .55rem 1rem; }
#fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 4; }
.spark { position: absolute; width: 1rem; height: 1rem; margin: -.5rem; animation: sp .8s ease-out forwards; }
@keyframes sp { from { transform: translate(0,0) scale(.4) rotate(0); opacity: 1; } to { transform: translate(var(--dx), var(--dy)) scale(1.1) rotate(160deg); opacity: 0; } }
#model.pop { animation: pop .28s ease-out; }
@keyframes pop { 40% { transform: scale(1.025); } }

/* panel */
#panel { grid-area: panel; display: flex; flex-direction: column; background: var(--cream); border-left: .25rem solid var(--navy); min-height: 0; min-width: 0; padding: .45rem .5rem .5rem; gap: .35rem; position: relative; }
#cats { display: flex; flex-wrap: wrap; gap: .25rem; }
.cat { padding: .28rem .6rem; border-radius: 999px; background: #fff; border: 2px solid var(--navy); font-weight: 700; font-size: .85rem; white-space: nowrap; }
.cat.on { background: var(--navy); color: #fff; }
#opts { display: flex; flex-direction: column; gap: .25rem; }
.row { display: flex; flex-wrap: wrap; gap: .25rem; align-items: center; }
.row > i { font-style: normal; font-size: .75rem; font-weight: 700; opacity: .75; margin-right: .15rem; min-width: 3.8rem; }
.sw { width: 1.7rem; height: 1.7rem; border-radius: 50%; border: 2px solid var(--navy); box-shadow: 0 0 0 2px #fff inset; }
.sw.on { outline: 3px solid var(--rose2); outline-offset: 1px; }
.pt { padding: .15rem .5rem; border-radius: .5rem; border: 2px solid var(--navy); background: #fff; font-size: .75rem; font-weight: 700; }
.pt.on { background: var(--rose); }
#gridBox { flex: 1; min-height: 0; display: flex; align-items: stretch; gap: .25rem; }
#grid { flex: 1; min-width: 0; display: grid; gap: .35rem; align-content: start; }
.pg { width: 1.7rem; border-radius: .6rem; background: #fff; border: 2px solid var(--navy); font-size: 1.4rem; font-weight: 700; }
.pg:disabled { opacity: .3; }
.tile { position: relative; background: #fff; border: 2px solid #e3d6c6; border-radius: .8rem; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; padding: .1rem; }
.tile svg { width: 100%; flex: 1; min-height: 0; }
.tile span { font-size: .68rem; font-weight: 700; line-height: 1.05; text-align: center; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 .15rem .1rem; }
.tile.on { border-color: var(--rose2); background: #fff2f6; box-shadow: 0 0 0 2px var(--rose2) inset; }
.tile.tool { background: #fdf6ea; }
.tile.dash { border-style: dashed; }
#acts { display: flex; flex-wrap: wrap; gap: .3rem; justify-content: center; }
.btn2 { padding: .4rem .8rem; border-radius: 999px; border: 2px solid var(--navy); background: #fff; font-weight: 700; font-size: .9rem; }
.big { display: inline-block; text-decoration: none; padding: .6rem 1.4rem; border-radius: 999px; background: var(--rose2); color: #fff; font-weight: 800; font-size: 1.15rem; border: 3px solid var(--navy); box-shadow: 0 .25rem 0 var(--navy); text-align: center; }
.big:active, .btn2:active, .tile:active, .sw:active { transform: translateY(2px); }

/* overlays */
.ov { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(45,58,100,.45); padding: .6rem; }
.card { background: var(--cream); border: 3px solid var(--navy); border-radius: 1.2rem; box-shadow: .45rem .45rem 0 var(--rose); max-height: 94vh; max-width: 96vw; display: flex; flex-direction: column; overflow: hidden; }
.foot { display: flex; gap: .5rem; justify-content: center; align-items: center; flex-wrap: wrap; padding: .5rem; flex: none; }
#start { background: rgba(45,58,100,.3) url(img/atelier.webp) center / cover; }
#start::before { content: ""; position: absolute; inset: 0; background: rgba(255,250,242,.35); }
.startCard { position: relative; flex-direction: row; align-items: center; gap: 1rem; padding: 1rem 1.4rem; width: min(44rem, 94vw); }
#startDog { width: 30%; max-width: 12rem; flex: none; }
.startTxt { display: flex; flex-direction: column; gap: .55rem; align-items: flex-start; min-width: 0; }
h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-style: italic; font-size: 2.3rem; line-height: 1; }
h1 small { display: block; font-size: 1.05rem; color: var(--rose2); margin-top: .3rem; font-style: normal; font-family: inherit; font-weight: 800; letter-spacing: .02em; }
.intro { margin: 0; font-size: .95rem; line-height: 1.35; }
.ctrl { font-size: .8rem; line-height: 1.9; }
.k { display: inline-block; border: 2px solid var(--navy); border-bottom-width: 3px; border-radius: .4rem; padding: 0 .35rem; background: #fff; font-weight: 700; line-height: 1.4; margin: 0 .15rem; }
#bPlay { font-size: 1.4rem; padding: .65rem 2.6rem; }
h2 { margin: 0; font-family: Georgia, serif; font-style: italic; font-size: 1.4rem; }
.defCard { width: min(46rem, 96vw); }
.defHead, .resHead { display: flex; gap: .7rem; align-items: center; padding: .6rem .9rem .3rem; flex: none; }
.defHead img, .resHead img { width: 3.6rem; flex: none; }
.defHead p { margin: .15rem 0 0; font-size: .85rem; }
#defList { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; padding: .3rem .8rem; overflow: auto; min-height: 0; }
.th { position: relative; border-radius: .8rem; overflow: hidden; border: 2px solid var(--navy); background: #fff center / cover; aspect-ratio: 1.75; display: flex; align-items: flex-end; text-align: left; }
.th span { width: 100%; background: rgba(255,250,242,.93); padding: .25rem .45rem; font-weight: 800; font-size: .85rem; line-height: 1.15; }
.th em { display: block; font-style: normal; color: var(--gold); font-size: .85rem; letter-spacing: .08em; }
.th .wk { position: absolute; top: .3rem; left: .3rem; background: var(--rose2); color: #fff; border: 2px solid var(--navy); border-radius: 999px; padding: .05rem .45rem; font-size: .7rem; font-weight: 800; }
.resCard { width: min(30rem, 94vw); }
#resStars { font-size: 1.7rem; color: var(--gold); letter-spacing: .1em; line-height: 1.1; }
#resStars .off { color: #e5d8c6; }
#resScore { font-weight: 800; font-size: .9rem; }
#resLines { padding: 0 1rem; overflow: auto; min-height: 0; }
.ln { display: flex; justify-content: space-between; gap: .5rem; font-size: .85rem; padding: .18rem 0; border-bottom: 1px dashed #e3d6c6; }
.ln b { white-space: nowrap; }
#resSay { margin: .35rem 1rem 0; font-style: italic; font-size: .9rem; }
.phCard { align-items: center; padding-top: .6rem; }
#phImg { max-height: calc(94vh - 5rem); max-width: 86vw; border-radius: .6rem; min-height: 0; }
#toast { position: absolute; left: 50%; top: 4.6rem; transform: translateX(-50%); background: var(--navy); color: #fff; padding: .45rem 1rem; border-radius: 999px; font-weight: 700; z-index: 20; white-space: nowrap; }

/* short windows (store frame 794x447, 640x360) */
@media (max-height: 560px) {
  :root { font-size: clamp(10px, calc(min(2.1vh, 1.3vw) + 3.2px), 15px); }
  #top { padding: .2rem .5rem .45rem; }
  .mode { padding: .22rem .5rem; }
  .ic { width: 2rem; height: 2rem; }
  .sw { width: 1.45rem; height: 1.45rem; }
  #startDog { width: 22%; }
  h1 { font-size: 1.9rem; }
  .startCard { padding: .7rem 1rem; }
  .th { aspect-ratio: 2.3; }
}
@media (max-width: 900px) and (min-aspect-ratio: 1/1) { .mode span { font-size: .85rem; } }
@media (max-width: 760px) and (min-aspect-ratio: 1/1) { .mode span { display: none; } .mode { padding: .3rem .55rem; } #brand .b1 { display: none; } }
@media (max-height: 420px) { #brand { display: none; } #task { width: min(11rem, 36%); font-size: .72rem; } #taskTip { display: none; } }

/* portrait phones */
@media (max-aspect-ratio: 1/1) {
  :root { font-size: clamp(11px, calc(1.2vh + 4px), 16px); }
  #app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "top" "stage" "panel"; }
  #top { flex-wrap: wrap; gap: .3rem; padding: .3rem .4rem .55rem; }
  #brand { order: 1; } #icons { order: 2; margin-left: auto; } #modes { order: 3; flex-basis: 100%; justify-content: space-between; }
  .mode { flex-direction: column; gap: 0; padding: .2rem .3rem; font-size: .72rem; border-radius: .7rem; flex: 1; }
  #panel { border-left: 0; border-top: .25rem solid var(--navy); height: 47vh; }
  .startCard { flex-direction: column; text-align: center; }
  .startTxt { align-items: center; }
  #startDog { width: 38%; }
  #defList { grid-template-columns: repeat(2, 1fr); }
  #task { width: auto; max-width: 60%; top: 2.5rem; padding: .25rem .5rem; }
  #taskTip { display: none; }
  #bShow { font-size: .9rem; padding: .45rem .8rem; }
}
@media (max-width: 520px) { #hint { white-space: normal; text-overflow: clip; text-align: center; border-radius: .9rem; font-size: .8rem; line-height: 1.2; width: max-content; max-width: 94%; } }
