/* ============================================================
   でじらぼきっず「へや」の 見た目（B20・2026/10/19）
   ・3つの へや（math・english・play）で 共通。へやの 色は room.js が :root に 入れる
   ・スクロールする ページ（アプリが 多いため）。.hidden は rules md 2-10 の 形
   ・左上 140px は deji_nav.js の 🏠 もどる の 場所
   ・T8（2026/10/24）：カードの 上の 16:9 に アプリの 絵（assets/thumbs/。cover。読みおわるまでは 絵文字）
   ============================================================ */

:root {
    --room: #21795A;
    --room-tint: #E6F3EC;
    --room-deep: #155640;
    --ink: #1F2A33;
    --ink-soft: #4E5B66;
    --paper: #FFFFFF;
    --line: rgba(31, 42, 51, 0.14);
    --font-round: 'M PLUS Rounded 1c', 'Gowun Dodum', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'BIZ UDPGothic', 'Meiryo', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
    --font-ko: 'Gowun Dodum', 'M PLUS Rounded 1c', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'BIZ UDPGothic', 'Meiryo', sans-serif;
}

/* UI要塞化：かくすのは .hidden だけ（スクロールする ページなので 高さ・はばも 0 に） */
.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    z-index: -1 !important;
    position: absolute !important;
    max-height: 0 !important;
    max-width: 0 !important;
    overflow: hidden !important;
}

*, *::before, *::after { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    font-family: var(--font-round);
    color: var(--ink);
    background-color: var(--room-tint);
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}
html[lang="ko"] body { font-family: var(--font-ko); }

/* へやごとの ノートの もよう（さんすう＝方眼・えいご＝4本線・おたのしみ＝水玉） */
body[data-room="math"] {
    background-image:
        linear-gradient(rgba(33, 121, 90, 0.07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(33, 121, 90, 0.07) 1px, transparent 1px);
    background-size: 28px 28px;
}
body[data-room="english"] {
    background-image: repeating-linear-gradient(
        to bottom,
        transparent 0, transparent 22px,
        rgba(52, 80, 184, 0.08) 22px, rgba(52, 80, 184, 0.08) 23px,
        transparent 23px, transparent 30px,
        rgba(52, 80, 184, 0.13) 30px, rgba(52, 80, 184, 0.13) 31px,
        transparent 31px, transparent 38px,
        rgba(52, 80, 184, 0.08) 38px, rgba(52, 80, 184, 0.08) 39px,
        transparent 39px, transparent 46px,
        rgba(184, 51, 106, 0.10) 46px, rgba(184, 51, 106, 0.10) 47px,
        transparent 47px, transparent 64px);
}
body[data-room="play"] {
    background-image: radial-gradient(rgba(184, 51, 106, 0.10) 2.5px, transparent 3px);
    background-size: 26px 26px;
}

.page {
    max-width: 1180px;
    margin: 0 auto;
    padding: 12px calc(18px + env(safe-area-inset-right, 0px)) calc(40px + env(safe-area-inset-bottom, 0px)) calc(18px + env(safe-area-inset-left, 0px));
}

/* ---------- 上の ならび：🏠（deji_nav.js）の 場所・言語ボタン ---------- */
.top-bar {
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    min-height: 58px;
    padding-left: calc(140px + env(safe-area-inset-left, 0px));
}
.lang-slot { display: flex; justify-content: flex-end; }

/* ---------- へやの ふだ（教室の 室名札） ---------- */
.room-head {
    display: flex;
    align-items: flex-end;
    gap: 18px;
    margin: 4px 0 18px;
}
.room-plate {
    position: relative;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 26px 14px 18px;
    background: var(--paper);
    border: 3px solid var(--room);
    border-radius: 10px;
    box-shadow: 0 6px 0 var(--room-deep);
}
.room-plate::before,
.room-plate::after {
    content: "";
    position: absolute;
    top: -15px;
    width: 4px;
    height: 15px;
    background: var(--room-deep);
    border-radius: 2px;
}
.room-plate::before { left: 26px; }
.room-plate::after { right: 26px; }
.room-ico {
    display: grid;
    place-items: center;
    width: 62px;
    height: 62px;
    flex: 0 0 62px;
    font-size: 36px;
    line-height: 1;
    background: var(--room-tint);
    border-radius: 50%;
}
.room-title {
    margin: 0;
    font-size: 34px;
    font-weight: 900;
    line-height: 1.2;
    color: var(--room-deep);
    letter-spacing: 0.02em;
    word-break: keep-all;
    overflow-wrap: anywhere;
}

.guide {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    min-width: 0;
}
.guide-gem {
    width: 74px;
    height: 74px;
    flex: 0 0 74px;
    object-fit: contain;
}
.guide-bubble {
    position: relative;
    margin: 0 0 18px;
    padding: 10px 16px;
    background: var(--paper);
    border: 2px solid var(--room);
    border-radius: 18px;
    font-size: 17px;
    font-weight: 700;
    line-height: 1.5;
    color: var(--ink);
    word-break: keep-all;
    overflow-wrap: anywhere;
}
.guide-bubble::before {
    content: "";
    position: absolute;
    left: -10px;
    bottom: 12px;
    width: 14px;
    height: 14px;
    background: var(--paper);
    border-left: 2px solid var(--room);
    border-bottom: 2px solid var(--room);
    transform: rotate(45deg);
}

/* ---------- えらぶ ところ（学年・ジャンル） ---------- */
.pickers {
    display: grid;
    gap: 12px;
    padding: 14px 16px;
    margin-bottom: 22px;
    background: rgba(255, 255, 255, 0.92);
    border: 2px solid var(--line);
    border-radius: 18px;
}
.picker {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.picker-label {
    flex: 0 0 auto;
    min-width: 128px;
    font-size: 17px;
    font-weight: 800;
    color: var(--room-deep);
}
.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
    padding: 0;
}
.chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 52px;
    padding: 0 18px;
    font-family: inherit;
    font-size: 17px;
    font-weight: 800;
    color: var(--ink);
    background: var(--paper);
    border: 2px solid var(--line);
    border-radius: 999px;
    cursor: pointer;
    touch-action: manipulation;
    transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}
