/* Find Neko ・ キャンディタウン: bubblegum pink, mint and lemon with polka dots. */
:root {
  --ink: #5b2a4e; --panel: #fffaf2; --c1: #ff5fa8; --c2: #2ccfb0; --c2l: #fff; --c3: #ffe066;
  --good: #2ccfb0; --bad: #ff6b6b; --frame: repeating-linear-gradient(45deg, #ff5fa8 0 18px, #fff 18px 36px);
  --card1: #ffd6ea; --card2: #c9f6ec; --backdrop: rgb(255 140 190 / .45); --dex-icon: "🍭";
  --bg: radial-gradient(circle, #ffffff 0 5px, transparent 6px) 0 0 / 38px 38px, radial-gradient(circle, #ffd1e8 0 5px, transparent 6px) 19px 19px / 38px 38px, linear-gradient(160deg, #ffe3f1, #fff4c9 60%, #d8fbf2);
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; overflow-x: hidden; color: var(--ink); line-height: 1.5;
  font-family: "Hiragino Maru Gothic ProN", "M PLUS Rounded 1c", "Kosugi Maru", "Arial Rounded MT Bold", "BIZ UDPGothic", "Noto Sans CJK JP", "Noto Sans JP", system-ui, sans-serif;
  background: var(--bg); -webkit-tap-highlight-color: transparent;
}
.decos span { position: fixed; z-index: 0; font-size: clamp(2.4rem, 6vw, 4.5rem); pointer-events: none; animation: float 4s ease-in-out infinite; filter: drop-shadow(0 6px 0 rgb(0 0 0 / .08)); }
.d1 { top: 110px; left: 1.5vw; } .d2 { top: 46%; right: 1.5vw; animation-delay: -1s !important; }
.d3 { bottom: 4vh; left: 2vw; animation-delay: -2s !important; } .d4 { bottom: 10vh; right: 3vw; animation-delay: -3s !important; }
@keyframes float { 50% { transform: translateY(-14px) rotate(8deg); } }

header {
  position: relative; z-index: 2; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 12px auto 0; padding: 10px 14px; max-width: min(1100px, calc(100% - 24px));
  background: var(--panel); border: 3px solid var(--ink); border-radius: 26px; box-shadow: 0 6px 0 var(--ink);
}
h1 { margin: 0 auto 0 0; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; font-size: 1.6rem; font-weight: 900; letter-spacing: .02em; }
h1 > span:not(.icon) { color: var(--c1); }
h1 .icon { display: inline-block; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-5px) rotate(-10deg); } }
.controls { display: flex; align-items: center; gap: 10px; }
.pill {
  padding: 8px 14px; border-radius: 999px; font-weight: 900; white-space: nowrap; font-variant-numeric: tabular-nums;
  background: var(--c3); border: 3px solid var(--ink);
}
.pill::before { content: "🏆 "; }

