@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;700;900&display=swap');

:root {
    --primary-color: #F97316;
    --primary-shadow: #EA580C;
    --key-bg: #FFFFFF;
    --key-shadow: #90A4AE;
    --text-color: #2d1600;
}

* { box-sizing: border-box; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

body {
    margin: 0; padding: 0;
    font-family: 'Noto Sans JP', "Hiragino Kaku Gothic ProN", sans-serif;
    background: linear-gradient(150deg, #fff7ed 0%, #fef3c7 100%);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#app {
    width: 100%; max-width: 600px; height: 100%;
    position: relative;
    background: white;
    box-shadow: 0 0 60px rgba(0,0,0,0.12);
}

.screen {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    display: none; flex-direction: column; align-items: center; justify-content: center;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}
.screen.active { display: flex; }

.hidden { display: none !important; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; }}

h1 { font-size: 3rem; font-weight: 900; margin-bottom: 24px; line-height: 1.2; text-align: center; color: #7c2d12; }

.primary-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-shadow));
    color: white;
    font-size: 2rem; padding: 15px 40px;
    border: none; border-radius: 50px;
    box-shadow: 0 6px 0 #c2410c, 0 8px 20px rgba(234,88,12,0.35);
    cursor: pointer; margin-top: 20px;
    font-family: inherit; font-weight: 700;
    transition: transform 0.1s;
}
.primary-btn:active { box-shadow: 0 2px 0 #c2410c; transform: translateY(4px); }

.secondary-btn {
    background: rgba(100,116,139,0.1);
    color: #475569;
    border: 2px solid rgba(100,116,139,0.25);
    padding: 10px 24px;
    border-radius: 20px; font-size: 1.1rem; cursor: pointer;
    text-decoration: none; margin-top: 16px;
    font-family: inherit;
    transition: background 0.15s;
    display: inline-block;
}
.secondary-btn:hover { background: rgba(100,116,139,0.2); }

/* Start Screen - Panel A: Dan selection */
.panel-label {
    font-size: 1.2rem;
    font-weight: 700;
    color: #9a3412;
    margin-bottom: 16px;
}

.dan-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    width: 100%;
    max-width: 340px;
    margin-bottom: 16px;
}

.dan-btn {
    background: linear-gradient(135deg, #FED7AA, #FDBA74);
    color: #7c2d12;
    border: none; border-radius: 16px;
    font-size: 1.6rem; font-weight: 700;
    padding: 16px 10px;
    box-shadow: 0 4px 0 #f97316, 0 6px 16px rgba(249,115,22,0.25);
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.1s;
}
.dan-btn:active { box-shadow: 0 1px 0 #f97316; transform: translateY(3px); }

.mazekaze-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-shadow));
    color: white;
    border: none; border-radius: 16px;
    font-size: 1.5rem; font-weight: 700;
    padding: 16px 10px;
    box-shadow: 0 4px 0 #c2410c, 0 6px 16px rgba(234,88,12,0.35);
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.1s;
    width: 100%; max-width: 340px;
    margin-bottom: 12px;
}
.mazekaze-btn:active { box-shadow: 0 1px 0 #c2410c; transform: translateY(3px); }

/* Panel B: Count selection */
.count-label {
    font-size: 1.4rem;
    font-weight: 700;
    color: #7c2d12;
    margin-bottom: 20px;
    text-align: center;
}

.count-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    width: 100%;
    max-width: 320px;
    margin-bottom: 20px;
}

.count-btn {
    background: linear-gradient(135deg, #FED7AA, #FDBA74);
    color: #7c2d12;
    border: none; border-radius: 16px;
    font-size: 1.5rem; font-weight: 700;
    padding: 20px 10px;
    box-shadow: 0 4px 0 #f97316, 0 6px 16px rgba(249,115,22,0.2);
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.1s;
}
.count-btn:active { box-shadow: 0 1px 0 #f97316; transform: translateY(3px); }

/* Game Screen */
#game-screen { justify-content: space-between; padding-bottom: 0; }
.back-link {
    position: absolute; top: 15px; left: 15px;
    font-size: 1rem; color: white; background: #90A4AE;
    padding: 8px 16px; border-radius: 20px; text-decoration: none;
    box-shadow: 0 3px #546E7A;
    border: none; cursor: pointer; font-family: inherit;
}
.back-link:active { box-shadow: 0 0; transform: translateY(3px); }

.progress { font-size: 1.5rem; margin-top: 20px; color: #555; }

.problem-area {
    font-size: 5rem; font-weight: bold;
    flex-grow: 1; display: flex; align-items: center; justify-content: center;
    font-family: monospace;
}
#answer-box {
    display: inline-block; min-width: 1.5em; border-bottom: 4px solid #333;
    text-align: center; color: var(--primary-color);
}

.input-area {
    width: 100%; background-color: #CFD8DC;
    padding: 20px; border-radius: 20px 20px 0 0;
}
.keypad {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px;
    max-width: 500px; margin: 0 auto;
}
.key {
    background: var(--key-bg); border: none; border-radius: 10px;
    font-size: 2.5rem; padding: 15px 0;
    box-shadow: 0 4px var(--key-shadow);
    color: #333; cursor: pointer;
}
.key:active { box-shadow: 0 0; transform: translateY(4px); }
.action-ac { background-color: #FFCDD2; color: #D32F2F; box-shadow: 0 4px #E57373; font-size: 2rem; }
.action-ok { background-color: #FED7AA; color: #c2410c; box-shadow: 0 4px #fb923c; font-size: 2rem; }

/* Result Screen */
.result-box {
    background: linear-gradient(135deg, #fff7ed, #fef3c7);
    border: 2px solid #FED7AA;
    padding: 30px; border-radius: 20px;
    box-shadow: 0 8px 24px rgba(249,115,22,0.15);
    margin: 30px 0;
    text-align: center; width: 100%;
}
.result-box p { font-size: 2rem; margin: 15px 0; }
.score-line, .time-line { font-weight: 700; }
.highlight { font-weight: 900; color: #D84315; font-size: 3rem; }

.home-link {
    color: #6B7280; text-decoration: none; font-size: 1.1rem;
    border-bottom: 1px solid currentColor;
}

/* Feedback Overlay */
.feedback-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    display: flex; align-items: center; justify-content: center;
    font-size: 15rem; font-weight: bold;
    opacity: 0; transition: opacity 0.2s;
    z-index: 100;
}
.feedback-overlay.correct::after   { content: "⭕"; color: #E91E63; }
.feedback-overlay.incorrect::after { content: "❌"; color: #3F51B5; }
.feedback-overlay.show { opacity: 0.8; animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }

@keyframes popIn {
    0%   { transform: scale(0.5); opacity: 0; }
    50%  { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1);   opacity: 0.8; }
}
