:root {
    --bg-dark: #0a0d14;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-glow: rgba(241, 196, 15, 0.15);

    --color-male: #e74c3c;
    /* 男弦のテーマ赤 */
    --color-middle: #3498db;
    /* 中弦のテーマ青 */
    --color-female: #2ecc71;
    /* 女弦のテーマ緑 */
    --color-gold: #f1c40f;
    /* 三線の弦の黄金色 */

    --glow-male: 0 0 15px rgba(231, 76, 60, 0.8);
    --glow-middle: 0 0 15px rgba(52, 152, 219, 0.8);
    --glow-female: 0 0 15px rgba(46, 204, 113, 0.8);
    --glow-gold: 0 0 15px rgba(241, 196, 15, 0.8);

    --font-outfit: 'Outfit', 'Noto Sans JP', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
}

body,
html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: var(--font-outfit);
    color: #e2e8f0;
    position: fixed;
    touch-action: none;
}

/* 縦画面時の警告 */
#orientation-warning {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #0b0f19;
    z-index: 9999;
    display: none;
    /* デフォルト非表示、CSSメディアクエリで制御 */
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
}

.warning-content {
    max-width: 400px;
}

.phone-icon-wrapper {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto 30px;
}

.phone-icon {
    position: absolute;
    top: 28px;
    left: 28px;
    color: #4a5568;
    animation: rotatePhone 3s infinite ease-in-out;
}

.rotate-arrow {
    position: absolute;
    top: 15px;
    left: 15px;
    color: var(--color-gold);
    animation: spinArrow 3s infinite linear;
}

@keyframes rotatePhone {

    0%,
    100% {
        transform: rotate(0deg);
    }

    50% {
        transform: rotate(-90deg);
    }
}

@keyframes spinArrow {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(-360deg);
    }
}

#orientation-warning h2 {
    font-size: 1.6rem;
    margin-bottom: 15px;
    color: #fff;
    font-weight: 600;
}

#orientation-warning p {
    font-size: 1rem;
    color: #a0aec0;
    line-height: 1.5;
}

/* アプリメインコンテナ */
#app-container {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at 80% 20%, #152035 0%, #07090e 100%);
    padding: 10px 15px 15px;
}

/* ヘッダー */
#app-header {
    height: 50px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 5px;
    margin-bottom: 10px;
}

.logo {
    display: flex;
    flex-direction: column;
}

.brand {
    font-size: 0.6rem;
    letter-spacing: 0.25em;
    color: var(--color-gold);
    font-weight: 700;
    line-height: 1;
}

.app-title {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: #ffffff;
    line-height: 1.2;
}

.controls-group {
    display: flex;
    align-items: center;
    gap: 20px;
}

.control-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-item label {
    font-size: 0.75rem;
    color: #a0aec0;
}

header,
.controls-group,
.control-item,
.control-item select,
.control-item input,
.icon-btn,
button,
select {
    pointer-events: auto !important;
    touch-action: manipulation !important;
    user-select: auto !important;
    -webkit-user-select: auto !important;
}

.control-item select {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    color: #fff;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-family: var(--font-outfit);
    outline: none;
    cursor: pointer;
}

.control-item input[type="range"] {
    width: 80px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
}

.control-item input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--color-gold);
    cursor: pointer;
    box-shadow: var(--glow-gold);
}

.icon-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

/* メインプレイボード（画面最下部への下寄せ・固定高さ） */
#playboard {
    position: fixed;
    bottom: 5px;
    left: 15px;
    right: 15px;
    height: 180px; /* 楽器全体の高さを180pxにスリム化 */
    display: flex;
    gap: 15px;
    z-index: 10;
}

/* 左手：勘所（キー）エリア（右側に配置、右下基準の絶対配置） */
#left-hand-area {
    flex: 1;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    backdrop-filter: blur(10px);
    position: relative;
    height: 180px; /* 高さを180pxに固定 */
    box-sizing: border-box;
    overflow: hidden;
}

