:root { --paper: #f3ead8; --card: #fbf6ea; --ink: #3b2a20; --mid: #b39b78; --soft: #8a7660; --red: #b5432f; --floor: #eadfc6; }
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--paper); color: var(--ink); font-family: "DotGothic16", monospace; -webkit-tap-highlight-color: transparent; }
/* スマホで連打・2本指による拡大や、長押しの文字選択・メニューが出ないようにする（ゲーム画面だけ） */
html, body { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; }
.app, .room, .me, .shopBtn, .sheet, .modal { touch-action: manipulation; }
.sheetBody { touch-action: pan-y; }
body { display: flex; justify-content: center; overflow: hidden; }
button { font-family: inherit; color: inherit; }
canvas, svg.px { image-rendering: pixelated; shape-rendering: crispEdges; }

.app { width: 100%; max-width: 440px; height: 100dvh; display: grid; grid-template-rows: auto auto auto 1fr auto; grid-template-columns: minmax(0, 1fr); gap: 9px; padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); }
.card { background: var(--card); border: 2px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); position: relative; }
.btn { font-size: 13px; background: var(--card); border: 2px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); padding: 5px 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; line-height: 1.2; }
.btn:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: none; }
.btn:disabled { color: var(--mid); border-color: var(--mid); box-shadow: 2px 2px 0 var(--mid); cursor: default; }
.btn.on { background: var(--ink); color: var(--card); }
.btn.small { font-size: 12px; padding: 3px 8px; }
.btn svg { width: 16px; height: 16px; }

/* 上：バナナの数 */
.hud { display: flex; align-items: center; gap: 10px; padding: 0 2px; }
.hud > svg { width: 32px; height: 32px; flex: none; }
.score { flex: 1; min-width: 0; }
.num { font-size: 30px; line-height: 1; white-space: nowrap; }
.rate { font-size: 12px; color: var(--soft); margin-top: 3px; }

/* 目標の一文 */
.target { display: flex; align-items: center; gap: 8px; padding: 6px 8px; }
.lab { font-size: 12px; color: var(--soft); flex: none; }
.slots { display: flex; flex-wrap: wrap; gap: 2px; }
.slot { width: 18px; height: 22px; border-bottom: 2px solid var(--mid); display: flex; align-items: center; justify-content: center; font-size: 15px; color: transparent; }
.slots.long .slot { width: 15px; height: 20px; font-size: 13px; }
.slot.on { color: var(--ink); border-color: var(--ink); }
.slot.new { animation: fl .6s steps(2) 3; }
.target.final { border-color: var(--red); box-shadow: 3px 3px 0 var(--red); }
.target.final .lab { color: var(--red); }
@keyframes fl { 50% { background: var(--ink); color: var(--card); } }

/* 自分の猿 */
.me { display: grid; grid-template-columns: 160px 1fr; gap: 8px; padding: 6px 8px; cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
#cu { width: 160px; height: 128px; display: block; }
.side { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.who { font-size: 12px; color: var(--soft); }
.line { font-size: 16px; white-space: nowrap; overflow: hidden; display: flex; justify-content: flex-end; margin-top: 4px; min-height: 20px; }
.line i { font-style: normal; color: var(--soft); }
.line i.w2 { color: var(--ink); }
.line i.w { color: var(--card); background: var(--ink); }
.tap { font-size: 12px; color: var(--red); margin-top: 6px; animation: bl 1s steps(1) infinite; }
@keyframes bl { 50% { opacity: 0; } }
.found { font-size: 12px; color: var(--soft); white-space: nowrap; overflow: hidden; margin-top: 6px; border-top: 2px dotted var(--mid); padding-top: 5px; min-height: 22px; }
.found b { font-weight: normal; color: var(--ink); margin-right: 8px; }
.found b.new { background: var(--red); color: var(--card); padding: 0 2px; }

/* 部屋 */
.room { overflow: hidden; min-height: 0; background: var(--floor); }
.room canvas { position: absolute; left: 0; top: 0; }
.rtitle { position: absolute; left: 6px; top: 6px; font-size: 12px; background: var(--card); border: 2px solid var(--ink); padding: 1px 6px; z-index: 3; }
.ov { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 2; }
.bub { position: absolute; transform: translate(-50%, -100%); background: var(--card); border: 2px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); padding: 2px 6px; font-size: 14px; white-space: nowrap; animation: bub 1.8s steps(9) forwards; }
.bub small { font-size: 11px; color: var(--red); margin-left: 4px; }
.bub.new { border-color: var(--red); box-shadow: 2px 2px 0 var(--red); }
@keyframes bub { 0% { opacity: 0; transform: translate(-50%, -70%); } 12% { opacity: 1; transform: translate(-50%, -100%); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -130%); } }
.banner { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); border: 3px solid var(--red); box-shadow: 3px 3px 0 var(--red); color: var(--red); font-size: 22px; padding: 6px 16px; background: var(--card); white-space: nowrap; z-index: 4; animation: ban 2.6s steps(1) forwards; }
@keyframes ban { 0%, 24% { opacity: 1; } 8%, 16% { opacity: 0; } 90% { opacity: 1; } 100% { opacity: 0; } }

