/* ==========================================================
 * でじらぼ 歌の教材 共通の見た目  (songs/song_player.css)  v1.1（B17・2026/10/19。v1.1：再生の はやさ）
 * ----------------------------------------------------------
 * songs/can・gojem・who・12rap で つかう。色は 各ページの :root（--sp-〇〇）で かえる。
 * ・左上の 🏠 もどる（deji_nav.js・140px）を よけるため、ヘッダーの 左を あける
 * ・右上に 言語ボタン（data-deji-lang）。せまい画面では ヘッダーの 下へ
 * ・.hidden は UI要塞化の 5つの 指定（引っ越しの型 3-4）
 * ・動画の わくの 大きさは song_player.js が 画面に あわせて きめる（16:9）
 * ========================================================== */

:root {
    --sp-font: 'M PLUS Rounded 1c', 'Gowun Dodum', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'BIZ UDPGothic', 'Meiryo', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
    --sp-safe-left: calc(150px + env(safe-area-inset-left, 0px));
    --sp-safe-right: calc(350px + env(safe-area-inset-right, 0px));
}

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

/* UI要塞化：かくす ものは 何よりも 先に かくす */
.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    z-index: -1 !important;
    position: absolute !important;
}

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

body {
    position: relative;
    background-color: var(--sp-bg);
    background-image:
        radial-gradient(circle at 15% 20%, var(--sp-spot-a), transparent 40%),
        radial-gradient(circle at 85% 80%, var(--sp-spot-b), transparent 40%);
    color: var(--sp-text);
    font-family: var(--sp-font);
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

button {
    font-family: var(--sp-font);
}

ruby rt {
    font-size: 0.5em;
    font-weight: 700;
}

/* ---------- 画面ぜんたい ---------- */
.sp-app {
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

@supports (height: 100dvh) {
    html,
    body {
        height: 100dvh;
    }
}

/* ---------- ヘッダー（タイトル） ---------- */
.sp-header {
    flex: 0 0 auto;
    min-height: calc(68px + env(safe-area-inset-top, 0px));
    padding: calc(8px + env(safe-area-inset-top, 0px)) var(--sp-safe-right) 4px var(--sp-safe-left);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sp-title {
    margin: 0;
    text-align: center;
    line-height: 1.25;
    min-width: 0;
    max-width: 100%;
}

.sp-title-main {
    display: block;
    font-size: clamp(18px, 2.4vw, 28px);
    font-weight: 900;
    color: var(--sp-title);
    letter-spacing: 0.03em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sp-title-sub {
    display: block;
    margin-top: 2px;
    font-size: clamp(13px, 1.6vw, 18px);
    font-weight: 700;
    color: var(--sp-title-sub);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- 言語の切りかえ（中身は deji_nav.js が入れる） ---------- */
.lang-slot {
    position: absolute;
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    z-index: 100;
    max-width: calc(100% - 170px);
}

/* ---------- 動画の場所 ---------- */
.sp-stage-area {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 12px;
}

.sp-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: 100%;
    background: #000;
    border: 4px solid var(--sp-frame);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--sp-frame-shadow);
}

/* 全画面（iPad の Safari は -webkit- の ほう。セレクタは 1つずつ 書く） */
.sp-frame:fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    max-height: none;
    aspect-ratio: auto;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

.sp-frame:-webkit-full-screen {
    width: 100vw !important;
    height: 100vh !important;
    max-height: none;
    aspect-ratio: auto;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

.sp-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    background: #000;
}

/* ---------- 動画の 上の 画面（スタート・おわり・エラー） ---------- */
.sp-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(4px, calc(var(--sp-fw, 900px) * 0.016), 18px);
    padding: clamp(8px, calc(var(--sp-fw, 900px) * 0.018), 16px);
    text-align: center;
    background: var(--sp-scrim);
    cursor: pointer;
    touch-action: manipulation;
}

.sp-overlay.sp-overlay-solid {
    cursor: default;
    background: var(--sp-scrim-strong);
}

.sp-big-play {
    width: clamp(52px, calc(var(--sp-fw, 900px) * 0.13), 150px);
    height: clamp(52px, calc(var(--sp-fw, 900px) * 0.13), 150px);
    border-radius: 50%;
    border: none;
    background: var(--sp-play);
    color: var(--sp-play-text);
    box-shadow: 0 6px 0 var(--sp-play-dark), 0 0 30px var(--sp-play-glow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    flex: 0 0 auto;
}

.sp-big-play svg {
    width: 46%;
    height: 46%;
    margin-left: 8%;
    fill: currentColor;
}

.sp-big-play:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 var(--sp-play-dark), 0 0 30px var(--sp-play-glow);
}

.sp-msg {
    margin: 0;
    font-size: clamp(16px, calc(var(--sp-fw, 900px) * 0.036), 38px);
    font-weight: 900;
    line-height: 1.5;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.85);
}

.sp-msg-sub {
    margin: 0;
    font-size: clamp(12px, calc(var(--sp-fw, 900px) * 0.022), 22px);
    font-weight: 700;
    line-height: 1.6;
    color: #fff;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.85);
}

.sp-chip {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: clamp(11px, calc(var(--sp-fw, 900px) * 0.017), 17px);
    font-weight: 700;
    line-height: 1.6;
}

.sp-end-btns {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-top: 4px;
}

/* 小さな わく（スマホ）では おわりの ボタンも 小さく */
.sp-end-btns .sp-btn {
    min-height: clamp(44px, calc(var(--sp-fw, 900px) * 0.058), 52px);
    font-size: clamp(14px, calc(var(--sp-fw, 900px) * 0.02), 18px);
}

/* ---------- 読みこみ中 ---------- */
.sp-loading {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    pointer-events: none;
}

.sp-spinner {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 7px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    animation: sp-spin 0.9s linear infinite;
}

@keyframes sp-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ---------- 一時停止の しるし（先生が 画面を 指して 話せるよう、動画を かくさない） ---------- */
.sp-paused {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 4;
    pointer-events: none;
}

/* ---------- 全画面を とじる ---------- */
.sp-fs-exit {
    position: absolute;
    top: calc(12px + env(safe-area-inset-top, 0px));
    right: calc(12px + env(safe-area-inset-right, 0px));
    z-index: 7;
}

/* ---------- 下の 操作 ---------- */
.sp-controls {
    position: relative;
    flex: 0 0 auto;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 6px 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sp-seek {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sp-time {
    flex: 0 0 auto;
    min-width: 3.2em;
    font-size: 16px;
    font-weight: 700;
    color: var(--sp-sub);
    font-variant-numeric: tabular-nums;
    text-align: center;
}

.sp-bar {
    position: relative;
    flex: 1 1 auto;
    height: 44px;
    cursor: pointer;
    touch-action: none;
}

.sp-bar-track {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 14px;
    margin-top: -7px;
    border-radius: 7px;
    background: var(--sp-track);
    overflow: hidden;
}

.sp-bar-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0%;
    background: linear-gradient(90deg, var(--sp-bar-a), var(--sp-bar-b));
}

.sp-bar-thumb {
    position: absolute;
    top: 50%;
    left: 0%;
    width: 26px;
    height: 26px;
    margin: -13px 0 0 -13px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 4px var(--sp-bar-a), 0 2px 6px rgba(0, 0, 0, 0.35);
    pointer-events: none;
}

.sp-bar.sp-bar-off {
    cursor: default;
    opacity: 0.55;
}

.sp-bar:focus-visible {
    outline: 3px solid var(--sp-bar-a);
    outline-offset: 2px;
    border-radius: 8px;
}

.sp-btns {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.sp-btn {
    min-width: 140px;
    min-height: 52px;
    padding: 0 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 800;
    line-height: 1.3;
    color: var(--sp-btn-text);
    background: var(--sp-btn-bg);
    border: 3px solid var(--sp-btn-border);
    border-radius: 999px;
    box-shadow: 0 4px 0 var(--sp-btn-shadow);
    cursor: pointer;
    touch-action: manipulation;
    white-space: nowrap;
}

.sp-btn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 var(--sp-btn-shadow);
}

.sp-btn:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}

.sp-btn:focus-visible,
.sp-big-play:focus-visible {
    outline: 4px solid var(--sp-bar-a);
    outline-offset: 3px;
}

.sp-btn.sp-primary {
    color: var(--sp-primary-text);
    background: var(--sp-primary-bg);
    border-color: var(--sp-primary-border);
    box-shadow: 0 4px 0 var(--sp-primary-shadow);
}

.sp-btn.sp-primary:active {
    box-shadow: 0 1px 0 var(--sp-primary-shadow);
}

.sp-ico {
    font-size: 1.15em;
    line-height: 1;
}

/* ---------- 再生の はやさ ---------- */
.sp-rate-val {
    font-variant-numeric: tabular-nums;
}

.sp-btn.sp-rate-changed {
    border-color: var(--sp-bar-b);
    box-shadow: 0 4px 0 var(--sp-btn-shadow), 0 0 0 3px var(--sp-bar-b);
}

.sp-rate-menu {
    position: absolute;
    right: 16px;
    bottom: calc(100% + 6px);
    z-index: 8000;
    width: min(380px, calc(100vw - 24px));
    padding: 12px;
    border-radius: 18px;
    background: #ffffff;
    color: #333333;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.sp-rate-title {
    margin: 0 0 8px;
    font-size: 15px;
    font-weight: 800;
    text-align: center;
    color: #2f6fb8;
}

.sp-rate-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.sp-rate-opt {
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    padding: 0 4px;
    border: 3px solid #c2dcf8;
    border-radius: 14px;
    background: #f4f8fd;
    color: #2f3a4a;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    touch-action: manipulation;
    white-space: nowrap;
    overflow: hidden;
}

.sp-rate-opt:active {
    transform: translateY(2px);
}

.sp-rate-opt.sp-rate-on {
    background: #4A90E2;
    border-color: #4A90E2;
    color: #ffffff;
}

.sp-rate-opt:focus-visible {
    outline: 3px solid #2f6fb8;
    outline-offset: 2px;
}

.sp-rate-note {
    background: rgba(255, 255, 255, 0.92);
    color: #2f3a4a;
}

/* ---------- せまい画面（スマホ たて など）：言語ボタンを ヘッダーの 下へ ---------- */
@media (max-width: 760px) and (min-height: 501px) {
    :root {
        --sp-safe-right: calc(12px + env(safe-area-inset-right, 0px));
    }

    .lang-slot {
        position: static;
        display: flex;
        justify-content: center;
        max-width: none;
        margin: 2px 8px 4px;
    }
}

/* ---------- はばが せまい 画面：ボタンを ならべて 入れる ---------- */
@media (max-width: 760px) {
    .sp-btns {
        gap: 8px;
        flex-wrap: wrap;
    }

    .sp-btn {
        min-width: 0;
        flex: 1 1 calc(50% - 8px);
        padding: 0 8px;
        font-size: 16px;
    }

    .sp-rate-menu {
        right: 12px;
    }

    .sp-time {
        font-size: 14px;
    }
}

/* ---------- 高さが ない 画面（スマホ よこ など）：操作を 1行に ---------- */
@media (max-height: 500px) {
    .sp-header {
        min-height: calc(64px + env(safe-area-inset-top, 0px));
        padding-top: calc(4px + env(safe-area-inset-top, 0px));
        padding-bottom: 2px;
    }

    .sp-title-main {
        font-size: 16px;
    }

    .sp-title-sub {
        display: none;
    }

    .sp-stage-area {
        padding: 2px 8px;
    }

    .sp-frame {
        border-width: 3px;
        border-radius: 10px;
    }

    .sp-controls {
        flex-direction: row;
        align-items: center;
        gap: 8px;
        padding: 4px 10px 6px;
        max-width: none;
    }

    .sp-seek {
        flex: 1 1 auto;
        min-width: 0;
        gap: 6px;
    }

    .sp-time {
        font-size: 13px;
        min-width: 2.8em;
    }

    .sp-btns {
        flex: 0 0 auto;
        gap: 6px;
    }

    .sp-btn {
        flex: 0 0 auto;
        min-width: 48px;
        min-height: 44px;
        padding: 0 12px;
        font-size: 15px;
    }

    .sp-btn .sp-lbl {
        display: none;
    }

    .sp-rate-menu {
        right: 10px;
        padding: 8px;
    }

    .sp-rate-title {
        margin-bottom: 6px;
        font-size: 13px;
    }

    .sp-rate-opt {
        min-height: 44px;
        font-size: 15px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .sp-spinner {
        animation-duration: 2.4s;
    }
}
