:root {
    --main-blue: #00A0E9;
    --light-blue: #E1F3FB;
    --main-yellow: #FFD200;
    --light-yellow: #FFF9E6;
    --main-pink: #FF8EB2;
    --text-color: #333333;
    --bg-gray: #F9F9F9;
    --border-color: #E6E6E6;
    --white: #FFFFFF;
    --radius-lg: 20px;
    --shadow: 0 8px 20px rgba(0,0,0,0.05);
    --drum-w: 80px;
    --drum-h: 100px;
    --item-h: 40px;
}

body {
    font-family: 'M PLUS Rounded 1c', sans-serif;
    background-color: var(--bg-gray);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100dvh;
    margin: 0;
    padding: 20px 0;
    overflow-x: hidden;
    overflow-y: auto;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
    touch-action: manipulation;
}

.container {
    background: none;
    box-shadow: none;
    border-radius: 0;
    padding: 25px 20px;
    text-align: center;
    width: 95%;
    max-width: 800px;
    height: auto;
    min-height: min-content;
    position: relative;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 15px;
    margin: 0 auto;
}

h1 {
    font-size: 1.5rem;
    color: var(--main-blue);
    margin: 0;
    font-weight: 900;
    flex-shrink: 0;
}

.top-controls-row {
    display: flex;
    flex-direction: row;
    gap: 12px;
    margin-bottom: 10px;
    align-items: stretch;
}