/* 竿の背景表現（グリッド全体をカバー） */
.neck-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #1a1510 0%, #2c221a 50%, #1a1510 100%);
    opacity: 0.15;
    z-index: 1;
    pointer-events: none;
    border-radius: 8px;
}

.row-1 {
    top: 45px;
}

.row-2 {
    top: 91px;
}

.row-3 {
    top: 137px;
}

/* 右下（赤丸）を基準とする固定ピクセル配置（右から左へ並びます） */
.col-1 {
    right: 35px;
    z-index: 2;
}

.col-2 {
    right: 259px;
    z-index: 2;
}

.col-3 {
    right: 364px;
    z-index: 2;
}

.col-4 {
    right: 434px;
    z-index: 2;
}

.col-5 {
    right: 539px;
    z-index: 2;
}

/* 運指ガイドラベル（目立たない半透明） */
.finger-guide {
    position: absolute;
    top: 15px; /* ボタンの上側の隙間に配置 */
    width: 38px; /* ボタンの横幅と揃えて中央配置 */
    text-align: center;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.35); /* 目立たない薄い半透明の白 */
    font-weight: bold;
    pointer-events: none;
    user-select: none;
    z-index: 2;
}

.fret-btn {
    position: absolute; /* 絶対配置に変更 */
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.03);
    border: 2px solid rgba(255, 255, 255, 0.1);
    color: #a0aec0;
    font-size: 13px;
    font-weight: bold;
    font-family: var(--font-outfit);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.12s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.05);
    touch-action: none;
    /* ポインターイベントの正常動作に必要 */
}

/* 各弦ごとのボタンフォーカス・アクティブ色 */
.fret-btn[data-string="male"].active {
    background: var(--color-male);
    border-color: #ff8a80;
    box-shadow: var(--glow-male);
    transform: scale(0.92);
}

.fret-btn[data-string="middle"].active {
    background: var(--color-middle);
    border-color: #80d8ff;
    box-shadow: var(--glow-middle);
    transform: scale(0.92);
}

.fret-btn[data-string="female"].active {
    background: var(--color-female);
    border-color: #b9f6ca;
    box-shadow: var(--glow-female);
    transform: scale(0.92);
}

/* 右手：弦エリア（左側に配置、スリムな幅に設定） */
#right-hand-area {
    width: 120px; /* 幅を120pxに固定 */
    flex: none; /* 自動縮小を防止 */
    background: rgba(15, 22, 36, 0.9);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 0 10px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.2);
    touch-action: none;
    /* ブラウザのデフォルトドラッグ/スクロール挙動を防止 */
    user-select: none;
    /* テキスト選択を防止 */
    height: 180px; /* 高さを180pxに完全固定 */
    box-sizing: border-box;
}

.bridge {
    position: absolute;
    top: 10%;
    left: 45px;
    width: 8px;
    height: 80%;
    background: linear-gradient(180deg, #d35400 0%, #e67e22 50%, #d35400 100%);
    border-radius: 4px;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.5);
    z-index: 3;
    touch-action: none;
    pointer-events: none;
    /* 駒自体はイベントを透過させて背景で拾うようにする */
}

/* 開放弦ラベルのスタイル定義（駒の左側に絶対配置） */
.open-string-badge {
    position: absolute;
    left: 10px;
    top: 43%;
    transform: translateY(-50%);
    font-size: 24px;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.95);
    text-shadow: 0 0 12px rgba(0, 0, 0, 0.9), 0 0 4px rgba(0, 0, 0, 0.8);
    font-family: var(--font-outfit);
    pointer-events: none;
    user-select: none;
    z-index: 4;
}

.strings-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    height: 85%;
    position: relative;
    touch-action: none;
}

.string-wrapper {
    position: relative;
    height: 40px;
    display: flex;
    align-items: center;
    cursor: pointer;
    touch-action: none;
}

.string-name-badge {
    position: absolute;
    right: 15px;
    /* 右側（境界線近く）に変更 */
    top: -5px;
    font-size: 0.65rem;
    color: #718096;
    background: rgba(10, 13, 20, 0.8);
    padding: 1px 6px;
    border-radius: 4px;
    border: 1px solid var(--glass-border);
    pointer-events: none;
}

