/* ==========================================================
   ダウンロードの待ち・完了の画面（assets/js/download-sheet.js）
   見た目は prototypes/download-flow-mock の「A キャンディ」。
   完了は横長の画面で左右2列（学校のノートPCは縦が600px前後しかない）、縦長では1列でスクロール。
   ========================================================== */

.sdl {
    position: fixed;
    inset: 0;
    z-index: 1500; /* 素材のプレビュー（1000）より上、トースト（2000）より下 */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    font-family: inherit;
    color: #2b2b3a;
    line-height: 1.5;
}

.sdl ruby { ruby-align: center; }
.sdl rt { font-size: 0.5em; font-weight: 700; }

.sdl-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(40, 16, 48, 0.45);
    animation: sdl-fade 0.2s ease-out both;
}

.sdl-card {
    position: relative;
    width: min(540px, 100%);
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    overflow: auto;
    overscroll-behavior: contain;
    background: #fff;
    border-radius: 30px;
    box-shadow: 0 0 0 6px #ffd5e6, 0 24px 60px rgba(0, 0, 0, 0.35);
    animation: sdl-up 0.35s cubic-bezier(0.2, 1.2, 0.4, 1) both;
    outline: none;
}

.sdl-card.is-done { width: min(800px, 100%); }

@keyframes sdl-fade { from { opacity: 0; } }
@keyframes sdl-up { from { transform: translateY(24px) scale(0.96); opacity: 0; } }

