:root {
  --ink: #3a2d5c; --soft: #7d6f9e; --accent: #ff5c8a; --accent-dark: #e23f70; --sun: #ffd23f;
  --panel: #ffffffee; --line: #e7dcff;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  color: var(--ink);
  background: #2b1f5c;
}
* { box-sizing: border-box; }
html, body, #app { width: 100%; height: 100%; margin: 0; overflow: hidden; touch-action: manipulation; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#app { position: relative; background: radial-gradient(120% 90% at 50% 20%, #5b3fb0 0%, #3a2780 45%, #22175a 100%); }
button { font: inherit; cursor: pointer; border: 0; color: inherit; touch-action: manipulation; }
button:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; }
[hidden] { display: none !important; }

#stars { position: absolute; inset: 0; pointer-events: none; }
#stars i { position: absolute; width: 3px; height: 3px; border-radius: 50%; background: #fff; opacity: .7; animation: tw 3s ease-in-out infinite; }
@keyframes tw { 50% { opacity: .15; } }

header { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 16px; right: 12px; display: flex;
  justify-content: space-between; align-items: center; z-index: 10; pointer-events: none; }
.brand { font-weight: 900; font-size: 18px; letter-spacing: 2px; color: #fff; text-shadow: 0 2px 0 #0003; }
.brand span { color: var(--sun); }
.tools { display: flex; gap: 8px; pointer-events: auto; }
.tools button { background: #ffffffd8; border-radius: 50px; height: 36px; min-width: 44px;
  padding: 0 14px; font-size: 12px; font-weight: bold; box-shadow: 0 3px 0 #0002; }

/* ───── 遊ぶ画面：縦長は上に星・下に操作、横長は左に星・右に操作 ───── */
#play { position: absolute; inset: 0; display: flex; flex-direction: column; padding-top: calc(max(10px, env(safe-area-inset-top)) + 40px); }
#stage { position: relative; flex: 1 1 auto; min-height: 120px; }
#planet { position: absolute; inset: 0; width: 100%; height: 100%; }
#panel { flex: none; padding: 8px 12px max(12px, env(safe-area-inset-bottom)); width: 100%; max-width: 560px; margin: 0 auto; }
@media (min-aspect-ratio: 5/4) {
  #play { flex-direction: row; padding-top: calc(max(10px, env(safe-area-inset-top)) + 36px); }
  #stage { flex: 1 1 auto; }
  #panel { width: min(46vw, 470px); max-width: none; margin: 0; display: flex; flex-direction: column; justify-content: center;
    padding: 8px max(14px, env(safe-area-inset-right)) 12px 6px; }
}

#status { display: flex; align-items: center; gap: 12px; background: var(--panel); border-radius: 16px; padding: 6px 12px; box-shadow: 0 4px 0 #0002; }
.day { display: flex; align-items: baseline; gap: 3px; white-space: nowrap; }
.day small { font-size: 10px; font-weight: bold; color: var(--soft); }
.day b { font-size: 24px; font-weight: 900; color: var(--accent); min-width: 1.4em; text-align: right; }
.meters { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; }
.meter { display: flex; align-items: center; gap: 5px; font-size: 11px; font-weight: bold; }
.meter i { flex: 1; height: 8px; border-radius: 8px; background: #eee7fb; overflow: hidden; position: relative; }
.meter b { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 8px; transition: width .35s cubic-bezier(.3,1.6,.5,1), background .35s; }
.m-water b { background: #3fa9f5; } .m-life b { background: #4cc75a; } .m-civ b { background: #ff8fc7; }
.m-heat b { background: linear-gradient(90deg, #7fd3ff, #ffd23f 55%, #ff6b4a); }

#trail { display: flex; gap: 4px; justify-content: center; min-height: 26px; margin: 8px 0 2px; flex-wrap: nowrap; overflow: hidden; }
#trail span { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; flex: none; box-shadow: 0 2px 0 #0003; animation: popin .3s cubic-bezier(.3,1.8,.5,1); }
#trail span svg { width: 15px; height: 15px; }
#trail span.old { opacity: .45; transform: scale(.82); }
#hint { margin: 4px 2px 8px; min-height: 2.6em; font-size: 13px; line-height: 1.35; color: #fff; text-align: center; font-weight: bold; text-shadow: 0 1px 0 #0004; }
#hint em { font-style: normal; color: var(--sun); }

#pad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.el { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: clamp(54px, 9.5vh, 76px); border-radius: 18px; color: #fff; font-weight: 900; font-size: 13px; letter-spacing: 1px;
  box-shadow: 0 5px 0 #0003, inset 0 -4px 0 #0002; text-shadow: 0 1px 0 #0003; transition: transform .08s; }
.el svg { width: 30px; height: 30px; filter: drop-shadow(0 1px 0 #0003); }
.el:active, .el.hit { transform: translateY(3px) scale(.95); box-shadow: 0 2px 0 #0003, inset 0 -4px 0 #0002; }
.el.bounce { animation: bounce .35s cubic-bezier(.3,1.8,.5,1); }
.el .key { position: absolute; top: 4px; left: 8px; font-size: 9px; opacity: .65; }
.el.maybe::after { content: ""; position: absolute; top: 5px; right: 6px; width: 10px; height: 10px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 8px 3px #fff9; animation: sparkle 1.1s ease-in-out infinite; }
#pad.locked .el { filter: saturate(.5) brightness(.9); pointer-events: none; }
@keyframes bounce { 0% { transform: scale(.85); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes popin { 0% { transform: scale(0); } 100% { transform: scale(1); } }
@keyframes sparkle { 50% { transform: scale(.5); opacity: .4; } }

#pop { position: absolute; left: 50%; top: 2%; transform: translate(-50%, 0); pointer-events: none; text-align: center; z-index: 3; width: 92%; }
#pop div { display: inline-block; background: #fff; color: var(--ink); border-radius: 999px; padding: 8px 18px; font-weight: 900; font-size: 18px;
  box-shadow: 0 5px 0 #0003; animation: toast 2.2s cubic-bezier(.3,1.6,.5,1) forwards; margin: 2px; }
#pop div.bad { background: #3a2d5c; color: #ffd0d0; }
#pop div small { display: block; font-size: 11px; color: var(--soft); font-weight: bold; }
@keyframes toast { 0% { transform: scale(.3) translateY(20px); opacity: 0; } 14% { transform: scale(1.12); opacity: 1; } 22% { transform: scale(1); }
  80% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-24px); } }

/* ───── 重ねる画面 ───── */
.overlay { position: absolute; inset: 0; z-index: 20; overflow-y: auto; display: flex; padding: 56px 16px 20px; }
#title { background: radial-gradient(100% 80% at 50% 30%, #5b3fb0, #22175a); }
.intro { margin: auto; max-width: 440px; width: 100%; text-align: center; color: #fff; }
.eyebrow { font-size: 11px; letter-spacing: 2px; font-weight: bold; color: #c8b8ff; }
h1 { font-size: clamp(42px, 11vw, 64px); line-height: 1.1; letter-spacing: 3px; margin: 10px 0 14px; font-weight: 900; text-shadow: 0 4px 0 #0004; }
h1 span { color: var(--sun); }
.rules { font-size: 13px; line-height: 1.7; margin: 0 0 18px; background: #ffffff18; border-radius: 16px; padding: 10px 14px; }
.rules p { margin: 3px 0; }
.rules b { color: var(--sun); }
.primary { display: block; margin: 0 auto; background: var(--accent); color: #fff; min-width: 220px; padding: 15px 24px; border-radius: 999px; font-weight: 900;
  font-size: 17px; letter-spacing: 4px; box-shadow: 0 6px 0 var(--accent-dark); }
.primary:hover { filter: brightness(1.05); }
.primary:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--accent-dark); }
.text-button { background: none; color: inherit; font-size: 13px; font-weight: bold; padding: 10px 14px; text-decoration: underline; text-underline-offset: 3px; }
.intro .text-button { margin-top: 6px; }
.instructions { font-size: 11px; line-height: 1.7; margin-top: 8px; color: #d8ccff; }
.instructions p { margin: 2px 0; }
.instructions b { margin-right: 6px; color: #fff; }
.best { font-size: 12px; letter-spacing: 2px; margin-top: 10px; font-weight: bold; }
.back { display: inline-block; margin-top: 8px; padding-block: .35rem; font-size: 12px; color: #d8ccff; }

.shade { background: #1d1450c8; }
.box { margin: auto; background: #fff; border-radius: 24px; padding: 20px 20px 16px; width: 100%; max-width: 400px; text-align: center; box-shadow: 0 8px 0 #0003; }
.box.wide { max-width: 640px; }
.box h2 { margin: 6px 0 10px; font-size: 22px; font-weight: 900; }
.box .eyebrow { color: var(--soft); }
.box .row { display: flex; justify-content: center; gap: 6px; }
#result-img { display: block; width: 168px; height: 168px; margin: 6px auto 0; object-fit: contain; }
#result-desc { font-size: 13px; line-height: 1.6; margin: 0 0 8px; color: var(--soft); }
.new { display: inline-block; background: var(--sun); color: var(--ink); font-weight: 900; border-radius: 999px; padding: 2px 12px; font-size: 12px; margin-bottom: 6px; animation: bounce .5s; }
.stats { display: flex; justify-content: center; gap: 12px; margin: 4px 0; }
.stats div { background: #f5f0ff; border-radius: 14px; padding: 6px 16px; min-width: 110px; }
.stats small { display: block; font-size: 10px; font-weight: bold; color: var(--soft); }
.stats b { font-size: 24px; font-weight: 900; color: var(--accent); }
#result-recipes { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; margin: 8px 0 14px; }
#result-recipes span { font-size: 11px; font-weight: bold; background: #f5f0ff; border-radius: 999px; padding: 3px 10px; }

.tabs { display: flex; justify-content: center; gap: 6px; margin-bottom: 10px; }
.tab { background: #f1ebff; border-radius: 999px; padding: 8px 16px; font-size: 13px; font-weight: bold; color: var(--soft); }
.tab.on { background: var(--ink); color: #fff; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px; margin-bottom: 14px; text-align: left; }
.card { border-radius: 14px; padding: 8px 10px; background: #f5f0ff; font-size: 11px; line-height: 1.5; color: var(--soft); min-height: 74px; }
.card b { display: block; font-size: 13px; color: var(--ink); }
.card.got { background: linear-gradient(135deg, #fff4c8, #ffe0ee); }
.card.locked b { color: #b6a9d6; }
.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px; margin-bottom: 14px; text-align: left; }
.recipe { display: flex; align-items: center; gap: 8px; background: #f5f0ff; border-radius: 12px; padding: 6px 10px; font-size: 12px; }
.recipe .seq { display: flex; gap: 3px; flex: none; }
.recipe .seq span { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 900; }
.recipe .seq span svg { width: 14px; height: 14px; }
.recipe .seq span.q { background: #d9cff3; }
.recipe b { font-size: 13px; }
.recipe small { display: block; color: var(--soft); font-size: 10px; }
.recipe.got { background: #fff6dc; }

/* 背の低い横長（スマホ横・PCの高さ600前後） */
@media (max-height: 520px) {
  .el { height: clamp(44px, 13vh, 60px); font-size: 11px; border-radius: 14px; }
  .el svg { width: 22px; height: 22px; }
  #hint { min-height: 2.4em; font-size: 12px; margin: 2px 2px 6px; }
  #trail { margin: 5px 0 0; }
  h1 { font-size: 38px; margin: 4px 0 8px; }
  .rules { font-size: 12px; margin-bottom: 10px; }
  .overlay { padding-top: 46px; }
  #result-img { width: 110px; height: 110px; }
}
