* { box-sizing: border-box; }
html { touch-action: manipulation; }   /* no double-tap zoom anywhere */
#app, #app * { touch-action: none; }   /* no panning or pinching on the play area */
.panel { touch-action: pan-y; }
button:focus, .cell:focus { outline: none; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #23170f; color: #fff;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
button, .button {
  font: inherit; font-weight: 700; color: #fff; background: #5a3d22; border: 0; border-radius: 12px;
  padding: 12px 18px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
button.primary { background: #ffcf33; color: #3b2717; }
button.big { font-size: 22px; padding: 16px 48px; }
.small { font-size: 13px; opacity: 0.85; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; }
#stage { position: relative; flex: 1 1 auto; min-height: 0; touch-action: none; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#hud { position: absolute; top: 14px; left: 10px; right: 10px; display: flex; align-items: flex-start; justify-content: space-between; pointer-events: none; text-shadow: 0 2px 0 #000; }
#score { font-size: 30px; font-weight: 900; font-variant-numeric: tabular-nums; }
#time { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 70px; text-align: right; padding-top: 6px; }
#time small { font-size: 11px; margin-left: 1px; }
#lives { display: flex; gap: 4px; padding-top: 8px; min-width: 70px; }
#lives i { width: 20px; height: 11px; border-radius: 11px 11px 2px 2px; background: #ffd21f; box-shadow: 0 2px 0 #000; }
#lives i.lost { background: #5a3d22; }
#pause-btn { position: absolute; right: 8px; bottom: 8px; padding: 6px 10px; font-size: 12px; background: rgba(0,0,0,0.35); }

#banner {
  position: absolute; left: 0; right: 0; top: 40%; text-align: center; font-size: 24px; font-weight: 900;
  color: #ffcf33; text-shadow: 0 3px 0 #000, 0 0 12px #000; pointer-events: none; animation: pop 1.6s ease-out forwards;
}
@keyframes pop { 0% { transform: scale(1.6); opacity: 0; } 15% { transform: scale(1); opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }

.hint { position: absolute; pointer-events: none; margin: 0; text-align: center; font-weight: 700; color: #fff; background: rgba(0,0,0,0.6); border-radius: 10px; padding: 6px 12px; line-height: 1.4; }
#hint-top { left: 50%; top: 58px; transform: translateX(-50%); white-space: nowrap; }
#hint-top b { color: #ffcf33; }

#bar { display: flex; align-items: center; gap: 12px; padding: 6px 12px; font-size: 12px; font-weight: 700; background: #2e1f14; }
#air { flex: 1; display: flex; align-items: center; gap: 6px; }
#air .gauge { flex: 1; height: 10px; border-radius: 5px; background: #140d08; overflow: hidden; }
#air i { display: block; height: 100%; width: 100%; background: #6bd0ff; transform-origin: left; }
#air.low i { background: #ff6b6b; animation: blink 0.4s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.35; } }
#dum { display: flex; align-items: center; gap: 6px; }
#dum b { display: flex; gap: 3px; }
#dum b i { width: 12px; height: 14px; border-radius: 6px 6px 3px 3px; background: #b98c5f; }
#dum b i.empty { background: #5a3d22; }
#dum b i.fill { background: linear-gradient(to top, #b98c5f var(--p), #5a3d22 var(--p)); }
#dum.flash { animation: blink 0.15s steps(2) 3; }

#pad {
  position: relative; flex: 0 0 auto; height: min(42dvh, 96vw, 400px); display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: #3b2717; touch-action: none;
}
.cell { position: relative; padding: 0; border-radius: 16px; background: #2f8a4c; box-shadow: inset 0 -4px 0 rgba(0,0,0,0.25); touch-action: none; }
.cell::before { content: ""; position: absolute; left: 22%; right: 22%; top: 30%; bottom: 22%; border-radius: 50%; background: #140c08; }
.cell::after { content: ""; position: absolute; left: 30%; right: 30%; top: 16%; bottom: 36%; border-radius: 50% 50% 20% 20%; background: #7a4a2a; opacity: 0; transition: opacity 0.05s; }
.cell.me { box-shadow: inset 0 0 0 3px #ffd21f, inset 0 -4px 0 rgba(0,0,0,0.25); }
.cell.out::after { opacity: 1; border-top: 6px solid #ffd21f; }
.cell.dum::after { opacity: 1; background: #b98c5f; border-top: 0; }
.cell.worm { box-shadow: inset 0 0 0 3px #ff8fb0, inset 0 -4px 0 rgba(0,0,0,0.25);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 14'%3E%3Cpath d='M3 9c4-6 7 4 11-1s7 4 11-1 7 3 11-2' fill='none' stroke='%238a3048' stroke-width='6' stroke-linecap='round'/%3E%3Cpath d='M3 9c4-6 7 4 11-1s7 4 11-1 7 3 11-2' fill='none' stroke='%23ff8fb0' stroke-width='4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-size: 46% auto; background-position: 50% 92%; }
.cell.koban { box-shadow: inset 0 0 0 3px #ffd21f, inset 0 -4px 0 rgba(0,0,0,0.25);
  background-image: radial-gradient(ellipse 13% 9% at 50% 88%, #ffe36b 0 70%, #b88a00 75% 100%, transparent 100%); }
.cell.me.koban { box-shadow: inset 0 0 0 3px #ffd21f, inset 0 0 0 6px #fff3a0, inset 0 -4px 0 rgba(0,0,0,0.25); }
.cell.me.worm { box-shadow: inset 0 0 0 3px #ffd21f, inset 0 0 0 6px #ff8fb0, inset 0 -4px 0 rgba(0,0,0,0.25); }
.cell:active { filter: brightness(1.15); }
#hint-pad { left: 50%; top: 50%; transform: translate(-50%, -50%); white-space: nowrap; }

.panel { position: fixed; inset: 0; background: rgba(22,13,7,0.94); overflow-y: auto; z-index: 10; display: flex; }
.panel[hidden] { display: none; }
.box { margin: auto; width: min(420px, 100%); padding: 24px 18px; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.box p { margin: 0; }
.big { font-size: 22px; font-weight: 900; }
#title { background: rgba(22,13,7,0.55); }
#title h1 { margin: 0; font-size: 44px; font-weight: 900; color: #ffcf33; letter-spacing: 2px; text-shadow: 0 4px 0 #7a2a10; }
#title .sub { font-weight: 700; margin-bottom: 14px; }
.title-name { font-size: 28px; font-weight: 900; color: #ffcf33; }
.new { font-size: 12px; font-weight: 700; background: #ff6b6b; border-radius: 6px; padding: 2px 8px; }
.score { font-size: 34px; font-weight: 900; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; width: 100%; }
.row > * { flex: 1; }
.box > button { width: 100%; }
.button.x { background: #000; border: 1px solid #555; }
.button.x svg { width: 16px; height: 16px; }

.board { width: 100%; display: flex; flex-direction: column; gap: 6px; background: #2e1f14; border-radius: 14px; padding: 10px; }
.board:empty { display: none; }
.board .head { display: flex; justify-content: space-between; align-items: baseline; font-weight: 800; }
.board .head span { font-size: 12px; font-weight: 700; opacity: 0.7; }
.board form { display: flex; gap: 6px; }
.board input { flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 10px; border-radius: 10px; border: 0; }
.board form button { padding: 10px 16px; }
.board .msg { font-size: 13px; color: #ffb3b3; }
.board ol { list-style: none; margin: 0; padding: 0; max-height: 34dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; text-align: left; }
.rk { font-weight: 700; }
.rk b { color: #ffcf33; font-size: 20px; }
.mode { font-size: 12px; font-weight: 800; letter-spacing: 1px; background: #5a3d22; border-radius: 6px; padding: 2px 10px; }
.tabs { display: flex; gap: 6px; width: 100%; }
.tabs button { flex: 1; padding: 8px; font-size: 14px; }
.tabs button.on { background: #ffcf33; color: #3b2717; }
#time.end { color: #ff6b6b; }
#time .lbl { font-size: 10px; display: block; opacity: 0.8; }

#z-list, #rk-list { list-style: none; margin: 0; padding: 0; width: 100%; text-align: left; display: flex; flex-direction: column; gap: 6px; }
#z-list li { background: #2e1f14; border-radius: 10px; padding: 8px 12px; }
#z-list li b { display: block; color: #ffcf33; }
#z-list li.locked b { color: #776; }
#z-list li span { font-size: 12px; opacity: 0.85; }
.rows li { display: flex; gap: 10px; background: #2e1f14; border-radius: 8px; padding: 6px 10px; font-variant-numeric: tabular-nums; }
.rows li.mine { outline: 2px solid #ffcf33; }
.rows .no { width: 26px; text-align: right; opacity: 0.7; }
.rows .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .sc { font-weight: 700; }
.rows .tm { opacity: 0.7; font-size: 12px; align-self: center; }
.board .rows li { background: #23170f; padding: 5px 10px; }

#r-head { font-size: 15px; font-weight: 800; opacity: 0.85; }
.title-line { font-size: 14px; }
.title-line b { font-size: 22px; color: #ffcf33; }
.rows li.gap { background: none; justify-content: center; padding: 0; opacity: 0.6; }
.links { display: flex; gap: 18px; justify-content: center; }
button.link { background: none; padding: 4px; font-size: 13px; font-weight: 700; color: rgba(255,255,255,0.75); text-decoration: underline; }
