/* GLITCHBORN GARDEN — ステッカー/ボードゲーム風UI
   統一ルール: 紙(--paper)のカード + インク(--ink)の太枠 + 下方向ハードシャドウ。
   押せるものは :active で「押し込み」（translateYしてシャドウを縮める）。 */
:root {
  --ink: #2a2233;
  --paper: rgba(255, 252, 245, .92);
  --paper-solid: #fffcf5;
  --shadow: rgba(42, 34, 51, .3);
  --font: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%; overflow: hidden; background: #7d95d8;
  font-family: var(--font);
  -webkit-user-select: none; user-select: none;
}

canvas#stage { display: block; width: 100%; height: 100%; touch-action: none; }

.hidden { display: none !important; }

button { font-family: var(--font); }

/* ============ UIレイヤー ============ */
#ui {
  position: fixed; inset: 0; pointer-events: none;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

#top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }

/* --- ネームプレート（ステッカー風に少し傾ける） --- */
.brand h1 {
  font-size: clamp(16px, 3vw, 22px); font-weight: 800; letter-spacing: .08em; color: var(--ink);
  background: var(--paper-solid); border: 2.5px solid var(--ink); border-radius: 14px 16px 15px 13px;
  padding: 7px 14px; box-shadow: 0 4px 0 var(--shadow);
  display: inline-block; transform: rotate(-1.2deg);
}
.brand h1 small {
  font-size: 10px; font-weight: 800; margin-left: 8px; padding: 3px 8px; border-radius: 8px;
  background: var(--ink); color: #ffe28a; vertical-align: middle; letter-spacing: .14em;
}
.brand .sub {
  display: block; font-size: 10px; letter-spacing: .26em; font-weight: 800;
  color: #fff; text-shadow: 0 1.5px 0 rgba(42, 34, 51, .45); margin: 8px 0 0 4px;
}

