:root {
  --ink: #5b3a2e;
  --bg1: #bfe6f5;
  --bg2: #fff4dc;
  --card: #fffdf8;
  --accent: #ff7a8a;
  --accent2: #4fb7a6;
  --c: #fff8ea;
  --v: #e9f7df;
  --f: #e1f1fb;
  --d: #fdeef3;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "M PLUS Rounded 1c", system-ui, sans-serif;
  font-weight: 500;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg1), var(--bg2)) fixed;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.screen { max-width: 520px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); min-height: 100%; }

/* ---------- タイトル ---------- */
#title { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding-top: 28px; }
.fridgeLogo { width: 150px; height: 170px; border: 5px solid var(--ink); border-radius: 26px; background: #fff; position: relative; box-shadow: 0 8px 0 rgba(91,58,46,.15); overflow: hidden; }
.fridgeLogo::before { content: ""; position: absolute; left: 0; right: 0; top: 56px; border-top: 5px solid var(--ink); }
.fridgeLogo::after { content: ""; position: absolute; right: 14px; top: 18px; width: 8px; height: 24px; border-radius: 4px; background: var(--ink); box-shadow: 0 60px 0 var(--ink); }
.logoFoods { position: absolute; inset: 66px 26px 8px 10px; display: flex; flex-wrap: wrap; gap: 2px; align-content: flex-start; justify-content: center; }
.logoFoods svg { animation: bob 2.4s ease-in-out infinite; }
.logoFoods svg:nth-child(2n) { animation-delay: -1.2s; }
@keyframes bob { 50% { transform: translateY(-4px); } }
h1 { font-family: "Mochiy Pop One", sans-serif; font-weight: 400; font-size: 34px; margin: 6px 0 0; line-height: 1.15; letter-spacing: .02em; }
h1 span { display: block; color: var(--accent); font-size: 40px; }
.tag { margin: 0; font-weight: 800; }
.name { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.name input { width: 170px; padding: 10px 12px; border: 3px solid var(--ink); border-radius: 14px; background: #fff; }
.btns { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 320px; }
.btn { padding: 14px 16px; border: 3px solid var(--ink); border-radius: 18px; background: #fff; font-weight: 800; font-size: 17px; cursor: pointer; box-shadow: 0 5px 0 var(--ink); transition: transform .06s, box-shadow .06s; }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn.main { background: var(--accent); color: #fff; }
.hint { font-size: 13px; line-height: 1.7; margin: 4px 0 0; }
.back { font-size: 13px; margin: 0; }
.back a { color: var(--ink); }

/* ---------- 共通の上の帯 ---------- */
.bar { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px; text-align: center; margin-bottom: 8px; }
.iconBtn { width: 44px; height: 44px; border: 3px solid var(--ink); border-radius: 14px; background: #fff; font-size: 20px; font-weight: 800; cursor: pointer; }
.stageTitle { display: flex; flex-direction: column; line-height: 1.2; }
.stageTitle small { font-size: 12px; }

/* ---------- ステージ選択 ---------- */
.stageList { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stageBtn { aspect-ratio: 1; border: 3px solid var(--ink); border-radius: 16px; background: #fff; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px; }
.stageBtn b { font-size: 22px; font-family: "Mochiy Pop One", sans-serif; font-weight: 400; }
.stageBtn small { font-size: 11px; }
.stageBtn.done { background: #fff0c4; }
.stageBtn:disabled { opacity: .4; cursor: default; }

/* ---------- あそぶ ---------- */
.timerRow { display: flex; justify-content: center; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.timer { font-family: "Mochiy Pop One", sans-serif; font-size: 22px; min-width: 4em; text-align: center; }
.taInfo { font-size: 13px; font-weight: 800; }
.fridge { margin: 0 auto; width: fit-content; padding: 10px; border: 5px solid var(--ink); border-radius: 22px; background: #fff; box-shadow: 0 8px 0 rgba(91,58,46,.15); }
.board { position: relative; touch-action: none; }
.cell { position: absolute; border: 1.5px dashed rgba(91,58,46,.18); }
.cell.zc { background: var(--c); } .cell.zv { background: var(--v); } .cell.zf { background: var(--f); } .cell.zd { background: var(--d); }
.cell.eR { border-right: 3px solid var(--ink); } .cell.eB { border-bottom: 3px solid var(--ink); }
.cell.blocked { background: #efe6dc; display: flex; align-items: center; justify-content: center; }
.zoneLabel { position: absolute; font-size: 10px; font-weight: 800; padding: 1px 5px; border-radius: 8px; background: rgba(255,255,255,.85); pointer-events: none; z-index: 1; white-space: nowrap; }
.hl { position: absolute; border-radius: 10px; pointer-events: none; z-index: 3; }
.hl.ok { background: rgba(79,183,166,.35); outline: 3px solid var(--accent2); }
.hl.ng { background: rgba(255,90,90,.3); outline: 3px solid #f05a5a; }
.piece { position: absolute; touch-action: none; cursor: grab; z-index: 2; line-height: 0; transition: left .12s, top .12s; }
.piece svg, .trayPiece svg, .ghost svg { display: block; filter: drop-shadow(0 2px 0 rgba(91,58,46,.25)); pointer-events: none; }
.piece.lifted, .trayPiece.lifted { opacity: .25; }
.piece.pop { animation: pop .22s ease-out; }
@keyframes pop { 40% { transform: scale(1.08); } }
.msg { min-height: 1.6em; text-align: center; font-weight: 800; margin: 8px 0 4px; }
.msg.warn { color: #e0474c; }
.tray { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; padding: 10px; min-height: 80px; border: 3px dashed rgba(91,58,46,.35); border-radius: 18px; background: rgba(255,255,255,.55); }
.tray:empty::after { content: "ぜんぶ入れた！"; font-weight: 800; opacity: .6; }
.trayPiece { touch-action: none; cursor: grab; line-height: 0; padding: 2px; }
.ghost { position: fixed; left: 0; top: 0; z-index: 50; pointer-events: none; line-height: 0; filter: drop-shadow(0 8px 10px rgba(0,0,0,.18)); }
.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ---------- クリア ---------- */
.overlay { position: fixed; inset: 0; background: rgba(91,58,46,.35); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 60; }
.card { background: var(--card); border: 5px solid var(--ink); border-radius: 26px; padding: 24px 20px; width: min(340px, 100%); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; animation: pop .3s; }
.clearHead { font-family: "Mochiy Pop One", sans-serif; font-size: 28px; color: var(--accent); margin: 0; }
.clearTime { font-family: "Mochiy Pop One", sans-serif; font-size: 34px; margin: 0; }
.clearNote { margin: 0 0 8px; font-weight: 800; line-height: 1.6; }

/* ---------- ランキング ---------- */
.rankPick { display: flex; align-items: center; gap: 8px; font-weight: 800; margin: 4px 0 12px; }
.rankPick select { flex: 1; padding: 10px; border: 3px solid var(--ink); border-radius: 14px; background: #fff; }
.rankList { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.rankList li { display: grid; grid-template-columns: 2.4em 1fr auto; align-items: center; gap: 8px; padding: 10px 12px; background: #fff; border: 3px solid var(--ink); border-radius: 14px; font-weight: 800; }
.rankList li.me { background: #fff0c4; }
.rankList .no { font-family: "Mochiy Pop One", sans-serif; text-align: center; }
.rankList .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rankList .empty { display: block; text-align: center; }
.rankMe { text-align: center; font-weight: 800; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
