/* ==========================================================
 * Bio Lab（apps/biolab） style.css
 * ========================================================== */
:root {
    --green: #047857;
    --green-dark: #065f46;
    --green-soft: #d1fae5;
    --ground: #f0fdf4;
    --text: #1e293b;
    --sub: #64748b;
    --yellow: #facc15;
    --font: 'M PLUS Rounded 1c', 'Gowun Dodum', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'BIZ UDPGothic', 'Meiryo', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
}
body {
    font-family: var(--font);
    color: var(--text);
    background: #1e293b;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
button { font-family: var(--font); }

/* UI要塞化 */
.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    z-index: -1 !important;
    position: absolute !important;
}

#app {
    position: relative;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ---------- 上の帯 ---------- */
#topbar {
    position: relative;
    flex: 0 0 auto;
    min-height: 68px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px 8px calc(140px + env(safe-area-inset-left, 0px));
    padding-right: calc(12px + env(safe-area-inset-right, 0px));
    background: var(--green-dark);
    color: #fff;
    z-index: 20;
}
.bar-title { margin: 0; font-size: 1.25rem; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1 1 auto; min-width: 0; }
.bar-sub { font-size: 0.9rem; opacity: 0.85; margin-left: 4px; }
.bar-right { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.bar-btn {
    min-height: 48px;
    padding: 6px 14px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 800;
    cursor: pointer;
    white-space: nowrap;
}
.bar-btn:active { transform: translateY(2px); }
.speed-box {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 30px;
    padding: 4px 12px;
    font-weight: 800;
    font-size: 0.9rem;
    min-height: 48px;
}
.speed-box input { width: clamp(90px, 12vw, 150px); height: 32px; accent-color: var(--yellow); }
.speed-box b { min-width: 2.2em; text-align: right; }

/* ---------- 里山 ---------- */
#world-wrap {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    background: var(--ground);
    overflow: hidden;
}
#world {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
    cursor: crosshair;
}
.panel {
    position: absolute;
    background: rgba(255, 255, 255, 0.94);
    border: 2px solid #e2e8f0;
    border-radius: 18px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.14);
    z-index: 10;
}
.mission-box {
    top: 10px;
    left: calc(10px + env(safe-area-inset-left, 0px));
    width: min(330px, 40vw);
    padding: 10px 12px;
    border-left: 8px solid var(--yellow);
}
.mission-head { font-size: 0.85rem; font-weight: 800; color: var(--sub); }
.mission-goal { font-size: 1.05rem; font-weight: 800; color: var(--green-dark); line-height: 1.45; margin: 2px 0 6px; }
.keep-bar { position: relative; height: 12px; border-radius: 6px; background: #e2e8f0; overflow: hidden; margin-bottom: 4px; }
.keep-fill { height: 100%; width: 0; background: linear-gradient(90deg, #34d399, #facc15); transition: width 0.2s linear; }
.keep-text { font-size: 0.85rem; font-weight: 800; color: #b45309; margin-bottom: 4px; }
.hint-btn {
    min-height: 44px;
    width: 100%;
    border: none;
    border-radius: 22px;
    background: var(--yellow);
    color: #713f12;
    font-weight: 800;
    font-size: 0.95rem;
    cursor: pointer;
    box-shadow: 0 3px 0 #ca8a04;
}
.hint-btn:active { transform: translateY(2px); box-shadow: none; }

.count-box {
    top: 10px;
    right: calc(10px + env(safe-area-inset-right, 0px));
    width: 240px;
    padding: 8px 10px;
    pointer-events: none;
}
.count-title { text-align: center; font-size: 0.8rem; font-weight: 800; color: var(--sub); }
.count-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; font-weight: 800; font-size: 0.92rem; }
.count-grid div { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px solid #f1f5f9; }
.count-grid b { font-size: 1.25rem; color: var(--green); font-variant-numeric: tabular-nums; }
.count-detail { display: flex; justify-content: space-between; font-size: 0.82rem; font-weight: 700; color: var(--sub); margin-top: 4px; }
.count-detail b { color: var(--text); font-variant-numeric: tabular-nums; }

.toolbar {
    left: 50%;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    width: min(940px, 96%);
    padding: 8px 10px 10px;
    border: 3px solid var(--green);
}
.tool-desc { font-size: 0.95rem; font-weight: 800; color: var(--green); margin: 0 4px 6px; }
.tool-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.tool-btn {
    position: relative;
    min-height: 68px;
    border: 3px solid #cbd5e1;
    border-radius: 14px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 0.82rem;
    font-weight: 800;
    color: var(--text);
    cursor: pointer;
    padding: 2px;
    line-height: 1.1;
}
.tool-btn img { width: 34px; height: 34px; object-fit: contain; pointer-events: none; }
.tool-btn.active { border-color: var(--green); background: var(--green-soft); box-shadow: 0 0 0 3px rgba(4, 120, 87, 0.3); }
.tool-btn.locked { opacity: 0.35; }
.tool-btn .left-badge {
    position: absolute;
    top: -8px;
    right: -6px;
    background: #f97316;
    color: #fff;
    border-radius: 12px;
    font-size: 0.72rem;
    padding: 1px 6px;
}
.pause-note {
    position: absolute;
    left: 50%;
    top: 46%;
    transform: translate(-50%, -50%);
    background: rgba(15, 23, 42, 0.8);
    color: #fff;
    font-weight: 800;
    padding: 10px 20px;
    border-radius: 24px;
    z-index: 11;
    pointer-events: none;
}

/* ---------- モードえらび ---------- */
.home-screen {
    position: absolute;
    inset: 0;
    z-index: 7000;
    background: #0f172a;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 70px 16px 16px;
}
.home-card {
    position: relative;
    width: min(1000px, 100%);
    height: 100%;
    max-height: 640px;
    background: #fff;
    border-radius: 28px;
    overflow: hidden;
    display: flex;
}
.home-left {
    position: relative;
    flex: 0 0 34%;
    background: var(--green);
    color: #fff;
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 6px;
}
.home-emoji { font-size: 4rem; line-height: 1; }
.home-title { margin: 0; font-size: 2.4rem; font-weight: 900; }
.home-sub { margin: 0; font-weight: 800; font-size: 1.1rem; }
.home-desc { margin: 6px 0; font-size: 0.95rem; font-weight: 700; line-height: 1.6; background: rgba(0, 0, 0, 0.18); border-radius: 14px; padding: 10px; }
.home-lang { margin-top: 8px; }
.home-right {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    background: #f8fafc;
    padding: 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.free-btn {
    width: 100%;
    min-height: 80px;
    display: flex;
    align-items: center;
    gap: 14px;
    text-align: left;
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 18px;
    padding: 10px 16px;
    cursor: pointer;
    box-shadow: 0 4px 0 #1d4ed8;
}
.free-btn:active { transform: translateY(3px); box-shadow: none; }
.free-btn b { display: block; font-size: 1.15rem; }
.free-btn small { display: block; font-size: 0.85rem; opacity: 0.92; font-weight: 700; }
.free-emoji { font-size: 2.4rem; }
.list-head { margin: 14px 0 4px; font-size: 1.15rem; color: #334155; border-left: 5px solid var(--green); padding-left: 8px; }
.clear-count { font-size: 0.9rem; color: var(--green); }
.medal-guide { margin: 0 0 8px; font-size: 0.85rem; font-weight: 800; color: #92400e; }
.mission-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mission-btn {
    position: relative;
    min-height: 64px;
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: left;
    background: #fff;
    border: 2px solid #e2e8f0;
    border-radius: 14px;
    padding: 6px 10px;
    cursor: pointer;
    font-family: var(--font);
    color: var(--text);
}
.mission-btn:active { background: #ecfdf5; }
.mission-btn .m-icon { flex: 0 0 44px; height: 44px; border-radius: 50%; background: #f1f5f9; display: flex; align-items: center; justify-content: center; font-size: 1.6rem; }
.mission-btn .m-name { font-weight: 800; font-size: 0.95rem; line-height: 1.3; }
.mission-btn .m-num { display: block; font-size: 0.75rem; color: var(--sub); }
.mission-btn.cleared { border-color: #34d399; background: #f0fdf4; }
.mission-btn.cleared::after { content: '✅'; position: absolute; top: 4px; right: 6px; font-size: 1rem; }

/* ---------- 小窓 ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 8000;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-box {
    position: relative;
    width: min(520px, 94vw);
    max-height: 92dvh;
    overflow-y: auto;
    background: #fff;
    border: 5px solid #10b981;
    border-radius: 24px;
    padding: 18px 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.modal-box h2 { margin: 0; color: var(--green-dark); font-size: 1.5rem; }
.big-emoji { font-size: 3.4rem; line-height: 1; }
.start-desc { margin: 0; font-weight: 700; line-height: 1.6; }
.goal-box { background: #fefce8; border: 2px solid #fde68a; border-radius: 14px; padding: 10px; font-size: 1.05rem; }
.start-limit { margin: 0; font-size: 0.9rem; font-weight: 800; color: #c2410c; }
.hint-box { border-color: var(--yellow); }
.hint-text { margin: 0; background: #fefce8; border-radius: 14px; padding: 12px; font-weight: 800; line-height: 1.7; text-align: left; }
.result-msg { margin: 0; font-weight: 800; font-size: 1.1rem; }
.result-medal { margin: 0; font-weight: 800; color: #92400e; }
.result-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn {
    min-height: 52px;
    border: none;
    border-radius: 16px;
    font-size: 1.05rem;
    font-weight: 800;
    cursor: pointer;
    padding: 6px 10px;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
}
.btn:active { transform: translateY(3px); box-shadow: none; }
.btn-main { background: #10b981; color: #fff; }
.btn-sub { background: #e2e8f0; color: var(--text); }
.btn-cert { background: var(--yellow); color: #713f12; grid-column: 1 / -1; }

.toast {
    position: fixed;
    left: 50%;
    top: 90px;
    transform: translateX(-50%);
    z-index: 8500;
    background: rgba(15, 23, 42, 0.9);
    color: #fff;
    font-weight: 800;
    padding: 10px 20px;
    border-radius: 24px;
    max-width: 90vw;
    text-align: center;
    pointer-events: none;
}

/* ---------- 高さ・はば ---------- */
@media (max-height: 740px) {
    #topbar { min-height: 64px; }
    .tool-btn { min-height: 56px; font-size: 0.75rem; }
    .tool-btn img { width: 28px; height: 28px; }
    .tool-desc { font-size: 0.85rem; margin-bottom: 4px; }
    .mission-goal { font-size: 0.95rem; }
    .count-grid b { font-size: 1.05rem; }
    .home-desc { font-size: 0.85rem; }
}
@media (max-width: 900px) {
    .bar-title { display: none; }
    .mission-list { grid-template-columns: 1fr; }
    .home-left { flex-basis: 38%; }
}
@media (max-width: 700px) {
    .tool-grid { grid-template-columns: repeat(4, 1fr); }
    .home-card { flex-direction: column; max-height: none; }
    .home-left { flex: 0 0 auto; padding: 10px; }
    .home-emoji, .home-desc { display: none; }
    .count-box { width: 180px; }
}

/* P1：スマホの よこ（高さが ひくい）。はじめの 画面の 左の 緑の らんが 上下に 切れて、言語ボタンが 画面の 外だった
   → 地球の 絵を かくして つめる・入りきらない ときは らんの 中を スクロール（まんなかよせは margin: auto） */
@media (max-height: 560px) and (orientation: landscape) {
    .home-screen { padding: 58px 12px 10px; }
    .home-left { justify-content: flex-start; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 12px; gap: 4px; }
    .home-left > :first-child { margin-top: auto; }
    .home-left > :last-child { margin-bottom: auto; }
    .home-emoji { display: none; }
    .home-title { font-size: 1.7rem; }
    .home-sub { font-size: 0.95rem; }
    .home-desc { font-size: 0.8rem; line-height: 1.5; padding: 6px 8px; margin: 2px 0; }
    .home-lang { margin-top: 4px; }
}

/* P1：スマホの たて。上の 帯が 1行に 入らず「はやさ」と「やりなおす」が 右の 画面の 外だった
   → 2行に（1行めは 🏠 の 右に「モードを えらぶ」、2行めに やりなおす・はやさ。rules md 2-9 の 🏠 よけは 1行めだけ） */
@media (max-width: 600px) {
    #topbar { flex-wrap: wrap; row-gap: 6px; padding-left: calc(12px + env(safe-area-inset-left, 0px)); }
    #btn-menu { margin-left: calc(124px + env(safe-area-inset-left, 0px)); }
    .bar-right { width: 100%; justify-content: flex-end; flex-wrap: wrap; }
    .bar-btn { min-height: 44px; padding: 6px 10px; font-size: 0.9rem; }
    .speed-box { min-height: 44px; }
}