/* --- ステータスカード --- */
#stats { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 48vw; }
.chip {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: var(--paper); backdrop-filter: blur(8px);
  border: 2px solid var(--ink); border-radius: 12px;
  padding: 4px 9px 5px; min-width: 62px;
  box-shadow: 0 3px 0 var(--shadow);
  transition: transform .18s cubic-bezier(.34, 1.56, .64, 1);
}
.chip .lbl { font-size: 8.5px; font-weight: 800; letter-spacing: .1em; color: var(--ink); opacity: .55; }
.chip b { font-size: 13px; font-weight: 800; color: var(--ink); letter-spacing: .03em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.chip em { font-size: 10px; font-style: normal; font-weight: 800; color: #e8503f; }
.chip.bump { transform: translateY(-4px) scale(1.1); }
.chip.warn { background: #ffd9d4; border-color: #b3382a; animation: warnPulse 1.2s infinite; }
.chip.warn .lbl { opacity: .8; color: #b3382a; }
@keyframes warnPulse { 50% { transform: translateY(-2px); box-shadow: 0 5px 0 rgba(179, 56, 42, .4); } }

/* --- ミニボタン（なかま/ずかん/じまん） --- */
.mini-btns { display: flex; gap: 6px; margin: 8px 0 0 2px; }
.mini-btns button {
  pointer-events: auto; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--paper-solid); color: var(--ink); font-weight: 800;
  font-size: 11px; padding: 5px 12px 6px; border-radius: 999px; letter-spacing: .1em;
  border: 2px solid var(--ink); box-shadow: 0 3px 0 var(--shadow);
  transition: transform .12s, box-shadow .12s;
}
.mini-btns button i { font-style: normal; font-size: 13px; }
.mini-btns button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }

#switch-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
#switch-list button {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: #f4eee0; color: var(--ink); text-align: left;
  width: 100%; padding: 11px 14px; font-size: 14px;
}
#switch-list button.current { background: #ffe28a; }
#switch-list button .meta { font-size: 11px; opacity: .65; font-weight: 800; }
#switch-list button.dead { opacity: .55; }
.panel button.ghost-btn {
  background: transparent; border: none; box-shadow: none; color: var(--ink);
  margin-left: 8px; opacity: .65; text-decoration: underline; text-underline-offset: 3px;
}
.panel button.ghost-btn:active { transform: scale(.94); }
#switch-new { margin-bottom: 4px; }

/* ============ ずかん ============ */
#zukan-count { font-size: 12px; opacity: .6; margin-left: 6px; }
#zukan-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  margin-bottom: 14px; max-height: 52vh; overflow-y: auto;
}
.zcard {
  border: 2px solid var(--ink); border-radius: 13px; padding: 9px 4px 7px;
  background: #f4eee0; display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 72px;
}
.zcard .zi { font-size: 27px; line-height: 1.1; }
.zcard .zn { font-size: 9px; font-weight: 800; color: var(--ink); letter-spacing: .02em; }
.zcard .zs { font-size: 8px; font-weight: 800; color: var(--ink); opacity: .5; letter-spacing: .1em; }
.zcard.raised { background: #ffefc2; }
.zcard.met .zi { filter: grayscale(1) brightness(.4); opacity: .75; }
.zcard.unseen { opacity: .75; }
.zcard.unseen .zi { filter: grayscale(1) brightness(.15); opacity: .45; }
.zukan-legend { font-size: 10px !important; opacity: .55 !important; margin-bottom: 12px !important; }
@media (max-width: 640px) { #zukan-grid { grid-template-columns: repeat(3, 1fr); } }

/* ============ 実績 ============ */
.achievements-panel { width: min(480px, 92vw); }
#achievements-count { font-size: 12px; opacity: .6; }
#achievements-list { display: grid; gap: 8px; max-height: 58vh; overflow-y: auto; margin-bottom: 14px; text-align: left; }
.achievement-card { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border: 2px solid var(--ink); border-radius: 13px; background: #f4eee0; }
.achievement-card.unlocked { background: #ffefc2; }
.achievement-card.locked { opacity: .48; filter: grayscale(1); }
.achievement-card i { font-style: normal; font-size: 26px; }
.achievement-card span { display: flex; flex-direction: column; }
.achievement-card b { font-size: 12px; color: var(--ink); }
.achievement-card small { font-size: 9px; line-height: 1.45; color: var(--ink); opacity: .65; }

/* ============ トースト ============ */
#toast {
  position: fixed; top: 26%; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff8ee; font-weight: 800; font-size: 15px;
  padding: 11px 24px; border-radius: 999px; letter-spacing: .06em;
  border: 2.5px solid #fff8ee; box-shadow: 0 4px 0 var(--shadow);
  pointer-events: none;
  animation: toastIn .25s cubic-bezier(.34, 1.56, .64, 1);
  z-index: 60; max-width: 86vw; text-align: center;
}
@keyframes toastIn { from { transform: translateX(-50%) translateY(14px) scale(.8); opacity: 0; } }

/* ============ 下段操作: キャンディボタン ============ */
#bottom { align-self: center; display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
#hint {
  font-size: 10px; font-weight: 700; color: #fff; letter-spacing: .14em; opacity: .9;
  background: rgba(42, 34, 51, .35); padding: 4px 14px; border-radius: 999px;
}
#actions {
  display: flex; gap: 8px; pointer-events: auto;
  background: var(--paper); backdrop-filter: blur(10px);
  border: 2.5px solid var(--ink); border-radius: 22px; padding: 9px;
  box-shadow: 0 5px 0 var(--shadow);
  flex-wrap: wrap; justify-content: center; max-width: 96vw;
}
#actions button {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  min-width: 66px; padding: 7px 8px 9px; cursor: pointer;
  border: 2.5px solid var(--ink); border-radius: 15px;
  box-shadow: 0 4px 0 var(--ink);
  color: var(--ink);
  transition: transform .1s, box-shadow .1s, filter .15s;
}
#actions button i { font-style: normal; font-size: 21px; line-height: 1.1; filter: drop-shadow(0 1px 0 rgba(255,255,255,.6)); }
#actions button span { font-size: 10px; font-weight: 800; letter-spacing: .08em; }
#actions button:hover { filter: brightness(1.05); }
#actions button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
#actions button:disabled { opacity: .4; cursor: default; filter: grayscale(.6); }
.act-feed     { background: #ffdfa6; }
.act-protein  { background: #e3d4ff; }
.act-train    { background: #ffcbc0; }
.act-battle   { background: #ffe28a; }
.act-clean    { background: #c6ecc9; }
.act-lights   { background: #c9dcff; }
.act-medicine { background: #ffd1e0; }

/* ============ オーバーレイ / パネル ============ */
.overlay {
  position: fixed; inset: 0; background: rgba(42, 34, 51, .5); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  padding: 18px;
}
.panel {
  background: var(--paper-solid); border: 3px solid var(--ink);
  border-radius: 24px 28px 22px 26px; padding: 26px 30px; text-align: center;
  box-shadow: 0 8px 0 var(--shadow); min-width: min(320px, 88vw); max-width: 88vw;
  animation: panelIn .3s cubic-bezier(.34, 1.56, .64, 1);
}
@keyframes panelIn { from { transform: translateY(24px) scale(.85); opacity: 0; } }
.panel h3 { color: var(--ink); font-weight: 800; letter-spacing: .12em; margin-bottom: 16px; font-size: 17px; }
.panel p { color: var(--ink); opacity: .75; font-size: 13px; font-weight: 700; margin-bottom: 16px; line-height: 1.7; }
.panel input {
  width: 100%; padding: 11px 14px; border: 2.5px solid var(--ink); border-radius: 14px;
  font-family: var(--font); font-weight: 700; font-size: 15px; margin-bottom: 18px; outline: none; color: var(--ink);
  background: #fff; box-shadow: inset 0 2px 0 rgba(42, 34, 51, .08);
  -webkit-user-select: text; user-select: text;
}
.panel input:focus { border-color: #6a5acd; }
.panel button {
  border: 2.5px solid var(--ink); background: #ffe28a; color: var(--ink);
  border-radius: 15px; padding: 12px 24px;
  font-size: 14px; font-weight: 800; letter-spacing: .1em; cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform .1s, box-shadow .1s;
}
.panel button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

/* ============ タイトル画面 ============ */
#title-overlay { background: rgba(42, 34, 51, .35); }
.title-card {
  background: var(--paper-solid); border: 3px solid var(--ink);
  border-radius: 30px 34px 28px 32px; padding: 34px 38px 26px; text-align: center;
  box-shadow: 0 10px 0 var(--shadow); max-width: min(420px, 90vw);
  animation: panelIn .35s cubic-bezier(.34, 1.56, .64, 1);
}
.title-egg { font-size: 64px; line-height: 1; animation: eggBob 2.2s ease-in-out infinite; }
@keyframes eggBob {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-10px) rotate(4deg); }
}
.title-logo { margin: 14px 0 4px; }
.title-jp {
  display: block; font-size: clamp(26px, 7vw, 34px); font-weight: 800; color: var(--ink);
  letter-spacing: .14em; text-shadow: 2px 2px 0 #ffe28a;
}
.title-en {
  display: inline-block; margin-top: 8px; font-size: 10px; font-weight: 800; letter-spacing: .3em;
  color: #fff8ee; background: var(--ink); padding: 4px 12px 4px 14px; border-radius: 999px;
}
.title-copy { color: var(--ink); opacity: .8; font-size: 13px; font-weight: 700; line-height: 1.8; margin: 16px 0 20px; }
#title-start {
  border: 2.5px solid var(--ink); background: #ffe28a; color: var(--ink);
  border-radius: 17px; padding: 14px 30px; font-size: 16px; font-weight: 800; letter-spacing: .08em;
  cursor: pointer; box-shadow: 0 5px 0 var(--ink);
  transition: transform .1s, box-shadow .1s;
}
#title-start:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.title-note { font-size: 10.5px; font-weight: 700; color: var(--ink); opacity: .5; margin-top: 18px; line-height: 1.7; }

/* ============ トレーニングミニゲーム ============ */
#train-overlay { background: rgba(42, 34, 51, .3); }
#train-overlay .panel { min-width: min(360px, 88vw); }
#train-bar {
  position: relative; height: 30px; background: #efe8d8; border-radius: 999px;
  margin-bottom: 14px; overflow: hidden; border: 2.5px solid var(--ink);
  box-shadow: inset 0 2px 0 rgba(42, 34, 51, .1);
}
#train-target {
  position: absolute; top: 0; bottom: 0; left: 37%; width: 26%;
  background: repeating-linear-gradient(-45deg, #9adf9f, #9adf9f 8px, #8bd490 8px, #8bd490 16px);
  border-left: 2px solid rgba(42, 34, 51, .35); border-right: 2px solid rgba(42, 34, 51, .35);
}
#train-cursor {
  position: absolute; top: -2px; bottom: -2px; width: 9px; left: 0;
  background: #e8503f; border-radius: 4px; box-shadow: 0 0 0 2.5px var(--paper-solid);
}
#train-pips { margin-bottom: 16px; font-size: 22px; font-weight: 800; letter-spacing: .5em; color: var(--ink); }
#train-pips .hit { color: #3aa04a; }
#train-pips .miss { color: #e8503f; }
#train-stop { font-size: 17px !important; padding: 14px 44px !important; background: #ffcbc0 !important; }

/* ============ バトルバナー ============ */
#battle-banner {
  position: fixed; top: 13%; left: 50%; transform: translateX(-50%);
  text-align: center; pointer-events: none; z-index: 20;
}
#battle-vs {
  font-size: clamp(20px, 4.2vw, 36px); font-weight: 800; color: #fff8ee; letter-spacing: .1em;
  white-space: nowrap; max-width: 96vw;
  text-shadow:
    -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 2px 2px 0 var(--ink),
    0 5px 0 var(--ink), 0 0 28px rgba(232, 80, 63, .55);
  transform: rotate(-2deg);
  animation: vsIn .4s cubic-bezier(.34, 1.56, .64, 1);
}
@keyframes vsIn { from { transform: scale(2.4) rotate(-2deg); opacity: 0; } }
#battle-pips { margin-top: 10px; font-size: 22px; letter-spacing: .4em; filter: drop-shadow(0 2px 0 rgba(42, 34, 51, .5)); }
#battle-strategy { margin-top: 8px; padding: 5px 12px; border-radius: 999px; background: var(--paper-solid); border: 2px solid var(--ink); color: var(--ink); font-size: 11px; font-weight: 800; white-space: nowrap; }
.strategy-buttons { display: flex; gap: 9px; margin-bottom: 16px; }
.strategy-buttons button { flex: 1; padding: 12px 8px; font-size: 25px; }
.strategy-buttons button span { display: block; margin-top: 4px; font-size: 11px; }
.strategy-panel p { font-size: 10px; margin-bottom: 8px; }

/* ============ 進化フラッシュ ============ */
#flash {
  position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 90;
  transition: opacity .18s;
}
#flash.on { opacity: 1; transition: opacity .06s; }

/* ============ モバイル ============ */
@media (max-width: 640px) {
  #ui { padding: max(10px, env(safe-area-inset-top)) 10px max(12px, env(safe-area-inset-bottom)); }
  #stats { max-width: 100vw; justify-content: flex-start; gap: 5px; }
  .chip { min-width: 56px; padding: 3px 7px 4px; }
  .chip .lbl { font-size: 8px; }
  .chip b { font-size: 11.5px; }
  #actions { gap: 5px; padding: 7px; border-radius: 19px; }
  #actions button { min-width: 0; flex: 1 1 21%; padding: 6px 4px 8px; }
  #actions button i { font-size: 19px; }
  #actions button span { font-size: 9px; letter-spacing: .04em; }
  .panel { padding: 22px 20px; }
}
