:root {
  --ink: #3b2414;
  --paper: #fff8ea;
  --red: #d63a2a;
  --yellow: #ffd23f;
  --shadow: rgba(59, 36, 20, .35);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  background: #f4dcb4; color: var(--ink);
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "PingFang TC", system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; touch-action: none;
}
#game, #game canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* HUD */
#hud {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  pointer-events: none;
}
/* touch vs keyboard instructions (class set on <html> by main.js) */
.touch-only { display: none; }
html.touch .touch-only { display: list-item; }
html.touch .kb-only { display: none; }
.gest { display: inline-block; min-width: 44px; font-size: 15px; }

/* first-run swipe tutorial */
#swipeHint { position: fixed; left: 50%; bottom: calc(6% + env(safe-area-inset-bottom)); transform: translateX(-50%);
  pointer-events: none; text-align: center; animation: hintIn .3s ease-out; }
#swipeHint[hidden] { display: none; }
.sh-row { display: flex; align-items: center; justify-content: center; gap: 18px; font-size: 40px;
  filter: drop-shadow(0 3px 0 var(--shadow)); }
.sh-arrow { font-family: "Dela Gothic One", sans-serif; color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; }
.sh-hand { display: inline-block; animation: swipe 1.2s ease-in-out infinite; }
.sh-text { margin-top: 6px; background: var(--paper); border: 3px solid var(--ink); border-radius: 999px;
  padding: 4px 16px; font-weight: 800; font-size: 15px; white-space: nowrap; }
@keyframes swipe { 0%, 100% { transform: translateX(-26px); } 50% { transform: translateX(26px); } }
@keyframes hintIn { from { opacity: 0; transform: translate(-50%, 12px); } }
.hud-left { display: flex; flex-direction: column; gap: 6px; }
.hearts { font-size: 26px; letter-spacing: 2px; filter: drop-shadow(0 2px 0 var(--shadow)); }
.hearts .off { filter: grayscale(1) opacity(.35); }
.rice { font: 800 22px "M PLUS Rounded 1c", sans-serif; background: var(--paper); border: 3px solid var(--ink);
  border-radius: 999px; padding: 2px 14px 2px 8px; display: inline-flex; gap: 6px; align-items: center;
  box-shadow: 0 3px 0 var(--shadow); width: max-content; }
.dist { font-family: "Dela Gothic One", sans-serif; font-size: 44px; color: #fff;
  -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 4px 0 var(--shadow); line-height: 1; }
.dist small { font-size: 22px; margin-left: 4px; }
.hud-right { display: flex; gap: 8px; pointer-events: auto; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 3px solid var(--ink); background: var(--paper);
  color: var(--ink); font: 800 18px "M PLUS Rounded 1c", sans-serif; cursor: pointer; box-shadow: 0 3px 0 var(--shadow); }
.icon-btn.muted { opacity: .45; text-decoration: line-through; }

/* screens */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(255,240,210,.25), rgba(80,40,10,.45)); }
.screen[hidden], #hud[hidden] { display: none; }
.card { background: var(--paper); border: 4px solid var(--ink); border-radius: 22px; padding: 24px 28px;
  max-width: 420px; width: 100%; text-align: center; box-shadow: 0 8px 0 var(--shadow);
  max-height: calc(100dvh - 32px); overflow-y: auto; }
.logo { font-family: "Dela Gothic One", sans-serif; font-size: 56px; line-height: 1.05; color: var(--yellow);
  -webkit-text-stroke: 5px var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--red); margin-bottom: 4px; }
.logo.small { font-size: 36px; -webkit-text-stroke-width: 4px; text-shadow: 0 4px 0 var(--red); }
.sub { display: inline-block; background: var(--red); color: #fff; font-weight: 800; padding: 4px 14px; border-radius: 6px;
  transform: rotate(-2deg); margin: 6px 0 14px; letter-spacing: .1em; }
.pets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 14px; }
.pet { background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 6px 4px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; box-shadow: 0 3px 0 var(--shadow);
  font: 800 13px "M PLUS Rounded 1c", sans-serif; color: var(--ink); transition: transform .1s; }
