@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;700;900&display=swap');

:root {
    --primary-color: #14B8A6;
    --primary-shadow: #0D9488;
    --text-color: #0f2e2b;
    --u: min(6.3vw, 7.4vh, 66px);
}

/* 指のいろ（キーと手の指で共通） */
.f-lp { --fc: #8B5CF6; --fcl: #EDE9FE; }
.f-lr { --fc: #3B82F6; --fcl: #DBEAFE; }
.f-lm { --fc: #06B6D4; --fcl: #CFFAFE; }
.f-li { --fc: #10B981; --fcl: #D1FAE5; }
.f-ri { --fc: #F59E0B; --fcl: #FEF3C7; }
.f-rm { --fc: #F97316; --fcl: #FFEDD5; }
.f-rr { --fc: #EF4444; --fcl: #FEE2E2; }
.f-rp { --fc: #EC4899; --fcl: #FCE7F3; }
.f-th { --fc: #94A3B8; --fcl: #E2E8F0; }

* {
    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, #ecfeff 0%, #f0fdfa 100%);
    color: var(--text-color);
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}

#app {
    width: 100%;
    max-width: 1200px;
    height: 100%;
    position: relative;
    background: white;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.12);
}

.screen {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeIn 0.25s ease;
}

.screen.active { display: flex; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ======================================================================
   スタート画面
   ====================================================================== */

h1 {
    font-size: clamp(2.2rem, 6vh, 3.4rem);
    font-weight: 900;
    margin: 0 0 4px;
    color: #0f766e;
    letter-spacing: 0.04em;
}

.lead {
    margin: 0 0 18px;
    font-size: 1.05rem;
    color: #14b8a6;
    font-weight: 700;
}

.mode-switch {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.mode-btn {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: #f1f5f9;
    color: #64748b;
    border: 3px solid transparent;
    border-radius: 16px;
    padding: 10px 26px;
    font-family: inherit;
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
}

.mode-btn span {
    font-size: 0.72rem;
    font-weight: 400;
    opacity: 0.75;
}

.mode-btn.active {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-shadow));
    color: #fff;
    border-color: #0f766e;
    box-shadow: 0 5px 0 #0f766e, 0 8px 18px rgba(13, 148, 136, 0.3);
}

.panel-label {
    font-size: 1rem;
    font-weight: 700;
    color: #0f766e;
    margin: 0 0 12px;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    width: 100%;
    max-width: 660px;
    margin-bottom: 18px;
}

.level-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    background: linear-gradient(135deg, #ccfbf1, #99f6e4);
    color: #115e59;
    border: none;
    border-radius: 18px;
    padding: 16px 8px 12px;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 5px 0 #5eead4, 0 8px 18px rgba(20, 184, 166, 0.2);
    transition: transform 0.1s;
}

.level-btn:active { box-shadow: 0 1px 0 #5eead4; transform: translateY(4px); }

.level-btn.lv2 { background: linear-gradient(135deg, #cffafe, #a5f3fc); box-shadow: 0 5px 0 #67e8f9, 0 8px 18px rgba(6, 182, 212, 0.2); }
.level-btn.lv3 { background: linear-gradient(135deg, #dbeafe, #bfdbfe); box-shadow: 0 5px 0 #93c5fd, 0 8px 18px rgba(59, 130, 246, 0.2); color: #1e3a8a; }
.level-btn.lv4 { background: linear-gradient(135deg, #ede9fe, #ddd6fe); box-shadow: 0 5px 0 #c4b5fd, 0 8px 18px rgba(139, 92, 246, 0.2); color: #4c1d95; }
.level-btn.lv5 { background: linear-gradient(135deg, #fce7f3, #fbcfe8); box-shadow: 0 5px 0 #f9a8d4, 0 8px 18px rgba(236, 72, 153, 0.2); color: #831843; }
.level-btn.lv6 { background: linear-gradient(135deg, #ffedd5, #fed7aa); box-shadow: 0 5px 0 #fdba74, 0 8px 18px rgba(249, 115, 22, 0.2); color: #7c2d12; }

.lv-label { font-size: 1.5rem; font-weight: 900; line-height: 1; }
.lv-name { font-size: 1.05rem; font-weight: 700; }
.lv-sub { font-size: 0.72rem; opacity: 0.7; }
.lv-best { font-size: 0.72rem; font-weight: 700; opacity: 0.85; margin-top: 2px; }

.sound-toggle {
    background: #ecfeff;
    color: #0f766e;
    border: 2px solid #99f6e4;
    border-radius: 20px;
    padding: 7px 20px;
    font-size: 0.95rem;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    margin-bottom: 10px;
}

.sound-toggle.off { background: #f8fafc; color: #94a3b8; border-color: #e2e8f0; }

.secondary-btn {
    background: rgba(100, 116, 139, 0.1);
    color: #475569;
    border: 2px solid rgba(100, 116, 139, 0.25);
    padding: 8px 22px;
    border-radius: 20px;
    font-size: 1rem;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-shadow));
    color: white;
    font-size: 1.6rem;
    padding: 12px 34px;
    border: none;
    border-radius: 50px;
    box-shadow: 0 5px 0 #0f766e, 0 8px 20px rgba(13, 148, 136, 0.35);
    cursor: pointer;
    font-family: inherit;
    font-weight: 700;
    transition: transform 0.1s;
}

.primary-btn:active { box-shadow: 0 1px 0 #0f766e; transform: translateY(4px); }

/* ======================================================================
   ゲーム画面
   ====================================================================== */

#game-screen {
    justify-content: space-between;
    padding: 10px 12px 8px;
}

.game-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex: 0 0 auto;
}

.back-link {
    font-size: 0.95rem;
    color: white;
    background: #94a3b8;
    padding: 7px 16px;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-weight: 700;
    box-shadow: 0 3px #64748b;
}

.back-link:active { box-shadow: none; transform: translateY(3px); }

.level-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #0f766e;
}

.stats { display: flex; gap: 18px; }

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.05;
    min-width: 72px;
}

.stat-label { font-size: 0.68rem; color: #64748b; font-weight: 700; }
.stat-value { font-size: 1.8rem; font-weight: 900; color: #0f766e; font-variant-numeric: tabular-nums; }
.stat-value.urgent { color: #ef4444; animation: pulse 0.6s ease-in-out infinite; }

@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }

.word-area {
    flex: 1 1 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 0;
}

.hint {
    font-size: 0.85rem;
    color: #14b8a6;
    font-weight: 700;
    height: 1.2em;
}

.kana {
    font-size: clamp(2.4rem, 7.5vh, 4.4rem);
    font-weight: 900;
    letter-spacing: 0.08em;
    line-height: 1.15;
}

.kana.single {
    font-size: clamp(4rem, 14vh, 8rem);
    font-family: 'Courier New', monospace;
}

.kana.long { font-size: clamp(1.6rem, 4.6vh, 2.9rem); letter-spacing: 0.04em; }

.k-done { color: #cbd5e1; }
.k-cur { color: #0d9488; }
.k-rest { color: #334155; }

.romaji {
    font-family: 'Courier New', monospace;
    font-size: clamp(1.5rem, 4.4vh, 2.6rem);
    font-weight: 700;
    letter-spacing: 0.16em;
}

.romaji.long { font-size: clamp(1rem, 2.9vh, 1.7rem); letter-spacing: 0.1em; }

.r-done { color: #10b981; }
.r-cur { color: #0f766e; background: #ccfbf1; border-radius: 6px; padding: 0 3px; }
.r-rest { color: #cbd5e1; }

/* もうひとつの書きかた（si / shi のような表記ゆれ） */
.alt {
    display: flex;
    align-items: baseline;
    gap: 8px;
    height: 1.7em;
    visibility: hidden;
}

.alt-word {
    font-family: 'Courier New', monospace;
    font-size: clamp(0.95rem, 2.4vh, 1.35rem);
    font-weight: 700;
    letter-spacing: 0.14em;
    color: #64748b;
}

.alt-note {
    font-size: clamp(0.68rem, 1.6vh, 0.85rem);
    color: #94a3b8;
    font-weight: 700;
}

.shake { animation: shake 0.25s; }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-9px); }
    75% { transform: translateX(9px); }
}

/* ---- キーボード ---- */

.guide {
    flex: 0 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.keyboard {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 10px 10px 12px;
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: 16px;
}

.kb-row { display: flex; gap: 5px; }

.kb-key {
    width: calc(var(--u) - 5px);
    height: calc(var(--u) - 5px);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: var(--fcl);
    color: #334155;
    border-bottom: 3px solid var(--fc);
    font-size: calc(var(--u) * 0.42);
    font-weight: 700;
    position: relative;
    transition: transform 0.08s, background 0.08s;
}

.kb-key.kb-space {
    width: calc(var(--u) * 6);
    font-size: calc(var(--u) * 0.24);
}

.kb-key.home-bump::after {
    content: '';
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 40%;
    height: 3px;
    border-radius: 2px;
    background: var(--fc);
    opacity: 0.55;
}

.kb-key.next {
    background: var(--fc);
    color: #fff;
    transform: translateY(-3px) scale(1.08);
    box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--fc), 0 8px 18px rgba(0, 0, 0, 0.18);
    z-index: 2;
    animation: keyPulse 0.9s ease-in-out infinite;
}

@keyframes keyPulse {
    0%, 100% { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--fc), 0 8px 18px rgba(0, 0, 0, 0.18); }
    50% { box-shadow: 0 0 0 3px #fff, 0 0 0 10px var(--fc), 0 8px 22px rgba(0, 0, 0, 0.22); }
}

.kb-key.hit { background: #0d9488; color: #fff; transform: translateY(2px) scale(0.96); }
.kb-key.miss { background: #ef4444; color: #fff; animation: shake 0.16s; }

/* ---- 手 ---- */

.hands {
    display: flex;
    gap: clamp(30px, 8vw, 110px);
    align-items: flex-end;
}

.hand-wrap { display: flex; flex-direction: column; align-items: center; }

.hand-label { font-size: 0.68rem; color: #94a3b8; font-weight: 700; }

.hand {
    width: auto;
    height: clamp(66px, 13vh, 116px);
    display: block;
}

.palm { fill: #f1f5f9; stroke: #cbd5e1; stroke-width: 2.5; }

.fg {
    fill: var(--fcl);
    stroke: var(--fc);
    stroke-width: 2.5;
    transition: fill 0.12s;
}

.fg.next {
    fill: var(--fc);
    filter: drop-shadow(0 0 7px var(--fc));
}

/* ======================================================================
   けっか画面
   ====================================================================== */

h2 {
    font-size: clamp(2rem, 6vh, 3rem);
    font-weight: 900;
    color: #0f766e;
    margin: 0;
}

.result-box {
    background: linear-gradient(135deg, #f0fdfa, #ccfbf1);
    border: 2px solid #99f6e4;
    padding: 22px 40px;
    border-radius: 20px;
    box-shadow: 0 8px 24px rgba(20, 184, 166, 0.15);
    margin: 20px 0;
    text-align: center;
}

.result-box p { margin: 8px 0; }
.score-line { font-size: 1.5rem; font-weight: 700; }
.sub-line { font-size: 1.05rem; color: #475569; }
.best-line { font-size: 1.05rem; color: #0f766e; font-weight: 700; }
.highlight { font-weight: 900; color: #0d9488; font-size: 2.6rem; }

.result-actions { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }

.home-link {
    color: #6b7280;
    text-decoration: none;
    font-size: 1rem;
    border-bottom: 1px solid currentColor;
}

/* ======================================================================
   よこむき うながし
   ====================================================================== */

.rotate-overlay {
    position: absolute;
    inset: 0;
    background: rgba(240, 253, 250, 0.97);
    z-index: 999;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    text-align: center;
    padding: 24px;
}

.rotate-overlay p { font-size: 1.4rem; font-weight: 700; color: #0f766e; margin: 0; }
.rotate-icon { font-size: 4rem; animation: tilt 1.6s ease-in-out infinite; }

@keyframes tilt {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(-90deg); }
}

@media (orientation: portrait) {
    .rotate-overlay { display: flex; }
}

.rotate-overlay.dismissed { display: none !important; }

/* せまい画面むけの微調整 */
@media (max-height: 560px) {
    .hands { display: none; }
    .hint { display: none; }
}
