/* ============================================
   Tutorial Specific Styles
   ============================================ */
:root {
    --tut-bg: #e0f7fa;
    --tut-text: #37474f;
    --tut-card: rgba(255, 255, 255, 0.95);
    --tut-accent: #00acc1;
    --tut-grid-border: #00838f;
    --tut-cell-border: rgba(0, 131, 143, 0.3);

    /* Animation Colors */
    --highlight-row: rgba(33, 150, 243, 0.3);
    /* Blue */
    --highlight-col: rgba(244, 67, 54, 0.3);
    /* Red */
    --highlight-block: rgba(76, 175, 80, 0.3);
    /* Green */
    --highlight-beam: rgba(255, 152, 0, 0.4);
    /* Orange */
}

body.tutorial-mode {
    background: var(--tut-bg);
    color: var(--tut-text);
    font-family: 'Noto Sans JP', sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: hidden;
}

.tutorial-container {
    width: 90%;
    max-width: 800px;
    height: 85vh;
    background: var(--tut-card);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    border: 2px solid var(--tut-accent);
}

.tutorial-header {
    padding: 20px;
    text-align: center;
    border-bottom: 2px solid rgba(0, 172, 193, 0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tutorial-header h1 {
    font-family: 'Orbitron', sans-serif;
    color: var(--tut-accent);
    margin: 0;
    font-size: 1.8rem;
    flex-grow: 1;
}

.close-btn {
    text-decoration: none;
    color: var(--tut-text);
    font-weight: bold;
    padding: 8px 16px;
    border: 2px solid var(--tut-text);
    border-radius: 20px;
    transition: all 0.3s;
}

.close-btn:hover {
    background: var(--tut-text);
    color: #fff;
}

/* Slides Container */
.slides {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
}

.slide {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    padding: 20px 40px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease-in-out, visibility 0.5s;
    pointer-events: none;
}

.slide.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    z-index: 10;
}

/* Visual Area */
.visual-area {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
    flex: 0 1 65%;
    /* 画像エリアを拡大 */
    min-height: 250px;
    overflow: hidden;
}

/* Text Area */
.text-area {
    flex: 1 1 30%;
    /* テキストエリアを現在の約8割（40%->30%）に縮小 */
    background: rgba(0, 172, 193, 0.05);
    padding: 15px 20px;
    border-radius: 12px;
    border-left: 4px solid var(--tut-accent);
    overflow-y: auto;
    min-height: 0;
    /* Flexコンテナ内での縮小を許可して重なりを防ぐ */
}

.text-area h2 {
    color: var(--tut-accent);
    margin-top: 0;
    font-size: 1.4rem;
    margin-bottom: 12px;
}

.text-area p {
    line-height: 1.8;
    font-size: 1.1rem;
    margin-bottom: 10px;
}

/* Mini Sudoku Board for Visuals */
.tut-board {
    display: grid;
    grid-template-columns: repeat(9, 30px);
    grid-template-rows: repeat(9, 30px);
    gap: 1px;
    background: var(--tut-grid-border);
    border: 3px solid var(--tut-grid-border);
    padding: 2px;
    border-radius: 4px;
}

.tut-cell {
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--tut-text);
    position: relative;
    transition: background 0.5s;
}

/* 3x3 Block Thicker Borders (Scoped to Sudoku 9x9) */
.sudoku-board .tut-cell:nth-child(3n) {
    border-right: 2px solid var(--tut-grid-border);
}

.sudoku-board .tut-cell:nth-child(9n) {
    border-right: none;
}

.sudoku-board .tut-cell:nth-child(n+19):nth-child(-n+27),
.sudoku-board .tut-cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 2px solid var(--tut-grid-border);
}


/* --- ANIMATION CLASSES (Toggled by JS) --- */

/* Slide 2: Rules */
.tut-board.anim-rules .tut-cell.row-2 {
    animation: pulseBgRow 3s infinite;
}

.tut-board.anim-rules .tut-cell.col-3 {
    animation: pulseBgCol 3s infinite 1s;
}

.tut-board.anim-rules .tut-cell.block-5 {
    animation: pulseBgBlock 3s infinite 2s;
}