.chip-grade {
    flex-direction: column;
    gap: 0;
    width: 56px;
    min-width: 56px;
    height: 56px;
    padding: 0;
    border-radius: 50%;
    line-height: 1;
}
.chip-grade .chip-num { font-size: 22px; font-weight: 900; }
.chip-grade .chip-unit { font-size: 11px; font-weight: 700; margin-top: 3px; white-space: nowrap; }
.chip-grade.chip-all { width: auto; min-width: 84px; padding: 0 16px; border-radius: 999px; font-size: 17px; }
.chip-ico { font-size: 22px; line-height: 1; }
.chip[data-empty="true"] {
    opacity: 0.45;
}
.chip[aria-pressed="true"] {
    color: #FFFFFF;
    background: var(--chip-on, var(--room));
    border-color: var(--chip-on, var(--room));
}
.chip:focus-visible,
.card:focus-visible,
.door:focus-visible {
    outline: 4px solid #F2B705;
    outline-offset: 3px;
}

.result-line {
    margin: -8px 2px 14px;
    font-size: 15px;
    font-weight: 700;
    color: var(--ink-soft);
}

/* ---------- ジャンルの まとまり ---------- */
.genre-sec {
    position: relative;
    margin: 0 0 26px;
}
.genre-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 12px;
    font-size: 21px;
    font-weight: 900;
    color: var(--ink);
}
.genre-head-ico {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    font-size: 22px;
    line-height: 1;
    background: var(--g, var(--room));
    border-radius: 12px;
}
.genre-head-count {
    font-size: 15px;
    font-weight: 700;
    color: var(--ink-soft);
}
.grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(206px, 1fr));
    gap: 16px;
}

/* ---------- アプリの カード（シール） ---------- */
.card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    color: inherit;
    text-decoration: none;
    background: var(--paper);
    border: 2px solid var(--g, var(--room));
    border-bottom-width: 6px;
    border-radius: 16px;
    overflow: hidden;
    touch-action: manipulation;
    -webkit-touch-callout: none;   /* T8：長おしで 絵の 保存・リンクの 下見が 出ないように（子どもが まよわない） */
    transition: transform 90ms ease, border-bottom-width 90ms ease;
}
.card:active {
    transform: translateY(3px);
    border-bottom-width: 3px;
}
.card-pic {
    position: relative;
    display: grid;
    place-items: center;
    aspect-ratio: 16 / 9;
    background: var(--g-tint, var(--room-tint));
    overflow: hidden;
}
.card-ico {
    font-size: 58px;
    line-height: 1;
}
/* T8：アプリの 絵（1280×720＝カードと 同じ 16:9 なので cover でも 切れない）。読みおわったら ふわっと 出す */
.card-img {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 180ms ease;
    pointer-events: none;
    -webkit-user-drag: none;
    user-select: none;
    -webkit-user-select: none;
}
.card-pic--loaded .card-img { opacity: 1; }
.card-medal {
    position: absolute;
    top: 8px;
    right: 8px;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px 9px 3px 6px;
    font-size: 13px;
    font-weight: 800;
    color: #6B4A00;
    background: #FFE27A;
    border: 2px solid #E0B320;
    border-radius: 999px;
    line-height: 1.2;
    z-index: 1;                                   /* T8：絵の 上に */
    box-shadow: 0 1px 3px rgba(31, 42, 51, 0.28); /* T8：絵の 上でも 読めるように */
}
.card-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1 1 auto;
    padding: 10px 12px 12px;
}
.card-name {
    margin: 0;
    font-size: 18px;
    font-weight: 900;
    line-height: 1.55;
    word-break: keep-all;          /* わかちがきの すきまで だけ 改行（ことばの とちゅうで 切らない） */
    overflow-wrap: anywhere;       /* すきまの ない 長い ことばは はみださないよう どこでも 改行 */
    line-break: strict;
}
.card-desc {
    margin: 0;
    font-size: 14.5px;
    font-weight: 400;
    line-height: 1.75;
    color: var(--ink-soft);
    word-break: keep-all;
    overflow-wrap: anywhere;
    line-break: strict;
}
ruby rt {
    font-size: 0.52em;
    font-weight: 700;
    letter-spacing: 0;
}
.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: auto;
    padding-top: 4px;
}
.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.3;
    color: var(--ink);
    background: #F1F4F6;
    border-radius: 8px;
}