.sanshin-string {
    width: 100%;
    height: 20px;
    overflow: visible;
    pointer-events: none;
    /* タッチイベントはラッパーで拾う */
}

/* 弦の振動アニメーション */
@keyframes stringVibrate {
    0% {
        transform: translateY(0);
    }

    10% {
        transform: translateY(-5px);
    }

    20% {
        transform: translateY(4px);
    }

    30% {
        transform: translateY(-3px);
    }

    40% {
        transform: translateY(2.5px);
    }

    50% {
        transform: translateY(-1.8px);
    }

    60% {
        transform: translateY(1.2px);
    }

    70% {
        transform: translateY(-0.8px);
    }

    80% {
        transform: translateY(0.5px);
    }

    90% {
        transform: translateY(-0.2px);
    }

    100% {
        transform: translateY(0);
    }
}

.vibrating {
    animation: stringVibrate 0.6s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

/* 開始オーバーレイ */
#welcome-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(10, 13, 20, 0.95);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.welcome-card {
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    max-width: 480px;
    backdrop-filter: blur(20px);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.welcome-card h2 {
    font-size: 1.8rem;
    color: #ffffff;
    margin-bottom: 20px;
    font-weight: 600;
}

.welcome-card p {
    color: #94a3b8;
    margin-bottom: 30px;
    line-height: 1.6;
}

#start-btn {
    background: linear-gradient(135deg, var(--color-gold) 0%, #d4ac0d 100%);
    color: #0f172a;
    border: none;
    padding: 14px 40px;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: var(--glow-gold);
    transition: all 0.2s ease;
}

#start-btn:hover {
    transform: scale(1.05);
}

/* ヘルプモーダル */
/* モーダル表示時にルートルート(html/body)のタッチ制限を開放しネイティブスクロールを全開放 */
body.modal-open,
html.modal-open {
    touch-action: auto !important;
    overflow: auto !important;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 9999;
    display: none;
    justify-content: center;
    align-items: center;
    padding: 15px;
    touch-action: pan-y;
    pointer-events: auto;
}

.modal-content {
    background: #1e293b;
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 1.5rem 1.75rem;
    width: 100%;
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y !important;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
    pointer-events: auto;
}

/* モーダル内の全子要素（テキスト・画像・見出しなど）のタッチスクロール阻害を完全防止 */
.modal-content *,
#tutorial-card * {
    touch-action: pan-y !important;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
}

.modal-content img,
#tutorial-card img {
    pointer-events: none;
    -webkit-user-drag: none;
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 1.8rem;
    color: #94a3b8;
    cursor: pointer;
    pointer-events: auto !important;
}

.close-btn:hover {
    color: #fff;
}

.modal-content h2 {
    font-size: 1.4rem;
    color: #fff;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--color-gold);
    padding-bottom: 8px;
}

.help-section {
    margin-bottom: 20px;
    touch-action: pan-y !important;
}

.help-section h3 {
    font-size: 1rem;
    color: var(--color-gold);
    margin-bottom: 8px;
    touch-action: pan-y !important;
}

.help-section p {
    font-size: 0.85rem;
    color: #94a3b8;
    line-height: 1.6;
    touch-action: pan-y !important;
}

/* メディアクエリ: 縦方向（ポートレート）のときは警告を出す */
@media (orientation: portrait) {
    #orientation-warning {
        display: flex;
    }

    #app-container {
        display: none;
    }
}

/* 目隠し（ブラインド）モード用スタイル */
body.blind-mode .fret-btn {
    color: transparent !important; /* ボタンの文字（漢字）を非表示にする */
}
body.blind-mode .open-string-badge {
    color: transparent !important; /* 開放弦の漢字を非表示にする */
    text-shadow: none !important;
}
body.blind-mode .finger-guide {
    color: transparent !important; /* 運指ガイドも非表示にする */
}