.sdl-x {
    position: absolute;
    right: 14px;
    top: 12px;
    z-index: 2;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    color: #8a7b88;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.sdl-x:hover { background: #fff; color: #4a3b48; }

/* ---------- 上（素材の見本と題） ---------- */

.sdl-head {
    position: relative;
    padding: 30px 24px 24px;
    text-align: center;
    background: linear-gradient(160deg, #ffe2ef, #fff4d2);
}

.sdl-head.is-done { background: linear-gradient(160deg, #d7f8ec, #e4f3ff); }

.sdl-tile {
    position: relative;
    width: 132px;
    height: 132px;
    margin: 0 auto;
    border-radius: 26px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px rgba(60, 30, 80, 0.16);
}

.sdl-thumb {
    max-width: 84%;
    max-height: 84%;
    object-fit: contain;
}

.sdl-aud {
    width: 100%;
    height: 100%;
    border-radius: 26px;
    background: linear-gradient(135deg, #ffb15c, #ff7a3d);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sdl-aud svg { width: 58%; height: 58%; }

.sdl-tile.is-wait { animation: sdl-bob 1.4s ease-in-out infinite; }

.sdl-tile.is-wait::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.75) 50%, transparent 70%);
    background-size: 250% 100%;
    animation: sdl-shine 1.6s linear infinite;
}

@keyframes sdl-bob { 50% { transform: translateY(-6px); } }
@keyframes sdl-shine { from { background-position: 120% 0; } to { background-position: -120% 0; } }

.sdl-check {
    position: absolute;
    right: -14px;
    top: -14px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 4px #fff, 0 6px 14px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: sdl-pop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1) both;
}

.sdl-check svg { width: 26px; height: 26px; }

@keyframes sdl-pop { from { transform: scale(0); } }

.sdl-spark {
    position: absolute;
    width: 38px;
    pointer-events: none;
    opacity: 0;
    animation: sdl-twinkle 1s ease-out both;
}

@keyframes sdl-twinkle {
    0% { transform: scale(0) rotate(0); opacity: 0; }
    40% { opacity: 1; }
    100% { transform: scale(1) rotate(25deg); opacity: 0; }
}

.sdl-title {
    margin: 18px 0 4px;
    font-size: 22px;
    font-weight: 900;
    color: #3d2440;
    line-height: 1.6;
}

.sdl-head.is-done .sdl-title { font-size: 27px; color: #17463f; }

.sdl-sub { margin: 0; font-size: 13px; color: #7a6178; }

/* キャンディのしましまの進みバー */
.sdl-candy {
    position: relative;
    height: 24px;
    max-width: 340px;
    margin: 16px auto 0;
    border-radius: 999px;
    background: #fff;
    box-shadow: inset 0 0 0 3px #ffc2da, inset 0 3px 6px rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

.sdl-candy i {
    position: absolute;
    left: 3px;
    top: 3px;
    bottom: 3px;
    width: 0;
    max-width: calc(100% - 6px);
    min-width: 18px;
    border-radius: 999px;
    background: repeating-linear-gradient(-45deg, #ff6fa8 0 10px, #ffa6ca 10px 20px);
    background-size: 28.28px 28.28px;
    animation: sdl-stripes 0.7s linear infinite;
    transition: width 0.25s;
}

@keyframes sdl-stripes { to { background-position: 28.28px 0; } }

.sdl-pct {
    margin-top: 6px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: #a0789a;
}

.sdl-cancel {
    margin-top: 10px;
    border: 0;
    background: none;
    color: #8f7a8c;
    font-size: 13px;
    text-decoration: underline;
    cursor: pointer;
}

.sdl-file {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    margin-top: 10px;
    padding: 6px 14px;
    border-radius: 999px;
    background: #fff;
    box-shadow: 0 0 0 2px #bfeee0 inset;
    font-size: 13px;
    font-weight: 700;
    color: #2f5d57;
}

.sdl-file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sdl-where { margin: 6px 0 0; font-size: 12px; color: #4f7d76; }

/* ブラウザが保存を止めたとき、子どもが押して保存し直す（受け取った Blob を画面を閉じるまで残してある） */
.sdl-resave {
    display: inline-block;
    margin-top: 6px;
    font-size: 11.5px;
    color: #3d7f9e;
    text-decoration: underline;
}

/* ---------- 下（使い方とボタン） ---------- */

.sdl-body { padding: 18px 22px 20px; background: #fbf9fd; }

.sdl-how { margin: 0 0 8px; font-size: 15px; font-weight: 700; color: #4b4b5e; }

.sdl-steps {
    display: grid;
    gap: 7px;
    margin: 0;
    padding: 0;
    list-style: none;
}

/* 文はかならず span 1つにまとめてある（grid の直下にルビとテキストを置くと別々のマスに割れる） */
.sdl-steps li {
    display: grid;
    grid-template-columns: 30px 1fr;
    column-gap: 10px;
    align-items: center;
    padding: 8px 12px;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 2px 0 #e7e2ef, 0 0 0 2px #f1edf6 inset;
    font-size: 14.5px;
    font-weight: 700;
    line-height: 1.5;
    text-align: left;
}

.sdl-steps li small {
    grid-column: 2;
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: #6c6c80;
    line-height: 1.45;
}

.sdl-steps em { font-style: normal; color: #d6336c; }

.sdl-n {
    grid-row: span 2;
    align-self: start;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin-top: 2px;
    border-radius: 50%;
    color: #fff;
    font-size: 15px;
    font-weight: 900;
}

.sdl-steps li:nth-child(1) .sdl-n { background: #ff6fa8; }
.sdl-steps li:nth-child(2) .sdl-n { background: #ffb31f; }
.sdl-steps li:nth-child(3) .sdl-n { background: #1fbfb1; }

.sdl-tip { margin: 10px 0 0; font-size: 12.5px; color: #5d5a70; }

.sdl-main {
    display: block;
    width: 100%;
    margin-top: 16px;
    padding: 15px;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(180deg, #2fd3c5, #14ab9f);
    box-shadow: 0 4px 0 #0f8a80;
    color: #fff;
    font-family: inherit;
    font-size: 18px;
    font-weight: 800;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
}

.sdl-main:hover { filter: brightness(1.05); color: #fff; }
.sdl-main:active { transform: translateY(3px); box-shadow: 0 1px 0 #0f8a80; }

.sdl-sub-link {
    display: block;
    width: fit-content;
    margin: 10px auto 0;
    border: 0;
    background: none;
    color: #2b7fc9;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.sdl-sub-link:hover { text-decoration: underline; }

.sdl-note { margin: 8px 0 0; font-size: 12px; color: #8a7b88; text-align: center; }

.sdl-err {
    margin: 0 0 4px;
    padding: 10px 14px;
    border-radius: 12px;
    background: #fff1f1;
    color: #b4232c;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.6;
    text-align: center;
}

/* コードブレイバーの案内（ログインしていない子だけ） */
.sdl-promo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    background: #fff7d6;
    border-top: 2px dashed #ffe08a;
}

.sdl-promo img { width: 58px; height: 58px; flex: none; object-fit: contain; }

.sdl-promo p {
    flex: 1;
    margin: 0;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.5;
    color: #5b4a1f;
}

.sdl-promo a {
    flex: none;
    padding: 8px 14px;
    border-radius: 999px;
    background: #fff;
    box-shadow: 0 0 0 2px #ffcf6b inset;
    color: #e2660f;
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
}

/* ---------- 横長の画面: 完了は左右2列 ---------- */
@media (min-width: 720px) {
    .sdl-split { display: grid; grid-template-columns: 290px 1fr; }
    .sdl-split .sdl-head {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 30px 18px 24px;
    }
    .sdl-split .sdl-body { padding: 22px 24px 20px; }
}

/* ---------- 狭い画面 ---------- */
@media (max-width: 480px) {
    .sdl { padding: 8px; }
    .sdl-card { border-radius: 24px; max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); }
    .sdl-head { padding: 26px 16px 18px; }
    .sdl-tile { width: 100px; height: 100px; border-radius: 22px; }
    .sdl-aud { border-radius: 22px; }
    .sdl-head.is-done .sdl-title { font-size: 23px; margin-top: 12px; }
    .sdl-body { padding: 16px 14px 18px; }
    .sdl-promo { flex-wrap: wrap; }
    .sdl-promo a { width: 100%; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
    .sdl-card,
    .sdl-backdrop,
    .sdl-tile.is-wait,
    .sdl-tile.is-wait::after,
    .sdl-check,
    .sdl-spark,
    .sdl-candy i { animation: none; }
    .sdl-spark { display: none; }
}