/* みせボタン */
.shopBtn { width: 100%; justify-content: center; font-size: 18px; padding: 10px; position: relative; }
.shopBtn .sub { font-size: 12px; color: var(--soft); }
.shopBtn .dot { display: none; width: 10px; height: 10px; background: var(--red); position: absolute; right: 10px; top: 10px; }
.shopBtn.has .dot { display: block; }

/* 下から出る画面 */
.sheet { position: fixed; inset: 0; z-index: 20; display: none; align-items: flex-end; justify-content: center; background: rgba(59, 42, 32, .35); }
.sheet.show { display: flex; }
.sheetBox { width: 100%; max-width: 440px; max-height: 82dvh; display: flex; flex-direction: column; margin: 0 10px calc(10px + env(safe-area-inset-bottom)); animation: up .25s steps(5); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheetHead { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 2px solid var(--ink); }
.sheetHead #sheetTitle { font-size: 18px; }
.sheetBank { flex: 1; text-align: right; font-size: 13px; color: var(--soft); }
.sheetBody { overflow-y: auto; padding: 10px; -webkit-overflow-scrolling: touch; }
.sec { font-size: 12px; color: var(--soft); margin: 14px 0 6px; display: flex; justify-content: space-between; }
.sec:first-child { margin-top: 0; }
.item { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 10px; align-items: center; padding: 8px; border: 2px solid var(--ink); background: var(--paper); margin-bottom: 6px; }
.ic { width: 40px; height: 40px; image-rendering: pixelated; display: block; flex: none; }
.item > .ic { grid-row: 1 / span 2; grid-column: 1; }
.item .nm { font-size: 15px; grid-column: 2; }
.item .nt { font-size: 12px; color: var(--soft); grid-column: 2; line-height: 1.4; }
.item .bt { grid-row: 1 / span 2; grid-column: 3; display: flex; flex-direction: column; gap: 4px; align-items: stretch; }
.item.owned .ic, .item.locked .ic { opacity: .5; }
.outfits { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.outfits .btn { justify-content: flex-start; padding: 4px 8px; flex-wrap: wrap; text-align: left; }
.outfits .btn .ic { width: 32px; height: 32px; }
.outfits .btn small { width: 100%; font-size: 10px; color: var(--mid); }
.words small { font-size: 10px; color: var(--soft); margin-left: 2px; }
.target.book { border-color: var(--soft); }
.target.book .lab { color: var(--red); }
.chal { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; padding: 6px 8px; margin-bottom: 8px; border: 2px dashed var(--red); color: var(--red); font-size: 12px; line-height: 1.5; }
/* 本棚：背表紙の並び */
.shelfBooks { display: grid; gap: 5px; }
.bk { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; padding: 5px 8px 5px 0; border: 2px solid var(--ink); background: var(--paper); }
.bk .sp { align-self: stretch; background: var(--mid); margin: -5px 0; border-right: 2px solid var(--ink); }
.bk.done .sp { background: var(--ink); }
.bk.now { border-color: var(--red); }
.bk.now .sp { background: var(--red); }
.bk .nm { font-size: 14px; }
.bk .nt { font-size: 11px; color: var(--soft); }
.bk .bt .btn { flex-direction: column; gap: 0; }
.bk .bt small { font-size: 10px; color: var(--soft); }
.modalBox .read { text-align: left; font-size: 14px; line-height: 1.9; max-height: 55dvh; overflow-y: auto; margin-top: 12px; padding: 8px; border: 2px solid var(--mid); background: var(--paper); touch-action: pan-y; }
/* セーブの文字列（16px未満だと iPhone で押したときに拡大してしまう） */
textarea { width: 100%; height: 84px; margin: 6px 0; font: 16px/1.4 Consolas, monospace; border: 2px solid var(--ink); background: #fff; color: var(--ink); padding: 6px; resize: vertical; -webkit-user-select: text; user-select: text; word-break: break-all; }
.item.owned { border-color: var(--mid); color: var(--soft); }
.item.locked .nm { color: var(--mid); }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.row3 .btn { flex-direction: column; justify-content: center; padding: 6px 4px; }
.row3 .btn small { font-size: 11px; color: var(--soft); }
.row3 .btn:disabled small { color: var(--mid); }
.menuList { display: grid; gap: 8px; }
.menuList .btn { justify-content: space-between; font-size: 15px; padding: 10px 12px; }
.menuList .btn small { font-size: 12px; color: var(--soft); }
.bar { height: 8px; border: 2px solid var(--ink); background: var(--paper); margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--ink); }
.shelf { padding: 8px; border: 2px solid var(--ink); background: var(--paper); margin-bottom: 6px; cursor: pointer; }
.shelf .top { display: flex; justify-content: space-between; font-size: 14px; }
.shelf .top small { font-size: 12px; color: var(--soft); }
.shelf.done { border-color: var(--red); }
.words { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 14px; padding: 4px 2px 8px; }
.words span.no { color: var(--mid); }
.achs { display: grid; gap: 6px; }
.ach { padding: 6px 8px; border: 2px solid var(--ink); background: var(--paper); }
.ach .nm { font-size: 14px; }
.ach .nt { font-size: 12px; color: var(--soft); }
.ach.no { border-color: var(--mid); }
.ach.no .nm { color: var(--mid); }
.txt { font-size: 13px; line-height: 1.7; }
.txt p + p { margin-top: 8px; }
.big { font-size: 24px; }
.credits li { font-size: 12px; line-height: 1.7; list-style: none; }
.credits a { color: var(--ink); }

/* まんなかのお知らせ */
.modal { position: fixed; inset: 0; z-index: 30; display: none; align-items: center; justify-content: center; background: rgba(59, 42, 32, .35); padding: 24px; }
.modal.show { display: flex; }
.modalBox { width: 100%; max-width: 380px; padding: 22px 18px; text-align: center; }
.modalBox .k { font-size: 14px; color: var(--red); }
.modalBox .t { font-size: 24px; margin: 14px 0 6px; line-height: 1.4; }
.modalBox .o { font-size: 14px; line-height: 1.6; }
.modalBox .s { font-size: 13px; color: var(--soft); margin-top: 6px; }
.modalBox .r { font-size: 18px; margin-top: 14px; }
.modalBox .bts { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }
.modalBox .tri { position: absolute; right: 10px; bottom: 6px; font-size: 12px; animation: bl .6s steps(1) infinite; }

.doneCard { position: fixed; left: 50%; top: 64px; transform: translateX(-50%); width: min(380px, calc(100vw - 32px)); z-index: 35; text-align: center; padding: 12px 14px; pointer-events: none; border-color: var(--red); box-shadow: 3px 3px 0 var(--red); animation: done 3.4s steps(10) forwards; }
.doneCard .k { font-size: 13px; color: var(--red); }
.doneCard .t { font-size: 20px; margin: 6px 0 2px; line-height: 1.4; }
.doneCard .s { font-size: 12px; color: var(--soft); }
.doneCard .r { font-size: 15px; margin-top: 6px; }
@keyframes done { 0% { opacity: 0; transform: translate(-50%, -10px); } 6% { opacity: 1; transform: translate(-50%, 0); } 85% { opacity: 1; } 100% { opacity: 0; } }
.toasts { position: fixed; left: 0; right: 0; top: 10px; z-index: 40; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: var(--card); border: 2px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); padding: 6px 12px; font-size: 13px; animation: toast 3.2s steps(8) forwards; max-width: 90vw; }
.toast small { display: block; font-size: 11px; color: var(--soft); }
@keyframes toast { 0% { opacity: 0; transform: translateY(-10px); } 8% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; } }

.loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--paper); z-index: 50; font-size: 16px; }
.loading.hide { display: none; }
.loading.err { flex-direction: column; gap: 10px; padding: 24px; text-align: center; line-height: 1.7; font-size: 14px; }