.pet img { width: 76px; height: 76px; object-fit: cover; image-rendering: auto; margin: -6px 0 -8px; }
.pet.on { background: var(--yellow); transform: translateY(-3px); box-shadow: 0 6px 0 var(--ink); }
.name-row { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font-weight: 800; font-size: 13px; }
.name-row span { white-space: nowrap; }
.name-row input { flex: 1; min-width: 0; font: 800 16px "M PLUS Rounded 1c", sans-serif; color: var(--ink);
  background: #fff; border: 3px solid var(--ink); border-radius: 10px; padding: 6px 10px; outline: none; }
.name-row input:focus { background: #fffbe6; box-shadow: 0 0 0 3px var(--yellow); }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.sub-btn { flex: 1; font: 800 15px "M PLUS Rounded 1c", sans-serif; color: var(--ink); background: #fff;
  border: 3px solid var(--ink); border-radius: 12px; padding: 8px 6px; cursor: pointer; box-shadow: 0 3px 0 var(--ink); }
.sub-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.sub-btn.wide { width: 100%; margin-top: 8px; }
.rank-line { font-weight: 800; color: var(--red); min-height: 1.4em; margin: -4px 0 10px; }
.tabs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin: 10px 0; }
.pop-chars { margin-top: 10px; padding-top: 8px; border-top: 3px solid var(--ink); text-align: left; }
.pop-title { font-weight: 800; font-size: 13px; margin-bottom: 4px; }
.pop-row { display: grid; grid-template-columns: 26px 64px 1fr 42px; align-items: center; gap: 6px; margin: 3px 0;
  font-weight: 800; font-size: 13px; }