/* ---------- 見つからない とき ---------- */
.empty {
    display: grid;
    justify-items: center;
    gap: 14px;
    padding: 36px 16px;
    text-align: center;
    background: var(--paper);
    border: 2px dashed var(--line);
    border-radius: 18px;
}
.empty-text {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

/* ---------- ほかの へや ---------- */
.doors {
    margin-top: 34px;
    padding-top: 22px;
    border-top: 3px dotted var(--line);
}
.doors-title {
    margin: 0 0 12px;
    font-size: 19px;
    font-weight: 900;
}
.doors-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px;
}
.door {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 72px;
    padding: 12px 18px;
    font-size: 19px;
    font-weight: 900;
    color: var(--door-deep, var(--ink));
    text-decoration: none;
    background: var(--paper);
    border: 3px solid var(--door, var(--line));
    border-radius: 12px;
    box-shadow: 0 5px 0 var(--door-deep, var(--line));
    touch-action: manipulation;
}
.door:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 var(--door-deep, var(--line));
}
.door-ico {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    font-size: 28px;
    background: var(--door-tint, #F1F4F6);
    border-radius: 50%;
}

/* ---------- せまい 画面（スマホ・iPad たて の 小さい とき） ---------- */
@media (max-width: 860px) {
    .room-head { flex-wrap: wrap; align-items: center; }
    .room-title { font-size: 28px; }
    .guide-gem { width: 58px; height: 58px; flex-basis: 58px; }
    .guide-bubble { margin-bottom: 10px; font-size: 16px; }
}
@media (max-width: 700px) {
    .page { padding-left: calc(12px + env(safe-area-inset-left, 0px)); padding-right: calc(12px + env(safe-area-inset-right, 0px)); }
    .top-bar { min-height: 64px; }
    .room-plate { gap: 12px; padding: 10px 16px 10px 12px; }
    .room-ico { width: 48px; height: 48px; flex-basis: 48px; font-size: 28px; }
    .room-title { font-size: 23px; }
    .picker-label { min-width: 0; width: 100%; font-size: 16px; }
    .pickers { padding: 12px; }
    .chip { min-height: 48px; padding: 0 14px; font-size: 16px; }
    .chip-grade { width: 50px; min-width: 50px; height: 50px; padding: 0; }
    .chip-grade.chip-all { width: auto; min-width: 76px; padding: 0 14px; }
    .chip-grade .chip-num { font-size: 20px; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 12px; }
    .card-ico { font-size: 46px; }
    /* T8：スマホでは メダルの 札を 🏅 だけに（絵を かくしすぎない）。「メダル」の 文字は 読み上げ用に のこす */
    .card-medal { top: 6px; right: 6px; padding: 3px 5px; font-size: 14px; }
    .card-medal-text {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        padding: 0;
        overflow: hidden;
        clip: rect(0 0 0 0);
        clip-path: inset(50%);
        white-space: nowrap;
        border: 0;
    }
    .card-name { font-size: 16.5px; }
    .card-desc { font-size: 13.5px; }
    .genre-head { font-size: 19px; }
    .doors-list { grid-template-columns: 1fr; }
}
@media (max-width: 400px) {
    .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .card-body { padding: 8px 9px 10px; }
    .tag { font-size: 12px; padding: 2px 7px; }
}

@media (prefers-reduced-motion: reduce) {
    .card, .chip, .door, .card-img { transition: none; }
    .card:active, .door:active { transform: none; }
}