@keyframes pulseBgRow {

    0%,
    100% {
        background: #fff;
    }

    50% {
        background: var(--highlight-row);
    }
}

@keyframes pulseBgCol {

    0%,
    100% {
        background: #fff;
    }

    50% {
        background: var(--highlight-col);
    }
}

@keyframes pulseBgBlock {

    0%,
    100% {
        background: #fff;
    }

    50% {
        background: var(--highlight-block);
    }
}

/* Slide 3: Beam (Elimination) */
.tut-board.anim-beam .tut-cell.beam-source {
    background: #FFD700;
    /* Gold */
    box-shadow: 0 0 10px #FFD700;
    z-index: 2;
}

.tut-board.anim-beam .tut-cell.beam-path {
    animation: beamShoot 4s infinite;
}

.tut-board.anim-beam .tut-cell.target-cell {
    animation: targetPop 4s infinite;
}

.tut-board.anim-beam .tut-cell.target-cell::after {
    content: '1';
    color: var(--tut-accent);
    opacity: 0;
    animation: textFadeIn 4s infinite;
}

@keyframes beamShoot {

    0%,
    15% {
        background: #fff;
    }

    25%,
    75% {
        background: var(--highlight-beam);
    }

    85%,
    100% {
        background: #fff;
    }
}

@keyframes targetPop {

    0%,
    75% {
        background: #fff;
        transform: scale(1);
    }

    80% {
        background: rgba(0, 230, 118, 0.4);
        transform: scale(1.1);
        box-shadow: 0 0 15px rgba(0, 230, 118, 0.8);
        z-index: 5;
    }

    90%,
    100% {
        background: rgba(0, 230, 118, 0.4);
        transform: scale(1);
    }
}

@keyframes textFadeIn {

    0%,
    75% {
        opacity: 0;
    }

    80%,
    100% {
        opacity: 1;
    }
}

/* Slide 4: Where to start (Full Block) */
.tut-board.anim-start .tut-cell.full-block {
    animation: pulseGood 2s infinite;
}

@keyframes pulseGood {

    0%,
    100% {
        background: rgba(3, 169, 244, 0.1);
    }

    50% {
        background: rgba(3, 169, 244, 0.3);
    }
}

/* Controls */
.tutorial-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 40px;
    background: #fff;
    border-top: 1px solid #eee;
}

.nav-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-btn.prev {
    background: #e0e0e0;
    color: #555;
}

.nav-btn.prev:hover {
    background: #d5d5d5;
}

.nav-btn.prev:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.nav-btn.next {
    background: var(--tut-accent);
    color: white;
    box-shadow: 0 4px 10px rgba(0, 172, 193, 0.3);
}

.nav-btn.next:hover {
    background: var(--green-bright, #26c6da);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0, 172, 193, 0.4);
}

.progress-dots {
    display: flex;
    gap: 8px;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ccc;
    transition: all 0.3s;
}

.dot.active {
    background: var(--tut-accent);
    transform: scale(1.3);
}

/* Final CTA */
.cta-btn {
    display: inline-block;
    margin-top: 20px;
    padding: 15px 40px;
    background: linear-gradient(135deg, #FFD700, #FFAB00);
    color: #5d4037;
    text-decoration: none;
    font-size: 1.2rem;
    font-weight: 900;
    border-radius: 30px;
    box-shadow: 0 5px 15px rgba(255, 171, 0, 0.4);
    transition: transform 0.2s;
}

.cta-btn:hover {
    transform: scale(1.05);
}

/* ============================================
   Skyscraper Tutorial Specific Styles
   ============================================ */

.tut-board.sky-board {
    grid-template-columns: repeat(6, 35px);
    grid-template-rows: repeat(6, 35px);
    gap: 2px;
    background: transparent;
    border: none;
    padding: 0;
}

.sky-board .tut-cell {
    border-radius: 4px;
    transition: all 0.5s;
}

.sky-board .inner-cell {
    background: #fff;
    border: 2px solid var(--tut-grid-border);
}

.sky-board .clue-cell {
    background: transparent;
    color: var(--tut-accent);
    font-size: 1rem;
}

.sky-board .corner-cell {
    visibility: hidden;
}

/* Sky Slide 2: Rules */
.tut-board.anim-sky-rules .example-row {
    animation: skyRowFlash 3s infinite;
}

@keyframes skyRowFlash {

    0%,
    100% {
        background: #fff;
        transform: scale(1);
    }

    50% {
        background: var(--highlight-row);
        transform: scale(1.1);
        box-shadow: 0 0 10px var(--highlight-row);
        z-index: 2;
    }
}

/* Sky Slide 3: Concept (Viewing lines) */
.tut-board.anim-sky-beam .focus-clue {
    animation: cluePulse 4s infinite;
}

.tut-board.anim-sky-beam .visible-building {
    background: #fff;
    animation: buildingReveal 4s infinite;
}

.tut-board.anim-sky-beam .hidden-building {
    background: #fff;
    animation: buildingHidden 4s infinite;
}

/* Simulate height differences with scaling or text-shadow */
.building-val-1 {
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.1);
}

.building-val-2 {
    box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.1);
}

