/* ==========================================================================
   そろばんれんしゅう (Soroban Learning App) Style System
   ========================================================================== */

:root {
    --primary-color: #ff6b6b;
    --primary-hover: #ff5252;
    --secondary-color: #4ecdc4;
    --accent-color: #ffe66d;
    --success-color: #2ed573;
    --error-color: #ff4757;
    --text-color: #2f3542;
    --bg-gradient-1: #e0c3fc;
    --bg-gradient-2: #8ec5fc;
    --card-bg: #ffffff;
    
    /* Soroban Specific Colors */
    --frame-wood-dark: #5c3a21;
    --frame-wood-light: #8b5a2b;
    --board-bg: #f7e6c4;
    --rod-color: #a88462;
    --bead-gradient-start: #f3a646;
    --bead-gradient-end: #d9741e;
    --bead-active-start: #ff7b25;
    --bead-active-end: #b33900;
    --beam-color: #4a2e18;

    --font-pop: 'Mochiy Pop One', 'Comic Sans MS', cursive, sans-serif;
    --font-sub: 'Yusei Magic', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-pop);
    background: linear-gradient(135deg, var(--bg-gradient-2) 0%, var(--bg-gradient-1) 100%);
    min-height: 100vh;
    min-height: 100dvh;
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px;
    overflow-x: hidden;
}

/* Confetti Canvas overlay */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9999;
}

/* App Container */
.app-container {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 28px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15), 0 5px 15px rgba(0, 0, 0, 0.08);
    width: 100%;
    max-width: 580px;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: relative;
    border: 4px solid #ffffff;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px dashed #e2e8f0;
    padding-bottom: 10px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    font-size: 2rem;
    animation: bounce 2s infinite alternate ease-in-out;
}

@keyframes bounce {
    0% { transform: translateY(0); }
    100% { transform: translateY(-6px); }
}

.app-title {
    font-size: 1.5rem;
    color: #3a4750;
    letter-spacing: 0.5px;
    text-shadow: 1px 1px 0px #ffffff;
}

.icon-btn {
    background: #f1f2f6;
    border: 2px solid #dfe4ea;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: #e4e7eb;
    transform: scale(1.08);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* Control Panel (Level selector & Stats) */
.control-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f8f9fa;
    padding: 10px 14px;
    border-radius: 16px;
    border: 2px solid #e9ecef;
}

.level-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: nowrap;
    width: 100%;
}

.level-selector .label {
    font-size: 0.85rem;
    color: #747d8c;
    white-space: nowrap;
}