.pop-row img { width: 26px; height: 26px; object-fit: cover; }
.pop-bar { height: 12px; background: #efe6d2; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; }
.pop-bar i { display: block; height: 100%; background: var(--yellow); }
.pop-row:first-child .pop-bar i { background: var(--red); }
.pop-row .pct { text-align: right; font-family: "Dela Gothic One", sans-serif; }
.pop-empty { font-size: 12px; opacity: .6; }
.tab { font: 800 14px "M PLUS Rounded 1c", sans-serif; color: var(--ink); background: #fff; border: 3px solid var(--ink);
  border-radius: 10px; padding: 6px 0; cursor: pointer; }
.tab.on { background: var(--yellow); }
.rank-list { list-style: none; margin: 0; padding: 0; text-align: left; min-height: 120px; max-height: 40dvh; overflow-y: auto; }
.rank-list li { display: grid; grid-template-columns: 34px 32px 1fr auto; align-items: center; gap: 6px;
  padding: 5px 6px; border-bottom: 2px dashed rgba(59, 36, 20, .2); font-weight: 800; }
.rank-list li.me { background: #fff1b8; border-radius: 8px; }
.rank-list li.empty { display: block; text-align: center; opacity: .6; border: 0; padding: 24px 0; }
.rank-list .no { font-family: "Dela Gothic One", sans-serif; text-align: center; font-size: 16px; }
.rank-list .no.g1 { color: #d4a514; } .rank-list .no.g2 { color: #8c96a0; } .rank-list .no.g3 { color: #b8743a; }
.rank-list img { width: 32px; height: 32px; object-fit: cover; }
.rank-list .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-list .val { font-family: "Dela Gothic One", sans-serif; font-size: 15px; }
.howto { list-style: none; padding: 0; margin: 0 0 16px; text-align: left; font-weight: 500; line-height: 1.9; font-size: 15px; }
.howto .touch { opacity: .7; font-size: 13px; }
kbd { display: inline-block; min-width: 24px; padding: 0 6px; border: 2px solid var(--ink); border-bottom-width: 4px;
  border-radius: 6px; background: #fff; font: 800 12px/18px "M PLUS Rounded 1c", sans-serif; text-align: center; margin-right: 2px; }
.big-btn { font-family: "Dela Gothic One", sans-serif; font-size: 24px; color: #fff; background: var(--red);
  border: 4px solid var(--ink); border-radius: 16px; padding: 10px 36px; cursor: pointer; box-shadow: 0 6px 0 var(--ink);
  transition: transform .08s; }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.hint { font-size: 12px; opacity: .6; margin: 10px 0 0; }
.bar { height: 16px; border: 3px solid var(--ink); border-radius: 999px; overflow: hidden; background: #fff; margin: 16px 0 8px; }
#loadbar { height: 100%; width: 0; background: var(--yellow); transition: width .2s; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.stats div { background: #fff; border: 2px solid var(--ink); border-radius: 10px; padding: 6px; display: flex; flex-direction: column; }
.stats span { font-size: 12px; opacity: .7; }
.stats b { font-family: "Dela Gothic One", sans-serif; font-size: 22px; }
.stats .total { background: var(--yellow); }
.new-best { color: var(--red); font-weight: 800; margin-bottom: 10px; animation: pulse .6s infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); } }

/* comic pops */
#pops { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.pop { position: absolute; transform: translate(-50%, -50%); font-family: "Dela Gothic One", sans-serif; font-size: 48px;
  color: #fff; -webkit-text-stroke: 5px var(--ink); paint-order: stroke fill; white-space: nowrap;
  animation: pop .9s ease-out forwards; }
.pop.red { color: var(--red); }
.pop.yellow { color: var(--yellow); }
.pop.small { font-size: 26px; -webkit-text-stroke-width: 3px; animation-duration: .6s; }
@keyframes pop {
  0% { transform: translate(-50%, -50%) scale(.2) rotate(-12deg); opacity: 1; }
  25% { transform: translate(-50%, -60%) scale(1.25) rotate(-6deg); }
  70% { opacity: 1; }
  100% { transform: translate(-50%, -110%) scale(1) rotate(-4deg); opacity: 0; }
}
.flash { position: fixed; inset: 0; background: #fff; pointer-events: none; animation: flash .25s ease-out forwards; }
@keyframes flash { from { opacity: .7; } to { opacity: 0; } }
.credit { position: fixed; right: 10px; bottom: 6px; font-size: 11px; opacity: .55; pointer-events: none; }

.rotate-hint { display: none; background: var(--yellow); border: 2px solid var(--ink); border-radius: 10px;
  padding: 6px 10px; font-weight: 800; font-size: 13px; margin: 0 0 14px; }
@media (orientation: portrait) and (max-width: 600px) { .rotate-hint { display: block; } }
@media (max-width: 600px) {
  .card { padding: 18px 16px; border-radius: 18px; }
  .logo { font-size: 42px; -webkit-text-stroke-width: 4px; }
  .logo.small { font-size: 30px; }
  .sub { margin: 4px 0 10px; }
  .howto { font-size: 14px; line-height: 1.75; margin-bottom: 12px; }
  .big-btn { width: 100%; padding: 12px 0; font-size: 26px; }
  .dist { font-size: 34px; }
  .hearts { font-size: 22px; }
  .rice { font-size: 18px; }
  .credit { font-size: 9px; bottom: max(4px, env(safe-area-inset-bottom)); }
}
@media (max-height: 640px) {
  .logo { font-size: 34px; }
  .pet img { width: 56px; height: 56px; }
  .howto { line-height: 1.55; }
}
/* phones held sideways: keep the start button on screen without scrolling */
@media (max-height: 460px) {
  .screen { padding: 8px; }
  .card { padding: 10px 14px; max-width: 560px; }
  .logo { font-size: 26px; -webkit-text-stroke-width: 3px; text-shadow: 0 3px 0 var(--red); }
  .logo br { display: none; }
  .logo.small { font-size: 24px; }
  .sub { margin: 2px 0 6px; font-size: 12px; padding: 2px 10px; }
  .pets { gap: 6px; margin-bottom: 8px; }
  .pet { flex-direction: row; justify-content: center; padding: 2px 4px; }
  .pet img { width: 36px; height: 36px; margin: 0; }
  .name-row { margin-bottom: 6px; }
  .name-row input { padding: 3px 8px; }
  .howto { display: none; }
  .big-btn { padding: 6px 0; font-size: 20px; }
  .btn-row { margin-top: 6px; }
  .sub-btn { padding: 5px 6px; font-size: 13px; }
  .stats { margin: 6px 0; gap: 6px; }
  .stats div { padding: 2px 6px; }
  .stats b { font-size: 18px; }
  .tabs { margin: 6px 0; }
  .rank-list { max-height: 44dvh; min-height: 80px; }
  .rank-list li { padding: 2px 6px; }
}