.building-val-3 {
    box-shadow: inset 0 -12px 0 rgba(0, 0, 0, 0.1);
}

.building-val-4 {
    box-shadow: inset 0 -16px 0 rgba(0, 0, 0, 0.1);
}

@keyframes cluePulse {

    0%,
    10% {
        transform: scale(1);
        color: var(--tut-accent);
    }

    15%,
    85% {
        transform: scale(1.3);
        color: #FF9800;
        text-shadow: 0 0 10px #FF9800;
    }

    90%,
    100% {
        transform: scale(1);
        color: var(--tut-accent);
    }
}

@keyframes buildingReveal {

    0%,
    20% {
        background: #fff;
        border-color: var(--tut-grid-border);
    }

    25%,
    80% {
        background: rgba(76, 175, 80, 0.2);
        border-color: #4CAF50;
        transform: translateY(-2px);
    }

    85%,
    100% {
        background: #fff;
        border-color: var(--tut-grid-border);
    }
}

@keyframes buildingHidden {

    0%,
    40% {
        background: #fff;
        color: var(--tut-text);
    }

    45%,
    80% {
        background: #eceff1;
        color: #b0bec5;
    }

    /* Darkened/greyed out */
    85%,
    100% {
        background: #fff;
        color: var(--tut-text);
    }
}

/* Sky Slide 4: Tips */
.tut-board.anim-sky-tips .clue-tip-1 {
    animation: tipHighlight1 3s infinite;
}

.tut-board.anim-sky-tips .clue-tip-4 {
    animation: tipHighlight4 3s infinite 1.5s;
}

.tut-board.anim-sky-tips .ans-1 {
    opacity: 0;
    animation: ansFade1 3s infinite;
    color: #4CAF50;
}

.tut-board.anim-sky-tips .ans-4 {
    opacity: 0;
    animation: ansFade4 3s infinite 1.5s;
    color: #2196F3;
}

@keyframes tipHighlight1 {

    0%,
    40%,
    100% {
        color: var(--tut-accent);
        transform: scale(1);
    }

    10%,
    30% {
        color: #4CAF50;
        transform: scale(1.3);
        text-shadow: 0 0 10px #4CAF50;
    }
}

@keyframes tipHighlight4 {

    0%,
    40%,
    100% {
        color: var(--tut-accent);
        transform: scale(1);
    }

    10%,
    30% {
        color: #2196F3;
        transform: scale(1.3);
        text-shadow: 0 0 10px #2196F3;
    }
}

@keyframes ansFade1 {

    0%,
    5%,
    45%,
    100% {
        opacity: 0;
        transform: scale(0.8);
    }

    15%,
    35% {
        opacity: 1;
        transform: scale(1.1);
        font-weight: 900;
    }
}

/* ============================================
   Image-based Tutorial Styles
   ============================================ */

.visual-area.image-slide {
    position: relative;
    max-width: 600px;
    width: 100%;
    margin: 0 auto 15px auto;
    line-height: 0;
    display: flex;
    /* 中央揃えのためにFlexに戻す */
    align-items: center;
    justify-content: center;
    height: 100%;
    /* 親の50%枠いっぱいに広げる */
}