.selector-wrapper, .step-wrapper {
    border: 2px dashed #BDE3F7;
    border-radius: var(--radius-lg);
    padding: 48px 10px 15px;
    position: relative;
    flex: 1;
    margin-bottom: 0;
}
.selector-wrapper { background-color: #F0F9FF; border-color: #BDE3F7; }
.step-wrapper { background-color: #FFF0F5; border-color: #FFD1DF; }

.selector-label, .step-label {
    position: absolute;
    top: -2px;
    left: -2px;
    width: calc(100% + 4px);
    background: var(--main-blue);
    color: white;
    font-size: 0.75rem;
    font-weight: 900;
    padding: 6px 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    z-index: 10;
    text-align: center;
    box-sizing: border-box;
}
.step-label { background: var(--main-pink); }

.main-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    margin-top: 20px;
}

.column-left {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.activity-selector, .step-controls {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.activity-btn, .mode-btn {
    font-size: 0.9rem !important;
    padding: 6px 14px !important;
    border-radius: 20px !important;
    background: #eee;
    border: 2px solid #ddd !important;
    color: #666;
    cursor: pointer;
    min-width: 100px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    box-sizing: border-box;
}
.mode-btn .btn-num {
    font-size: 0.9rem;
    font-weight: 900;
    display: inline;
    margin-right: 2px;
}

.activity-btn.active { background: var(--main-blue) !important; color: var(--white) !important; border-color: #0086c4 !important; }
.mode-btn.active { background: var(--main-pink) !important; color: var(--white) !important; border-color: #ff6699 !important; }

@media screen and (min-width: 600px) {
    :root {
        --radius-lg: 30px;
        --drum-w: 120px;
        --drum-h: 150px;
        --item-h: 60px;
    }
    .activity-selector, .step-controls {
        flex-direction: row !important;
    }
    .container {
        background: var(--white);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow);
    }
    .selector-wrapper, .step-wrapper { padding: 60px 10px 15px; border-radius: var(--radius-lg); }
    .selector-label, .step-label { border-radius: 28px 28px 0 0; font-size: 0.9rem; padding: 10px 0; }
    .quiz-area { padding: 35px 20px 10px 20px !important; min-height: 145px !important; }
    .clock-container { width: clamp(200px, 38vh, 440px) !important; height: clamp(200px, 38vh, 440px) !important; }
    #digital-display { font-size: 1.6rem !important; }
    button { font-size: clamp(0.8rem, 1.6vh, 1.1rem) !important; padding: 1vh !important; border-radius: 15px !important; }
    button.primary { font-size: clamp(1.1rem, 2.2vh, 1.5rem) !important; padding: 1.2vh !important; }
    .quiz-label { font-size: clamp(1.1rem, 2.5vh, 1.5rem) !important; top: -18px !important; }
    .target-time { font-size: clamp(3rem, 9vh, 5rem) !important; }
    h1 { font-size: clamp(1.8rem, 4vh, 2.5rem) !important; margin-bottom: 20px !important; }
}

@media screen and (min-width: 768px) and (orientation: landscape) {
    body { align-items: center; }
    .container {
        max-width: 1100px;
        padding: 30px 40px;
    }
    .main-content {
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 40px;
    }
    .column-left { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
    .column-right { flex: 1; display: flex; flex-direction: column; gap: 20px; }
    .controls { max-width: 550px; margin: 0 auto; width: 100%; }
}

.sub-mode-selector {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-top: 10px;
    margin-bottom: 0;
    flex-wrap: nowrap;
    width: 100%;
}
.sub-mode-btn {
    font-size: clamp(0.6rem, 2.2vw, 0.85rem);
    padding: 6px 15px;
    flex: 1;
    max-width: 120px;
    border-radius: 10px;
    border: 2px solid var(--main-blue);
    background: var(--white);
    color: var(--main-blue);
    font-weight: 900;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
}
.sub-mode-btn.active {
    background: var(--main-blue);
    color: var(--white);
    box-shadow: 0 4px 0 rgba(0, 160, 233, 0.2);
}
#sub-oni { border-color: #e60000; color: #e60000; }
#sub-oni.active { background: #e60000; color: var(--white); }
.oni-icon { height: 1.2em; width: auto; vertical-align: middle; }

#sub-oni .oni-icon {
    filter: invert(11%) sepia(92%) saturate(7456%) hue-rotate(0deg) brightness(85%) contrast(118%);
}
#sub-oni.active .oni-icon {
    filter: brightness(0) invert(1);
}

.quiz-label .oni-icon { filter: invert(11%) sepia(92%) saturate(7456%) hue-rotate(0deg) brightness(85%) contrast(118%); }

.quiz-area {
    position: relative;
    font-weight: 700;
    /* margin-bottom: 40px; */
    padding: 20px 15px 10px 15px;
    background: var(--light-yellow);
    border: 4px solid var(--main-yellow);
    border-radius: 20px;
    min-height: 120px;
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 100%;
    transition: all 0.3s ease;
}

.quiz-label {
    position: absolute;
    top: -18px;
    background-color: var(--main-yellow);
    padding: 4px 20px;
    border-radius: 12px;
    font-size: 1.1rem;
    color: #000000;
    font-weight: 900;
    white-space: nowrap;
    z-index: 2;
    box-shadow: 0 4px 0 rgba(255, 210, 0, 0.3);
    transition: all 0.3s ease;
}

.target-time {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    font-weight: 900;
    color: var(--text-color);
    line-height: 1.2;
    text-align: center;
    margin: 2px 0 10px 0;
    min-width: 0;
}
.target-time span.unit { font-size: 1rem; margin-left: 2px; margin-right: 5px; color: inherit; opacity: 0.8; }

#time-input-display {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    justify-content: center;
    width: 100%;
    white-space: nowrap;
}

.drum-picker-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 10px;
}

.drum-container {
    width: var(--drum-w);
    height: var(--drum-h);
    background: white;
    border: 3px solid var(--main-blue);
    border-radius: 15px;
    position: relative;
    overflow: hidden;
    touch-action: none;
    user-select: none;
}

.drum-mask {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(0deg, white 0%, transparent 25%, transparent 75%, white 100%);
    pointer-events: none;
    z-index: 5;
}

.drum-selection-bar {
    position: absolute;
    top: 50%; left: 0; width: 100%; height: var(--item-h);
    background: rgba(0, 160, 233, 0.1);
    transform: translateY(-50%);
    z-index: 1;
}

.drum-list {
    position: absolute;
    width: 100%;
    padding: 0;
    margin: 0;
    list-style: none;
    z-index: 2;
}

.drum-list.is-snapping {
    transition: transform 0.2s cubic-bezier(0, 0, 0.2, 1);
}

.drum-item {
    height: var(--item-h);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--item-h) * 0.7);
    font-weight: 900;
    color: var(--main-blue);
}

.clock-container {
    position: relative;
    margin: 0 auto;
    width: 240px;
    height: 240px;
    user-select: none;
    flex-shrink: 0;
    touch-action: none;
    overflow: visible;
}

#clock-svg { width: 100%; height: 100%; filter: drop-shadow(0 4px 8px rgba(0,0,0,0.05)); }

