/* ==========================================================================
   Student textbooks — read-only library
   ========================================================================== */

:root {
    --tb_bg: #96a9bf;
    --tb_card: #ffffff;
    --tb_border: #e2e8f0;
    --tb_navy: #0e2a3a;
    --tb_green: #2f6b4f;
    --tb_text: #1f2430;
    --tb_muted: #64748b;
}

body.tb_body {
    margin: 0;
    background: var(--tb_bg);
    color: var(--tb_text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.tb_wrap {
    max-width: 1520px;
    margin: 0 auto;
    padding: 26px 18px 48px;
}

/* Keeps a page heading for screen readers without showing it. */
.tb_sr_only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.tb_layout {
    display: grid;
    grid-template-columns: 260px 360px minmax(0, 1fr);
    grid-template-areas: "side units lesson";
    gap: 18px;
    align-items: start;
}

/* ---- inline lesson viewer ------------------------------------------------ */

.tb_lesson__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding-bottom: 10px;
}

.tb_lesson__eyebrow {
    margin: 0;
    color: var(--tb_green);
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.tb_lesson__close {
    flex: 0 0 auto;
    padding: 7px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    color: #33404f;
    font-size: 12.5px;
    font-weight: 700;
    text-decoration: none;
}

.tb_lesson__close:hover {
    background: #f8fafc;
}

.tb_reader {
    /* The lesson sheet reads these from :root, which a shadow tree cannot
       see — define them on the host so they inherit in. */
    --ink: #1f2430;
    --ink-soft: #374151;
    --muted: #6b7280;
    --line: #e5e7eb;
    --accent: #2f6fb5;
    --accent-dark: #24466c;
    --accent-soft: #eef4fb;
    --page-bg: #e8eaee;

    overflow: hidden;
    border: 1px solid #e6ebf1;
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.tb_reader[hidden] {
    display: none;
}

.tb_lesson__head[hidden],
.tb_lesson__placeholder[hidden],
.tb_reader[hidden] {
    display: none;
}

.tb_lesson__placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 380px;
    padding: 24px;
    border: 1px dashed #cbd5e1;
    border-radius: 12px;
    background: #f8fafc;
    color: var(--tb_muted);
    text-align: center;
}

.tb_lesson__placeholder p {
    margin: 0;
    font-size: 14px;
}

.tb_side,
.tb_units_col,
.tb_lesson_col {
    min-width: 0;
    background: var(--tb_card);
    border: 1px solid var(--tb_border);
    border-radius: 16px;
}

.tb_side {
    grid-area: side;
    padding: 14px;
    position: sticky;
    top: 14px;
    max-height: calc(100vh - 28px);
    overflow-x: hidden;
    overflow-y: auto;
}

/* Small tag that labels the whole menu. */
.tb_side__tag {
    display: inline-flex;
    align-items: center;
    margin: 2px 0 10px 2px;
    padding: 4px 10px;
    border-radius: 999px;
    background: #eef7f1;
    color: #2f6b4f;
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: 0.14em;
    line-height: 1.2;
}

.tb_units_col {
    grid-area: units;
    padding: 16px 18px;
    position: sticky;
    top: 14px;
    max-height: calc(100vh - 28px);
    overflow-x: hidden;
    overflow-y: auto;
}

.tb_lesson_col {
    grid-area: lesson;
    padding: 16px;
}

.tb_group {
    margin-bottom: 6px;
}

.tb_group:last-child {
    margin-bottom: 0;
}

.tb_group__name {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    margin: 0;
    padding: 8px 10px;
    border-radius: 9px;
    color: #52606d;
    font-size: 12.5px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    list-style: none;
    cursor: pointer;
    user-select: none;
}

.tb_group__text {
    flex: 0 0 auto;
    min-width: 0;
}

.tb_group__icon {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    color: #64748b;
}

.tb_group__icon svg {
    display: block;
    width: 18px;
    height: 18px;
}

.tb_group__name:hover .tb_group__icon,
.tb_group[open] > .tb_group__name .tb_group__icon {
    color: #2f6b4f;
}

/* Hide the native triangle; a CSS chevron shows the open state instead. */
.tb_group__name::-webkit-details-marker {
    display: none;
}

.tb_group__name::after {
    content: "";
    flex: 0 0 auto;
    width: 7px;
    height: 7px;
    margin-left: auto;
    margin-right: 2px;
    border-right: 1.5px solid #94a3b8;
    border-bottom: 1.5px solid #94a3b8;
    transform: rotate(45deg);
    transition: transform 0.15s ease;
}

.tb_group[open] > .tb_group__name::after {
    transform: rotate(-135deg);
}

.tb_group__name:hover {
    background: #f5f8fa;
    color: #33404f;
}

.tb_group__name:focus-visible {
    outline: 2px solid rgba(47, 107, 79, 0.28);
    outline-offset: 1px;
}

.tb_group[open] > .tb_group__name {
    margin-bottom: 4px;
    color: #33404f;
}

.tb_level {
    display: block;
    padding: 8px 10px;
    border-radius: 9px;
    color: #33404f;
    font-size: 14.5px;
    text-decoration: none;
}

.tb_level:hover {
    background: #eef7f1;
    color: var(--tb_green);
}

.tb_level.is-active {
    background: #eef7f1;
    color: var(--tb_green);
    font-weight: 700;
}

.tb_main__head {
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid #eef1f5;
}

.tb_main__title {
    margin: 0;
    color: var(--tb_text);
    font-size: 19px;
    font-weight: 700;
}

.tb_main__meta {
    margin: 4px 0 0;
    color: var(--tb_muted);
    font-size: 12.5px;
    font-weight: 600;
}

.tb_units {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.tb_unit {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid #eef1f5;
    border-radius: 12px;
    color: inherit;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.tb_unit:hover,
.tb_unit:focus-visible {
    background: #fbfdfc;
    border-color: #cfe3d6;
    outline: none;
}

.tb_unit.is-open {
    background: #fff4e8;
    border-color: #f0c48c;
}

.tb_unit--static {
    cursor: default;
}

.tb_unit--static:hover {
    background: #f4faf6;
    border-color: #cfe3d6;
}

/* Inline textbook page (Free Conversation, Trial lesson) */
.tb_embed {
    display: block;
    width: 100%;
    height: calc(100vh - 160px);
    min-height: 560px;
    border: 1px solid #e6ebf1;
    border-radius: 10px;
    background: #fff;
}

.tb_unit.is-open .tb_unit__num {
    background: #ffe4c4;
    color: #b45309;
}

.tb_unit__num {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: #eef7f1;
    color: var(--tb_green);
    font-size: 13px;
    font-weight: 800;
}

.tb_unit__body {
    flex: 1;
    min-width: 0;
}

.tb_unit__title {
    display: block;
    font-size: 14.5px;
    font-weight: 700;
}

.tb_unit__desc {
    display: block;
    margin-top: 2px;
    overflow: hidden;
    color: var(--tb_muted);
    font-size: 12.5px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tb_unit__chev {
    flex: 0 0 auto;
    color: #94a3b8;
    font-size: 16px;
    font-weight: 700;
}

/* Lesson status tints the whole row, like the calendar's day chips.
   Booked and completed share one colour. */
.tb_unit--booked,
.tb_unit--completed {
    background: #e9f3ed;
    border-color: #d3e5da;
}

.tb_unit--booked:hover,
.tb_unit--booked:focus-visible,
.tb_unit--completed:hover,
.tb_unit--completed:focus-visible {
    background: #dcece2;
    border-color: #bcd8c7;
}

.tb_legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    margin: 10px 0 12px;
    color: var(--tb_muted);
    font-size: 12px;
    font-weight: 600;
}

.tb_legend__item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.tb_legend__dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    border: 1px solid #d3e5da;
    background: #e9f3ed;
}

.tb_legend__dot--new {
    background: #ffffff;
    border-color: #cbd5e1;
}

.tb_empty {
    margin: 0;
    padding: 22px;
    border: 1px dashed #cbd5e1;
    border-radius: 12px;
    background: #f8fafc;
    color: var(--tb_muted);
    font-size: 14px;
    text-align: center;
}

/* Two columns: the level list stays left, lessons and the page stack right. */
@media (max-width: 1150px) {
    .tb_layout {
        grid-template-columns: 260px minmax(0, 1fr);
        grid-template-areas:
            "side units"
            "side lesson";
    }

    .tb_units_col {
        position: static;
        max-height: none;
        overflow: visible;
    }
}

@media (max-width: 760px) {
    .tb_layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "side"
            "units"
            "lesson";
    }

    .tb_side {
        position: static;
        max-height: 260px;
        overflow-y: auto;
    }
}

@media (max-width: 560px) {
    .tb_wrap {
        padding: 12px 12px 36px;
    }

    .tb_units_col {
        padding: 14px;
    }

    .tb_lesson_col {
        padding: 12px;
    }

    .tb_unit__desc {
        white-space: normal;
    }
}

/* teacher-only category teaching guides under the textbook links */
.tb_teacher_guides {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid #e2e8f0;
}

.tb_teacher_guides .tb_side__tag {
    margin-bottom: 8px;
}

.tb_teacher_guide {
    display: block;
    margin-top: 6px;
    padding: 9px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    color: #1f2430;
    text-decoration: none;
}

.tb_teacher_guide span {
    display: block;
    font-size: 13px;
    font-weight: 600;
}

.tb_teacher_guide small {
    display: block;
    margin-top: 1px;
    color: #64748b;
    font-size: 11px;
}

.tb_teacher_guide:hover {
    background: #eef7f1;
    border-color: #b9dcc6;
    color: #2f6b4f;
}

.tb_teacher_guide:focus-visible {
    outline: 2px solid #5b8c6a;
    outline-offset: 2px;
}

/* ---- teacher library page ------------------------------------------------ */

/* The library sits inside the teacher layout instead of its own page shell. */
.tb_teacher_lib .tb_layout {
    gap: 16px;
}

.tb_teacher_lib .tb_side,
.tb_teacher_lib .tb_units_col,
.tb_teacher_lib .tb_lesson_col {
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}

.tb_teacher_lib .tb_side,
.tb_teacher_lib .tb_units_col {
    top: 0;
    max-height: calc(100vh - 40px);
}

@media (max-width: 760px) {
    .tb_teacher_lib .tb_units_col {
        position: static;
        max-height: none;
        overflow: visible;
    }

    .tb_teacher_lib .tb_side {
        max-height: none;
        overflow: visible;
    }
}

/* ---- teaching guides in the reading column ------------------------------ */

.tb_teacher_guide.is-active {
    border-color: #8fbfa4;
    background: #e7f3eb;
    color: #245a3d;
}

.tb_lesson_view[hidden],
.tb_guide_panel[hidden] {
    display: none;
}

.tb_guide_head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 2px;
}

.tb_guide_head .tb_lesson__eyebrow {
    margin: 0;
}

.tb_guide_title {
    margin: 0;
    color: var(--tb_text);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.tb_guide_summary {
    margin: 6px 0 14px;
    color: var(--tb_muted);
    font-size: 13.5px;
    line-height: 1.5;
}

.tb_guide_panel .ts_guide_page {
    grid-template-columns: 1fr;
    gap: 12px;
}

.tb_guide_panel .ts_guide_section,
.tb_guide_panel .ts_guide_section--wide {
    grid-column: auto;
    padding: 14px 16px;
}

.tb_guide_panel .ts_guide_section h2 {
    margin-bottom: 8px;
    font-size: 15px;
}

.tb_guide_panel .ts_guide_section ol,
.tb_guide_panel .ts_guide_section ul {
    gap: 6px;
    padding-left: 18px;
    font-size: 13px;
    line-height: 1.5;
}

.tb_guide_panel .ts_guide_section p {
    font-size: 13px;
    line-height: 1.55;
}

.tb_guide_loading {
    margin: 0;
    padding: 26px 18px;
    border: 1px dashed #cbd5e1;
    border-radius: 12px;
    background: #f8fafc;
    color: var(--tb_muted);
    font-size: 13.5px;
    text-align: center;
}

@media (max-width: 760px) {
    .tb_guide_panel .ts_guide_page {
        gap: 10px;
    }
}

/* While a guide is open, the individual lesson list gives up its space to the
   guide. The textbook levels stay so the guide links remain reachable. */
.tb_teacher_lib .tb_layout.is-guide {
    grid-template-columns: 260px minmax(0, 1fr);
    grid-template-areas: "side lesson";
}

.tb_teacher_lib .tb_layout.is-guide .tb_units_col {
    display: none;
}

@media (max-width: 1150px) {
    .tb_teacher_lib .tb_layout.is-guide {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "side" "lesson";
    }

    .tb_teacher_lib .tb_layout.is-guide .tb_side {
        position: static;
        max-height: none;
        overflow: visible;
    }
}

/* ---- mobile lesson flow -------------------------------------------------- */

/* The search field and its short close label are small-screen only. */
.tb_filter,
.tb_close_label--mobile {
    display: none;
}

.tb_filter__label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.tb_filter__input {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #f8fafc;
    color: #1f2430;
    font: inherit;
    font-size: 14px;
}

.tb_filter__input:focus {
    outline: none;
    border-color: #8fbfa4;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(91, 140, 106, 0.18);
}

.tb_filter__status {
    margin: 8px 0 0;
    color: #64748b;
    font-size: 12.5px;
}

@media (max-width: 760px) {
    .tb_filter {
        display: block;
    }

    /* Level, lesson count and search stay pinned while the list scrolls. */
    body.tb_body .tb_units_top {
        position: sticky;
        top: 0;
        z-index: 8;
        margin: -16px -18px 12px;
        padding: 12px 18px 10px;
        border-bottom: 1px solid #eef1f5;
        border-radius: 16px 16px 0 0;
        background: #fff;
    }

    body.tb_body .tb_units_top .tb_main__head {
        margin: 0;
        padding-bottom: 10px;
        border-bottom: 0;
    }

    body.tb_body .tb_units_top .tb_main__title {
        font-size: 18px;
    }

    body.tb_body .tb_units_top .tb_main__meta {
        margin-top: 2px;
        font-size: 12px;
    }

    /* Every category and level stays in the page flow: no inner scroll box,
       and each dropdown row stays on a single line. */
    body.tb_body .tb_side {
        position: relative;
        z-index: 50;
        max-height: none;
        overflow: visible;
    }

    /* A category's levels open as a floating menu over the page instead of
       pushing the lesson list down. */
    body.tb_body .tb_group {
        position: relative;
    }

    body.tb_body .tb_group[open] {
        z-index: 55;
    }

    body.tb_body .tb_levels {
        position: absolute;
        top: calc(100% + 4px);
        left: 0;
        right: 0;
        z-index: 60;
        max-height: 55vh;
        overflow-y: auto;
        padding: 6px;
        background: #fff;
        border: 1px solid #dfe5ec;
        border-radius: 12px;
        box-shadow: 0 18px 40px rgba(15, 23, 42, 0.2);
        -webkit-overflow-scrolling: touch;
    }

    body.tb_body .tb_group[open] > .tb_group__name {
        background: #f5f8fa;
    }

    body.tb_body .tb_group__name,
    body.tb_body .tb_group__text,
    body.tb_body .tb_level {
        white-space: nowrap;
    }

    body.tb_body .tb_group__text {
        flex: 1 1 auto;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    body.tb_body .tb_level {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    body.tb_body .tb_lesson_col {
        scroll-margin-top: 10px;
    }

    .tb_close_label--desktop {
        display: none;
    }

    .tb_close_label--mobile {
        display: inline;
    }

    .tb_lesson__close {
        display: inline-flex;
        align-items: center;
        min-height: 40px;
        padding: 8px 14px;
    }

    .tb_lesson__close::before {
        content: "\2190";
        margin-right: 7px;
        font-weight: 700;
    }
}

@media (max-width: 560px) {
    body.tb_body .tb_units_top {
        margin: -14px -14px 10px;
        padding: 12px 14px 10px;
    }
}

/* ---- desktop keeps the original three columns --------------------------- */

@media (min-width: 761px) {
    /* Phones use the すべてのレッスン menu instead of the category accordions. */
    .tb_group--all {
        display: none;
    }
}

/* ---- phones: menu + lesson sheet only ----------------------------------- */

@media (max-width: 760px) {
    .tb_layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "side" "lesson";
    }

    .tb_desktop_nav,
    .tb_units_col {
        display: none;
    }
}

/* One scrollable index of every live lesson, grouped by level. */
.tb_levels--all {
    max-height: min(60vh, 520px);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.tb_levels__group {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 9px 8px;
    color: #475569;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.05em;
    white-space: nowrap;
    cursor: pointer;
    list-style: none;
}

.tb_levels__group::-webkit-details-marker {
    display: none;
}

.tb_lv {
    border-bottom: 1px solid #eef1f5;
}

.tb_lv:last-child {
    border-bottom: 0;
}

.tb_lv__name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tb_lv__count {
    flex: 0 0 auto;
    color: #94a3b8;
    font-size: 10px;
    font-weight: 700;
}

.tb_levels__group::after {
    content: "";
    flex: 0 0 auto;
    width: 6px;
    height: 6px;
    margin-left: 2px;
    margin-right: 3px;
    border-right: 1.5px solid #94a3b8;
    border-bottom: 1.5px solid #94a3b8;
    transform: rotate(45deg);
    transition: transform 0.15s ease;
}

.tb_lv[open] > .tb_levels__group::after {
    transform: rotate(-135deg);
}

.tb_lv__list {
    padding: 0 2px 6px;
}

.tb_lv__list--cat {
    padding-left: 6px;
}

.tb_level--lesson {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.tb_level__no {
    flex: 0 0 auto;
    min-width: 18px;
    color: #2f6b4f;
    font-size: 11px;
    font-weight: 700;
    text-align: right;
}

.tb_level__name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