button {
  font: inherit; font-size: 1.1rem; font-weight: 900; cursor: pointer; color: var(--ink);
  padding: 9px 22px; border-radius: 999px; border: 3px solid var(--ink); background: var(--c2l, #fff);
  box-shadow: 0 5px 0 var(--ink); transition: transform .12s, box-shadow .12s, filter .2s;
}
button:hover { transform: translateY(-2px); box-shadow: 0 7px 0 var(--ink); filter: brightness(1.05); }
button:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
button:focus-visible { outline: 4px solid var(--c1); outline-offset: 3px; }
button.primary { color: #fff; background: var(--c1); text-shadow: 0 2px 0 rgb(0 0 0 / .2); }

main { position: relative; z-index: 1; padding: 14px 12px 28px; display: flex; flex-direction: column; align-items: center; }
#status {
  margin: 0 0 14px; padding: 6px 20px; min-height: 2.4em; border-radius: 999px; font-weight: 900; font-size: 1.1rem; text-align: center;
  background: var(--panel); border: 3px solid var(--ink);
}
#status.good { color: #fff; background: var(--good); animation: boing .5s; }
#status.bad { color: #fff; background: var(--bad); animation: wobble .4s; }
@keyframes boing { 30% { transform: scale(1.15); } 60% { transform: scale(.95); } }
@keyframes wobble { 25% { transform: rotate(-4deg); } 75% { transform: rotate(4deg); } }

#frame { padding: 10px; border-radius: 30px; background: var(--frame); border: 3px solid var(--ink); box-shadow: 0 8px 0 var(--ink); max-width: 100%; }
#stage { position: relative; line-height: 0; border-radius: 20px; overflow: hidden; border: 3px solid var(--ink); background: #ffe3f1; }
/* The canvas keeps its own aspect ratio; hit-testing scales by its on-screen box. */
canvas { display: block; max-width: 100%; max-height: calc(100vh - 210px); cursor: pointer; transition: opacity .25s; }
canvas.fade { opacity: 0; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px) rotate(-1deg); } 40%, 80% { transform: translateX(8px) rotate(1deg); } }
.ripple {
  position: absolute; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%; pointer-events: none;
  border: 5px dashed var(--bad); background: rgb(255 255 255 / .35); animation: ripple .7s ease-out forwards;
}
.ripple::after { content: var(--miss-mark, "✖"); position: absolute; inset: 0; display: grid; place-items: center; font-size: 22px; line-height: 1; color: var(--bad); }
@keyframes ripple { from { transform: scale(.3) rotate(-30deg); } 40% { opacity: 1; } to { transform: scale(1.4) rotate(20deg); opacity: 0; } }

#toast {
  position: absolute; top: 14px; left: 50%; display: flex; align-items: center; gap: 12px; line-height: 1.3; white-space: nowrap; cursor: pointer;
  padding: 8px 22px 8px 8px; border-radius: 26px; font-size: 1.25rem; font-weight: 900;
  background: var(--panel); border: 4px solid var(--ink); box-shadow: 0 6px 0 var(--ink); transform: translateX(-50%);
  animation: popin .5s cubic-bezier(.3, 1.6, .5, 1);
}
#toast[hidden] { display: none; }
#toast img { height: 64px; padding: 6px; border-radius: 18px; background: var(--c3); border: 3px solid var(--ink); animation: bob 1.2s ease-in-out infinite; }
@keyframes popin { from { opacity: 0; transform: translateX(-50%) scale(.3) rotate(-8deg); } }