.visual-area.image-slide img {
    max-width: 100%;
    max-height: 100%;
    /* 親要素の高さ制限に合わせる */
    object-fit: contain;
    /* アスペクト比を維持 */
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.highlight-box {
    position: absolute;
    box-sizing: border-box;
    border: 4px solid;
    border-radius: 4px;
    pointer-events: none;
    z-index: 100;
}

.highlight-box.blue {
    border-color: #00bcd4;
    box-shadow: 0 0 15px rgba(0, 188, 212, 0.6);
}

.highlight-box.red {
    border-color: #ff5252;
    box-shadow: 0 0 15px rgba(255, 82, 82, 0.6);
}

.highlight-box.yellow {
    border-color: #FFD700;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
}

/* Specific animations for highlights if needed */
.highlight-box {
    animation: boxPulse 2s infinite;
}

@keyframes boxPulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.8;
        transform: scale(1.02);
    }
}

/* ============================================
   TowerFill Tutorial Specific Styles
   ============================================ */

.tut-board.tower-board {
    grid-template-columns: repeat(11, 28px);
    /* 11 cells total */
    grid-template-rows: repeat(11, 28px);
    gap: 1px;
    background: transparent;
    border: none;
    padding: 0;
}

.tower-board .tut-cell {
    border-radius: 2px;
}

.tower-board .inner-cell {
    background: #fff;
    border: 1px solid var(--tut-grid-border);
}

.tower-board .clue-cell {
    background: transparent;
    color: var(--tut-accent);
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tower-board .corner-cell {
    visibility: hidden;
}

/* 3x3 block borders in 11x11 tut-board (offset by 1) */
.tower-board .inner-cell.block-start-row {
    border-top: 2px solid var(--tut-grid-border);
}

.tower-board .inner-cell.block-start-col {
    border-left: 2px solid var(--tut-grid-border);
}

/* Tower Slide 2: Rules */
.tut-board.anim-tower-rules .highlight-sudoku {
    animation: sudokuFlash 3s infinite;
}

.tut-board.anim-tower-rules .highlight-shadow {
    animation: shadowFlash 3s infinite 1.5s;
}

@keyframes sudokuFlash {

    0%,
    100% {
        background: #fff;
    }

    50% {
        background: var(--highlight-block);
    }
}

@keyframes shadowFlash {

    0%,
    100% {
        color: var(--tut-accent);
    }

    50% {
        color: #FF9800;
        transform: scale(1.2);
    }
}

/* Slide 3: Concept (Shadow clues) */
.tut-board.anim-tower-concept .clue-9 {
    animation: clue9Pulse 4s infinite;
}

.tut-board.anim-tower-concept .ans-9 {
    opacity: 0;
    animation: ans9Fade 4s infinite;
    color: #4CAF50;
}

@keyframes clue9Pulse {

    0%,
    15% {
        transform: scale(1);
        color: var(--tut-accent);
    }

    20%,
    80% {
        transform: scale(1.4);
        color: #FF9800;
        font-weight: 900;
    }

    85%,
    100% {
        transform: scale(1);
        color: var(--tut-accent);
    }
}

@keyframes ans9Fade {

    0%,
    20% {
        opacity: 0;
        transform: scale(0.5);
    }

    30%,
    80% {
        opacity: 1;
        transform: scale(1.1);
        font-weight: 900;
    }

    85%,
    100% {
        opacity: 0;
    }
}

@media (max-width: 600px) {
    .tut-board.tower-board {
        grid-template-columns: repeat(11, 24px);
        grid-template-rows: repeat(11, 24px);
    }
}

@keyframes ansFade4 {

    0%,
    5%,
    45%,
    100% {
        opacity: 0;
        transform: scale(0.8);
    }

    15%,
    35% {
        opacity: 1;
        transform: scale(1.1);
        font-weight: 900;
    }
}

/* --- nextBtn text toggle rules --- */
#nextBtn .text-finish {
    display: none;
}
#nextBtn .text-next {
    display: inline;
}
.tutorial-container.is-last-slide #nextBtn .text-next {
    display: none;
}
.tutorial-container.is-last-slide #nextBtn .text-finish {
    display: inline;
}