.clock-balloon {
    position: relative;
    width: max-content;
    max-width: 90vw;
    background: var(--white);
    border: 4px solid var(--main-pink);
    padding: 8px 15px;
    border-radius: 20px;
    font-weight: 900;
    font-size: 1.1rem;
    color: var(--main-pink);
    white-space: nowrap;
    z-index: 40;
    box-shadow: 0 6px 15px rgba(0,0,0,0.1);
    animation: float 2s ease-in-out infinite;
    box-sizing: border-box;
    text-align: center;
    margin-bottom: 8px;
    display: none;
}
.clock-balloon::after {
    content: "";
    position: absolute;
    bottom: -15px; left: 50%; transform: translateX(-50%);
    border-width: 15px 15px 0; border-style: solid; border-color: var(--main-pink) transparent transparent;
}
.clock-balloon.oni { border-color: #e60000; color: #e60000; }
.clock-balloon.oni::after { border-top-color: #e60000; }

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-5px); }
}

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 5px; flex-shrink: 0; }
.controls button {
    font-family: 'M PLUS Rounded 1c', sans-serif; padding: 8px; font-size: 0.85rem; cursor: pointer; border: 4px solid var(--border-color); border-radius: 15px; background-color: var(--white); color: var(--text-color); font-weight: 700; transition: all 0.2s; display: flex; align-items: center; justify-content: center; gap: 5px; box-sizing: border-box; touch-action: manipulation;
    min-width: 100px;
}
button.toggle-digital { padding: 5px 10px; border-width: 2px; border-style: dashed; border-color: var(--main-blue); color: var(--main-blue); font-size: 0.7rem; }
button.toggle-digital.active { background-color: var(--main-blue); color: var(--white); border-style: solid; border-width: 2px; }
button.primary { background-color: var(--main-yellow); border-color: var(--main-yellow); grid-column: 1 / -1; padding: 10px; font-size: 1.2rem; box-shadow: 0 4px 0 #E6BD00; }
button.primary:active { box-shadow: 0 2px 0 #E6BD00; transform: translateY(2px); }
button.sub { background-color: var(--light-blue); border-color: var(--main-blue); color: var(--main-blue); grid-column: 1 / -1; padding: 10px; margin-top: 10px; margin-bottom: 5px; }
.btn-m1 { background-color: #FFF0F5 !important; border-color: var(--main-pink) !important; color: var(--main-pink) !important; }

.digital-wrapper { display: flex; justify-content: center; align-items: center; gap: 10px; margin: 0 auto; flex-shrink: 0; width: 100%; }
#digital-display { font-size: 1.5rem; font-weight: 900; color: var(--main-blue); background: var(--light-blue); border-radius: 100px; padding: 4px 20px; visibility: hidden; min-width: 100px; }

#result-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
    display: none;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}
#result-overlay.show { display: flex; }

.result-box {
    background: rgba(255, 255, 255, 0.95);
    padding: 40px;
    border-radius: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 80%;
    max-width: 400px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.overlay-text { font-size: 2.2rem; font-weight: 900; }
.overlay-icon { font-size: 5rem; }
.overlay-hint { font-size: 1.2rem; font-weight: 700; color: #FF5C00; text-align: center; }
.overlay-footer-text { margin-top: 20px; font-size: 1rem; color: #999; font-weight: 700; }

.hand { stroke-linecap: round; transform-origin: 100px 100px; }
.hour-hand { stroke: #FF5C00; stroke-width: 8; }
.minute-hand { stroke: var(--main-blue); stroke-width: 6; }
.hand-hit { stroke-linecap: round; transform-origin: 100px 100px; cursor: grab; stroke: rgba(0,0,0,0); stroke-width: 30; pointer-events: stroke; }
.clock-face { fill: var(--white); stroke: #333; stroke-width: 4; }
.number { font-weight: 900; font-size: 18px; fill: var(--text-color); pointer-events: none; }
.tick { stroke: #333; stroke-width: 2; pointer-events: none; }
.sakura { position: fixed; top: -20px; width: 15px; height: 15px; background: var(--main-pink); border-radius: 100% 0 100% 100%; z-index: 1000; animation: sakura-fall 4s linear forwards; }
@keyframes sakura-fall { 0% { transform: translateY(0) rotate(0deg); opacity: 1; } 100% { transform: translateY(100vh) rotate(360deg); opacity: 0; } }
