@font-face { font-family: "KomaFont"; src: url("img/koma.woff2") format("woff2"); font-weight: 700; font-display: block; }
:root {
  --ink: #2b1a10; --cream: #fbf1dc; --paper: #fffaf0; --wood: #e7bf6e; --wood2: #b7833d; --walnut: #5a3418; --indigo: #2a2f5a; --indigo2: #1c2042;
  --red: #b8321f; --green: #3f8f4a; --gold: #e9b949;
  --jp: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo, "Noto Sans JP", "Noto Sans CJK JP", system-ui, sans-serif;
  --min: "KomaFont", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body { background: #3a2616; color: var(--ink); font-family: var(--jp); user-select: none; -webkit-user-select: none; touch-action: none; }
.hidden { display: none !important; }
#bg { position: fixed; inset: 0; background: url(img/bg.webp) center/cover no-repeat; }
#bg::after { content: ""; position: absolute; inset: 0; background: linear-gradient(rgba(40,24,12,.30), rgba(40,24,12,.55)); }
button { font-family: var(--jp); }

#top { position: fixed; top: 0; left: 0; right: 0; height: 48px; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 0 10px; padding-top: env(safe-area-inset-top);
  background: linear-gradient(var(--indigo), var(--indigo2)); color: var(--cream); border-bottom: 3px solid var(--gold); box-shadow: 0 2px 10px rgba(0,0,0,.35); }
.logo { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.logo .k { font: 700 25px/1 var(--min); color: #fff; letter-spacing: .04em; }
.logo .s { font-size: 12px; color: var(--gold); font-weight: 700; border: 1.5px solid var(--gold); border-radius: 6px; padding: 1px 5px; }
#status { flex: 1; min-width: 0; text-align: center; font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#status.alert { color: #ffd2c4; }
.hbtns { display: flex; gap: 6px; }
.ib { width: 38px; height: 38px; border-radius: 50%; border: 2px solid rgba(233,185,73,.7); background: rgba(255,255,255,.08); color: var(--gold); cursor: pointer; display: grid; place-items: center; padding: 0; }
.ib svg { width: 20px; height: 20px; }
.ib.off { opacity: .55; }

#main { position: fixed; top: 48px; left: 0; right: 0; bottom: 0; display: flex; gap: 10px; padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
#stage { position: relative; flex: 1; min-width: 0; min-height: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: pointer; }
#side { width: 300px; flex: none; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
#ponBox { display: flex; align-items: center; gap: 8px; background: rgba(255,250,240,.94); border-radius: 16px; padding: 6px 10px 6px 6px; box-shadow: 0 3px 12px rgba(0,0,0,.25); border: 2px solid #e8cf9c; }
#pon { width: 92px; height: 92px; flex: none; transition: transform .2s; }
#pon.bump { transform: scale(1.08) rotate(-3deg); }
#bubble { font-weight: 700; font-size: 14.5px; line-height: 1.45; color: var(--ink); }
#hint1 { margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--cream); background: rgba(30,18,8,.55); border-radius: 10px; padding: 6px 9px; }
#tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tool { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 54px; border-radius: 12px; border: 2px solid #d8b878; background: var(--paper);
  color: var(--walnut); font-weight: 800; font-size: 12.5px; cursor: pointer; box-shadow: 0 3px 0 #b8935a; padding: 0; }
.tool svg { width: 21px; height: 21px; }
.tool:active { transform: translateY(2px); box-shadow: 0 1px 0 #b8935a; }
.tool:disabled { opacity: .45; cursor: default; }
.tool.primary { background: var(--red); color: #fff; border-color: #8e2414; box-shadow: 0 3px 0 #74200f; }
.chk { display: flex; align-items: center; gap: 8px; color: var(--cream); font-weight: 700; font-size: 13.5px; cursor: pointer; }
.chk input { width: 20px; height: 20px; accent-color: var(--red); }
#kifuBox { flex: 1; min-height: 60px; display: flex; flex-direction: column; background: rgba(255,250,240,.94); border-radius: 14px; border: 2px solid #e8cf9c; overflow: hidden; }
#kifuBox h3 { margin: 0; padding: 6px 10px; font-size: 14px; background: #f1dfb6; color: var(--walnut); display: flex; justify-content: space-between; align-items: baseline; }
#kifuBox small { font-weight: 600; color: #8a6a3a; }
#kifu { list-style: none; margin: 0; padding: 4px 6px 8px; overflow-y: auto; flex: 1; display: grid; grid-template-columns: 1fr 1fr; align-content: start; column-gap: 6px; font-size: 14px; }
#kifu li { padding: 2px 4px; border-radius: 6px; white-space: nowrap; font-family: var(--jp); }
#kifu li b { display: inline-block; min-width: 24px; color: #9b7b4a; font-weight: 600; font-size: 11.5px; }
#kifu li.last { background: #ffe3a3; }

.dlg { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(20,12,6,.45); z-index: 4; }
.card { background: var(--paper); border-radius: 20px; padding: 18px 22px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.45); border: 3px solid var(--gold); max-width: min(92%, 380px); }
.card h2 { margin: 4px 0 10px; font-size: 24px; color: var(--walnut); }
.card p { margin: 6px 0; font-size: 15px; line-height: 1.5; }
.row { display: flex; gap: 10px; justify-content: center; margin-top: 10px; }
.pbtn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 10px 10px; border-radius: 14px; border: 2px solid #d8b878; background: #fff7e6; cursor: pointer; font-weight: 800; font-size: 16px; color: var(--walnut); }
.pbtn canvas { width: 72px; height: 72px; }
#prYes { border-color: var(--red); }
.btn { border: 0; border-radius: 999px; background: var(--red); color: #fff; font-weight: 800; font-size: 16px; padding: 11px 22px; cursor: pointer; box-shadow: 0 4px 0 #74200f; }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #74200f; }
.btn.ghost { background: #fff3da; color: var(--walnut); box-shadow: 0 4px 0 #c9a56a; border: 2px solid #d8b878; }
.btn.small { font-size: 14px; padding: 8px 14px; }
.btn.big { font-size: 22px; padding: 14px 46px; letter-spacing: .1em; }
#endPon { width: 120px; height: 120px; }
#banner { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); z-index: 3; pointer-events: none; font: 700 64px/1 var(--min); color: #fff; padding: 14px 34px;
  background: rgba(184,50,31,.92); border: 4px solid var(--gold); border-radius: 18px; box-shadow: 0 8px 30px rgba(0,0,0,.45); animation: pop .9s ease both; white-space: nowrap; }
@keyframes pop { 0% { transform: translate(-50%,-50%) scale(.4); opacity: 0 } 20% { transform: translate(-50%,-50%) scale(1.08); opacity: 1 } 75% { transform: translate(-50%,-50%) scale(1); opacity: 1 } 100% { transform: translate(-50%,-50%) scale(1); opacity: 0 } }

.overlay { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(28,20,40,.55); padding: 12px; overflow-y: auto; }
.panel { position: relative; width: min(520px, 100%); background: var(--paper); border-radius: 22px; border: 3px solid var(--gold); box-shadow: 0 14px 50px rgba(0,0,0,.5); padding: 16px 20px 16px; text-align: center; }
.spon { width: 96px; height: 96px; position: absolute; left: 10px; top: 6px; }
.panel h1 { margin: 0 0 4px; display: flex; flex-direction: column; align-items: center; }
.panel h1 .k { font: 700 56px/1.05 var(--min); color: var(--walnut); letter-spacing: .08em; }
.panel h1 small { font-size: 14px; font-weight: 800; color: var(--red); }
.intro { font-size: 14px; line-height: 1.6; margin: 6px 0 10px; color: #4a3220; }
.optrow { display: flex; align-items: center; gap: 8px; margin: 7px 0; justify-content: center; }
.lab { font-weight: 800; color: var(--walnut); font-size: 14px; width: 40px; text-align: right; flex: none; }
.seg { display: flex; background: #f1dfb6; border-radius: 12px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 8px 11px; border-radius: 9px; font-weight: 800; font-size: 14px; color: #7a5a2e; cursor: pointer; }
.seg button.on { background: var(--indigo); color: #fff; box-shadow: 0 2px 0 #12152e; }
.panel .chk { color: var(--walnut); justify-content: center; margin: 8px 0 12px; }
#play { display: block; margin: 4px auto 10px; }
.keys { margin: 10px 0 0; font-size: 12px; color: #7a5a2e; line-height: 2; }
.kb { display: inline-block; border: 1.5px solid #c9a56a; border-bottom-width: 3px; border-radius: 6px; padding: 0 6px; margin: 0 2px; background: #fff; font-weight: 700; color: var(--walnut); line-height: 1.5; }

.tutp { width: min(560px, 100%); text-align: left; }
.tutp .x { position: absolute; right: 10px; top: 8px; width: 36px; height: 36px; border-radius: 50%; border: 2px solid #d8b878; background: #fff3da; font-size: 22px; line-height: 1; cursor: pointer; color: var(--walnut); }
#tutPage h2 { margin: 2px 40px 8px 0; font-size: 21px; color: var(--walnut); }
#tutPage p { margin: 6px 0; font-size: 14.5px; line-height: 1.65; }
#tutPage ul { margin: 6px 0; padding-left: 20px; font-size: 14px; line-height: 1.6; }
#tutPage .diag { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin: 6px 0; }
#tutPage figure { margin: 0; text-align: center; font-weight: 800; color: var(--walnut); font-size: 13.5px; }
#tutPage canvas { width: 170px; height: 170px; display: block; }
.tutnav { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
#tutNum { font-weight: 700; color: #8a6a3a; }

/* portrait / phone */
@media (max-aspect-ratio: 1/1), (max-width: 760px) and (min-height: 561px) {
  #main { flex-direction: column; gap: 6px; padding: 4px 4px max(6px, env(safe-area-inset-bottom)); }
  #stage { flex: none; height: var(--stageH, 60vh); }
  #side { width: auto; flex: 1; gap: 5px; }
  #ponBox { padding: 3px 8px 3px 3px; border-radius: 12px; }
  #pon { width: 64px; height: 64px; }
  #bubble { font-size: 14px; line-height: 1.4; }
  #hint1 { display: none; }
  #tools { grid-template-columns: repeat(6, 1fr); gap: 4px; }
  .tool { height: 50px; font-size: 11px; border-radius: 10px; }
  .tool svg { width: 18px; height: 18px; }
  #begWrap { font-size: 12.5px; }
  #kifuBox h3 { padding: 3px 10px; font-size: 13px; }
  #kifu { grid-template-columns: 1fr 1fr 1fr; font-size: 13px; }
  .logo .k { font-size: 22px; }
  #status { font-size: 13.5px; }
  .panel { padding: 12px 14px; }
  .panel h1 .k { font-size: 46px; }
  .spon { width: 70px; height: 70px; }
  .seg button { padding: 8px 9px; font-size: 13.5px; }
  #tutPage canvas { width: 140px; height: 140px; }
  #banner { font-size: 44px; }
}
@media (max-height: 560px) and (min-aspect-ratio: 1/1) {
  #pon { width: 60px; height: 60px; }
  #hint1 { display: none; }
  .tool { height: 44px; }
}

/* embed fit: small store frame (794x447, 640x360) */
.overlay .panel { max-height: calc(100vh - 16px); overflow-y: auto; }
.tutp { display: flex; flex-direction: column; }
.tutp #tutPage { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.tutnav { flex: none; }
.card { max-height: calc(100% - 8px); overflow-y: auto; }
@media (max-height: 560px) and (min-aspect-ratio: 1/1) {
  .overlay { padding: 8px; }
  .panel { padding: 10px 16px 12px; }
  .spon { width: 64px; height: 64px; left: 8px; top: 6px; }
  .panel h1 .k { font-size: 40px; }
  .intro { font-size: 13px; line-height: 1.45; margin: 4px 0 6px; }
  .optrow { margin: 4px 0; }
  .seg button { padding: 6px 10px; font-size: 13.5px; }
  .panel .chk { margin: 4px 0 8px; }
  #play, #howStart { display: inline-block; vertical-align: middle; margin: 2px 4px 4px; }
  .btn.big { font-size: 20px; padding: 11px 34px; }
  #start .keys { display: none; }
  #endPon { width: 72px; height: 72px; }
  .card { padding: 12px 18px; }
  .card h2 { margin: 2px 0 6px; font-size: 21px; }
  .card p { font-size: 14px; margin: 4px 0; }
  .row { margin-top: 6px; }
  .pbtn canvas { width: 60px; height: 60px; }
  #tutPage h2 { font-size: 19px; margin-bottom: 4px; }
  #tutPage p, #tutPage ul { font-size: 13.5px; line-height: 1.5; }
  #tutPage canvas { width: 130px; height: 130px; }
  .tutnav { margin-top: 6px; }
  #banner { font-size: 48px; }
}
@media (max-height: 560px) and (min-aspect-ratio: 1/1) and (max-width: 760px) {
  #main { gap: 8px; }
  #side { width: 214px; gap: 6px; }
  #pon { width: 48px; height: 48px; }
  #bubble { font-size: 12.5px; line-height: 1.35; }
  #ponBox { padding: 4px 8px 4px 4px; }
  .tool { height: 42px; font-size: 11px; }
  .tool svg { width: 18px; height: 18px; }
  #begWrap { font-size: 12px; }
}
@media (max-height: 420px) and (min-aspect-ratio: 1/1) {
  #top { height: 40px; }
  .logo .k { font-size: 21px; }
  .ib { width: 32px; height: 32px; }
  .ib svg { width: 17px; height: 17px; }
  #status { font-size: 13.5px; }
  #main { top: 40px; padding: 6px; }
  #side { gap: 5px; }
  #ponBox { border-radius: 12px; }
  #pon { width: 42px; height: 42px; }
  #bubble { font-size: 12px; }
  #tools { gap: 4px; }
  .tool { height: 38px; font-size: 10.5px; border-radius: 10px; }
  .tool svg { width: 16px; height: 16px; }
  #kifuBox h3 { padding: 3px 8px; font-size: 12.5px; }
  #kifu { font-size: 12.5px; }
  .overlay { padding: 6px; }
  .panel { padding: 8px 14px 10px; border-radius: 16px; }
  .spon { width: 48px; height: 48px; }
  .panel h1 .k { font-size: 32px; }
  .panel h1 small { font-size: 12.5px; }
  .intro { font-size: 12px; line-height: 1.4; margin: 2px 0 4px; }
  .optrow { margin: 3px 0; }
  .lab { font-size: 13px; }
  .seg { padding: 2px; }
  .seg button { padding: 5px 9px; font-size: 13px; }
  .panel .chk { margin: 2px 0 6px; font-size: 12.5px; }
  .chk input { width: 17px; height: 17px; }
  .btn.big { font-size: 18px; padding: 9px 28px; }
  .btn { font-size: 15px; padding: 9px 18px; }
  #endPon { width: 52px; height: 52px; }
  .card { padding: 10px 14px; border-radius: 16px; }
  .card h2 { font-size: 19px; margin: 0 0 4px; }
  .card p { font-size: 13px; line-height: 1.4; margin: 2px 0; }
  .pbtn canvas { width: 50px; height: 50px; }
  .pbtn { font-size: 14px; padding: 6px 8px 8px; }
  #tutPage canvas { width: 110px; height: 110px; }
  #banner { font-size: 40px; padding: 10px 26px; }
}