.level-btn {
    background: #ffffff;
    border: 2px solid #ced6e0;
    color: #57606f;
    font-family: var(--font-pop);
    font-size: 0.82rem;
    padding: 4px 10px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.level-btn:hover {
    border-color: var(--secondary-color);
    color: var(--secondary-color);
}

.level-btn.active {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
    color: #ffffff;
    box-shadow: 0 3px 8px rgba(78, 205, 196, 0.4);
}

.stats-bar {
    display: flex;
    gap: 16px;
    justify-content: center;
    width: 100%;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85rem;
    background: #ffffff;
    padding: 3px 10px;
    border-radius: 12px;
    box-shadow: inset 0 0 0 1px #e2e8f0;
    white-space: nowrap; /* Prevents vertical text wrapping */
    flex-shrink: 0;
}

.stat-icon {
    font-size: 1rem;
}

.stat-label {
    white-space: nowrap;
}

/* Main Content Area */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Question Card */
.question-card {
    background: linear-gradient(135deg, #fff9db 0%, #fff3bf 100%);
    border: 3px dashed #fcc419;
    border-radius: 18px;
    padding: 12px 16px;
    text-align: center;
    position: relative;
    box-shadow: 0 6px 12px rgba(252, 196, 25, 0.15);
}

.question-badge {
    position: absolute;
    top: -11px;
    left: 20px;
    background: #fcc419;
    color: #5c3a21;
    font-size: 0.75rem;
    padding: 2px 10px;
    border-radius: 10px;
}

.question-text {
    font-size: 1.8rem;
    color: #2b2d42;
    letter-spacing: 1px;
    margin-top: 2px;
}

/* Soroban Wrapper */
.soroban-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

/* Place Values Header */
.place-values {
    display: flex;
    justify-content: space-around;
    width: 100%;
    max-width: 480px;
    padding: 0 20px;
    margin-bottom: 3px;
}

.pv-item {
    font-size: 0.9rem;
    background: #eccc68;
    color: #fff;
    width: 34px;
    height: 22px;
    border-radius: 8px 8px 0 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    box-shadow: inset 0 -2px 0 rgba(0,0,0,0.1);
}

/* Soroban Board */
.soroban-board {
    background: var(--board-bg);
    border: 10px solid var(--frame-wood-dark);
    border-radius: 16px;
    padding: 10px 18px;
    display: flex;
    justify-content: space-around;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35), inset 0 0 20px rgba(0, 0, 0, 0.15);
    position: relative;
    user-select: none;
}

/* The Beam (梁) */
.soroban-board::before {
    content: '';
    position: absolute;
    top: 50px;
    left: 0;
    right: 0;
    height: 11px;
    background: linear-gradient(to bottom, #5c3a21, #3a2211);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4);
    z-index: 10;
}

/* Rod (桁) - Centered Container */
.rod {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 8px;
    background-color: var(--rod-color);
    height: 180px;
    position: relative;
    border-radius: 4px;
    box-shadow: inset 1px 0 3px rgba(0,0,0,0.4);
    touch-action: manipulation;
}

/* Positioning Point (定位置 / 点) on beam */
.rod.positioning-point::after {
    content: '';
    position: absolute;
    top: 45px; /* Center on beam */
    left: 50%;
    transform: translate(-50%, -50%);
    width: 5px;
    height: 5px;
    background-color: #ffffff;
    border-radius: 50%;
    z-index: 15;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.8);
}

/* Bead (玉) - Perfectly Centered on Rod */
.bead {
    width: 50px;
    height: 22px;
    background: linear-gradient(to bottom, var(--bead-gradient-start), var(--bead-gradient-end));
    border: 1px solid #7a4212;
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
    cursor: pointer;
    transition: transform 0.18s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: 20;
    position: relative;
    flex-shrink: 0;
}

.bead.active {
    background: linear-gradient(to bottom, var(--bead-active-start), var(--bead-active-end));
}

.heaven-bead {
    margin-top: 2px;
}

/* Heaven bead touches beam when active */
.heaven-bead.active {
    transform: translateY(18px);
}

.earth-beads {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    margin-top: 46px; /* Gap below beam */
    gap: 2px;
}

/* Earth beads slide UP towards beam when active */
.earth-bead.active {
    transform: translateY(-30px);
}

/* Live Soroban Value Display */
.soroban-value-display {
    margin-top: 6px;
    font-size: 0.9rem;
    color: #57606f;
    background: #f1f2f6;
    padding: 3px 14px;
    border-radius: 12px;
}

.soroban-value-display span {
    color: var(--primary-color);
    font-size: 1.05rem;
    font-weight: bold;
}

/* Result Feedback Area */
.result-area {
    background: #ffffff;
    border-radius: 16px;
    padding: 12px 14px;
    text-align: center;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
    border: 2px solid #e2e8f0;
}

.result-area.hidden {
    display: none;
}

.result-area.correct-style {
    background: #e6fffa;
    border-color: #38b2ac;
}

.result-area.incorrect-style {
    background: #fff5f5;
    border-color: #feb2b2;
}

.result-badge {
    font-size: 1.3rem;
}

.result-detail {
    font-size: 0.95rem;
    color: #4a5568;
}

.countdown-bar-container {
    width: 100%;
    max-width: 260px;
    height: 7px;
    background: #edf2f7;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 2px;
}

.countdown-bar {
    height: 100%;
    width: 100%;
    background: var(--secondary-color);
    transition: width 3s linear;
}

.countdown-text {
    font-size: 0.78rem;
    color: #a0aec0;
}

/* Button Area */
.button-area {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.btn {
    font-family: var(--font-pop);
    font-size: 1rem;
    padding: 10px 20px;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.btn:active {
    transform: scale(0.95);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-check {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5253 100%);
    color: #ffffff;
    font-size: 1.15rem;
    padding: 12px 28px;
}

.btn-check:hover:not(:disabled) {
    box-shadow: 0 6px 16px rgba(255, 107, 107, 0.4);
    transform: translateY(-2px);
}

.btn-clear {
    background: #f1f2f6;
    color: #57606f;
    border: 2px solid #dfe4ea;
}

.btn-clear:hover {
    background: #e4e7eb;
}

.btn-next {
    background: linear-gradient(135deg, #2ed573 0%, #26af5f 100%);
    color: #ffffff;
}

.btn-next:hover {
    box-shadow: 0 6px 16px rgba(46, 213, 115, 0.4);
    transform: translateY(-2px);
}

/* ==========================================================================
   Responsive Smartphone Design (Balanced & Roomy without Vertical Wrapping)
   ========================================================================== */
@media (max-width: 600px) {
    body {
        padding: 6px;
        align-items: flex-start;
    }

    .app-container {
        padding: 14px 16px;
        border-radius: 20px;
        gap: 10px;
        max-width: 100%;
    }
    
    .app-header {
        padding-bottom: 6px;
    }

    .logo-icon {
        font-size: 1.5rem;
    }

    .app-title {
        font-size: 1.25rem;
    }

    .icon-btn {
        width: 36px;
        height: 36px;
        font-size: 1.05rem;
    }

    .control-panel {
        padding: 8px 10px;
        gap: 6px;
    }

    .level-selector {
        gap: 4px;
    }

    .level-selector .label {
        font-size: 0.8rem;
    }

    .level-btn {
        font-size: 0.78rem;
        padding: 3px 8px;
    }

    .stats-bar {
        gap: 12px;
    }

    .stat-item {
        font-size: 0.8rem;
        padding: 3px 8px;
        white-space: nowrap;
    }

    .main-content {
        gap: 10px;
    }

    .question-card {
        padding: 10px 12px;
        border-radius: 14px;
    }

    .question-text {
        font-size: 1.45rem;
    }

    .place-values {
        padding: 0 12px;
    }
    
    .pv-item {
        width: 28px;
        height: 18px;
        font-size: 0.78rem;
    }

    .soroban-board {
        padding: 8px 12px;
        border-width: 8px;
        border-radius: 14px;
    }

    .soroban-board::before {
        top: 42px;
        height: 9px;
    }

    .rod {
        height: 150px;
        width: 7px;
    }

    .rod.positioning-point::after {
        top: 38px;
        width: 4px;
        height: 4px;
    }

    .bead {
        width: 42px;
        height: 18px;
    }

    .heaven-bead {
        margin-top: 1px;
    }

    .heaven-bead.active {
        transform: translateY(15px);
    }

    .earth-beads {
        margin-top: 38px;
        gap: 1px;
    }

    .earth-bead.active {
        transform: translateY(-25px);
    }

    .soroban-value-display {
        margin-top: 4px;
        font-size: 0.85rem;
        padding: 2px 10px;
    }

    .result-area {
        padding: 8px 12px;
        border-radius: 12px;
        gap: 4px;
    }

    .result-badge {
        font-size: 1.15rem;
    }

    .result-detail {
        font-size: 0.88rem;
    }

    .button-area {
        gap: 8px;
        margin-top: 2px;
    }

    .btn {
        font-size: 0.9rem;
        padding: 8px 16px;
    }

    .btn-check {
        font-size: 1rem;
        padding: 10px 22px;
    }
}