dialog {
  width: min(92vw, 540px); padding: 24px; text-align: center; color: var(--ink);
  background: var(--panel); border: 4px solid var(--ink); border-radius: 32px; box-shadow: 0 10px 0 var(--ink);
}
dialog[open] { animation: popd .45s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes popd { from { opacity: 0; transform: scale(.6); } }
dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(3px); }
h2 { margin: 0; font-size: 1.8rem; font-weight: 900; color: var(--c1); }
h2::before { content: var(--dex-icon, "📕") " "; }
#dex-count { margin: 4px 0 10px; font-size: 1.15rem; font-weight: 900; }
.meter { height: 18px; margin: 0 auto 20px; max-width: 260px; border-radius: 999px; background: #fff; border: 3px solid var(--ink); overflow: hidden; }
.meter i { display: block; height: 100%; background: repeating-linear-gradient(-45deg, var(--c1) 0 10px, var(--c2) 10px 20px); transition: width .6s; }
.cats { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; margin-bottom: 22px; }
.cats figure { margin: 0; width: 140px; padding: 16px 8px 10px; border-radius: 24px; border: 3px solid var(--ink); background: var(--card1); box-shadow: 0 5px 0 var(--ink); transform: rotate(-3deg); }
.cats figure:nth-child(even) { background: var(--card2); transform: rotate(3deg); }
.cats figure:hover { transform: rotate(0) scale(1.06); transition: transform .2s; }
.cats img { height: 100px; max-width: 100%; object-fit: contain; }
.cats figcaption { margin-top: 6px; font-weight: 900; font-size: 1.1rem; }
.unknown { border-style: dashed !important; background: #fff !important; }
.unknown img { filter: brightness(0) opacity(.25); }
.unknown figcaption { opacity: .55; letter-spacing: .2em; }

@media (max-width: 640px) {
  header { gap: 10px; border-radius: 22px; }
  h1 { font-size: 1.3rem; }
  .controls { width: 100%; }
  .controls button { flex: 1; padding: 9px 10px; }
  #status { font-size: .95rem; }
  canvas { max-height: none; }
  #toast { font-size: 1rem; top: 8px; }
  #toast img { height: 46px; }
  .decos span { opacity: .6; }
  .d1, .d2 { display: none; }
}
/* Phones and tablets held upright: ask to turn sideways. Mouse-driven desktop windows never see this. */
#rotate { display: none; }
/* game.js adds .tall only when a touch device's viewport is taller than it is wide. */
.tall #rotate {

    position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
    padding: 24px; text-align: center; background: var(--bg);
  }
.tall #rotate p { margin: 28px 0 0; padding: 10px 22px; font-size: clamp(1.1rem, 6.2vw, 1.6rem); white-space: nowrap; font-weight: 900; color: #fff; background: var(--c1); border: 4px solid var(--ink); border-radius: 999px; box-shadow: 0 6px 0 var(--ink); }
.tall #rotate small { font-size: 1.05rem; font-weight: 800; }
.tall .phone {
    display: grid; place-items: center; width: 92px; height: 150px; font-size: 2.6rem; border-radius: 22px;
    background: var(--panel); border: 6px solid var(--ink); box-shadow: 0 8px 0 var(--ink); animation: turn 2.4s ease-in-out infinite;
  }
.tall body { overflow: hidden; }
@keyframes turn { 0%, 20% { transform: rotate(0); } 50%, 80% { transform: rotate(-90deg); } }

/* Phones on their side: buttons move to a slim column on the left so the picture can use the full height. */
@media (orientation: landscape) and (max-height: 500px) {
  /* --app-h is the real visible height from game.js (Android/iOS toolbars); dvh and vh are fallbacks. */
  html, body { overflow: hidden; overscroll-behavior: none; }
  body {
    display: flex; gap: 8px; min-height: 0; height: 100vh; height: 100dvh; height: var(--app-h, 100dvh);
    padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }
  header {
    flex: none; flex-direction: column; flex-wrap: nowrap; justify-content: flex-start; gap: 8px; width: 144px;
    margin: 0; padding: 10px 8px; border-radius: 20px; box-shadow: 0 4px 0 var(--ink);
  }
  h1 { margin: 0; font-size: 1.1rem; }
  .controls { flex-direction: column; width: 100%; gap: 8px; }
  .controls button, .pill { width: 100%; padding: 6px 4px; font-size: .9rem; text-align: center; }
  .pill { font-size: .8rem; }
  .controls button { min-height: 42px; }
  #status {
    position: fixed; left: calc(14px + env(safe-area-inset-left)); bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 3; width: 128px; margin: 0;
    padding: 4px 8px; min-height: 0; border-radius: 14px; font-size: .75rem; line-height: 1.35;
  }
  main { flex: 1; min-width: 0; padding: 0; justify-content: center; z-index: auto; }
  #frame { padding: 4px; border-radius: 20px; box-shadow: 0 4px 0 var(--ink); }
  #stage { border-radius: 14px; }
  /* Largest 16:9 box that fits: 44px = body padding + frame + borders + shadow; 190px = side column + gaps + frame. */
  canvas {
    width: auto; height: auto;
    max-height: calc(100vh - 44px); max-height: calc(100dvh - 44px);
    max-height: calc(var(--app-h, 100dvh) - 44px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    max-width: calc(100vw - 190px - env(safe-area-inset-left) - env(safe-area-inset-right));
  }
  #toast { top: 8px; font-size: 1rem; }
  #toast img { height: 44px; }
  .decos { display: none; }
  dialog { max-height: calc(100dvh - 16px); overflow-y: auto; padding-top: 12px; padding-bottom: 12px; }
  dialog h2 { margin: 0; font-size: 1.3rem; }
  #dex-count { margin: 2px 0 6px; }
  .meter { margin-bottom: 10px; }
  .cats { margin-bottom: 12px; }
  .cats figure { width: 112px; padding: 8px 6px 6px; }
  .cats img { height: 64px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

button.primary { background: linear-gradient(180deg, #ff86bf, #ff4f9e); }
#dex-btn { background: #c9f6ec; }
