/* =========================================
   1. 全体の設定（カラーパレットと基本フォント）
   ========================================= */
:root {
    --primary: #3b82f6;
    /* メインの青色 */
    --primary-dark: #2563eb;
    /* ホバー時の濃い青 */
    --bg-color: #f1f5f9;
    /* 背景の薄いグレー */
    --surface: #ffffff;
    /* カードの白色 */
    --text-main: #1e293b;
    /* メインテキスト（濃いグレー） */
    --text-muted: #64748b;
    /* サブテキスト */
    --border: #e2e8f0;
    /* 境界線の色 */
    --accent: #ef4444;
    /* アクセント（赤） */
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

body {
    font-family: 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
    margin: 0;
    background: var(--bg-color);
    color: var(--text-main);
}

/* =========================================
   2. レイアウト（サイドバーとメイン画面）
   ========================================= */
.app-container {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 260px;
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    color: white;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.sidebar-header {
    padding: 25px 20px;
    text-align: center;
    border-bottom: 1px solid #334155;
}

.sidebar-header h1 {
    margin: 0;
    font-size: 22px;
    letter-spacing: 2px;
}

.nav-menu {
    list-style: none;
    padding: 10px 0;
    margin: 0;
}

.nav-menu li {
    padding: 18px 25px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    border-left: 4px solid transparent;
}

.nav-menu li:hover {
    background: rgba(255, 255, 255, 0.05);
    padding-left: 30px;
    /* ホバー時に少し右に動く */
}

.nav-menu li.active {
    background: rgba(255, 255, 255, 0.1);
    border-left: 4px solid var(--primary);
    font-weight: bold;
}

.main-content {
    flex-grow: 1;
    padding: 40px;
    overflow-y: auto;
}

/* =========================================
   3. タブとカードのデザイン
   ========================================= */
.tab-section {
    display: none;
    background: var(--surface);
    border-radius: 12px;
    padding: 30px;
    box-shadow: var(--shadow);
    max-width: 1000px;
    margin: 0 auto;
    animation: fadeIn 0.4s ease;
    /* タブ切り替え時のフワッと表示 */
}

.tab-section.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

h2 {
    border-bottom: 2px solid var(--primary);
    padding-bottom: 10px;
    margin-top: 0;
    color: var(--text-main);
}

/* =========================================
   4. ボタンと入力フォーム
   ========================================= */
button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
    transition: all 0.2s;
}

button:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    /* ホバー時に少し浮く */
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.4);
}

select,
input[type="text"] {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 15px;
    outline: none;
    transition: border 0.3s;
}

select:focus,
input[type="text"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* マークシートを横に並べるためのコンテナ */
.sheet-container {
    display: flex;
    flex-wrap: wrap;
    /* 画面に入り切らない場合は自動で下段に折り返す */
    gap: 30px;
    /* テーブル同士の隙間 */
    justify-content: center;
    /* 画面の中央に寄せる */
    margin: 20px 0;
}

/* 小分けにされたマークシートテーブル独自のデザイン */
.mark-table {
    width: auto;
    /* 画面いっぱい(100%)に広がるのを防ぐ */
    margin: 0;
    background: var(--surface);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
    /* 角丸を綺麗に適用するため */
}

/* 選択肢の隙間を少しコンパクトにして見やすくする */
.mark-table th,
.mark-table td {
    padding: 6px 10px;
}

.mark-table .choice {
    width: 28px;
    /* 複数列でも画面に収まるように少し小さく */
    height: 28px;
    font-size: 14px;
}

/* =========================================
   5. マークシート（テーブル）のデザイン
   ========================================= */
/* =========================================
   5. マークシートのデザイン（本物志向）
   ========================================= */
.sheet-container {
    display: flex;
    justify-content: center;
    margin: 30px 0;
}

.mark-sheet-block {
    background: #ffffff;
    padding: 30px 40px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    max-width: 600px;
}

/* 1問ごとの行 */
.mark-row {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px dashed #e2e8f0;
}

.mark-row:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

/* 左側の解答番号（丸の拡大に合わせて少し大きくします） */
.q-num {
    background: #f8fafc;
    color: #475569;
    font-size: 18px;
    /* 16px -> 18px */
    font-weight: bold;
    width: 44px;
    /* 36px -> 44px */
    height: 44px;
    /* 36px -> 44px */
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
    margin-right: 30px;
    border: 2px solid #e2e8f0;
}

/* 丸を横に並べる */
.bubbles {
    display: flex;
    gap: 16px;
    /* 押し間違いを防ぐため、12px -> 16px へ隙間を広げます */
}

/* 選択肢の丸（タップしやすい44pxへ拡大） */
.choice.bubble {
    width: 44px;
    /* 32px -> 44px */
    height: 44px;
    /* 32px -> 44px */
    border: 2px solid #94a3b8;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #64748b;
    font-weight: bold;
    font-size: 18px;
    /* 15px -> 18px */
    cursor: pointer;
    background: white;
    transition: all 0.2s;
    /* タップした時に青い枠が出るのを防ぐ（スマホ向け） */
    -webkit-tap-highlight-color: transparent;
}

/* マウスを乗せたとき */
.choice.bubble:hover {
    background: #f1f5f9;
    border-color: var(--primary);
    color: var(--primary);
}

/* 鉛筆で塗りつぶした状態（黒鉛のような色） */
.choice.bubble.selected {
    background: #334155;
    border-color: #334155;
    color: white;
    /* 塗った後は文字を白抜きにする */
    transform: scale(1.05);
    /* 少しだけ大きくなる */
}

/* -----------------------------------------
   ※成績表などのテーブル用基本設定（残す）
   ----------------------------------------- */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}

th,
td {
    padding: 12px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

th {
    background: var(--bg-color);
    font-weight: bold;
    color: var(--text-muted);
}

/* =========================================
   6. 成績画面・ランキング
   ========================================= */
.scoreContainer {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.topArea {
    display: flex;
    gap: 20px;
}

.judgeBox {
    flex: 1;
    background: #fff1f2;
    border: 2px solid #fda4af;
    border-radius: 12px;
    text-align: center;
    padding: 30px;
    box-shadow: var(--shadow);
}

.judgeBox h3 {
    margin-top: 0;
    color: #be123c;
}

#judgeLetter {
    font-size: 100px;
    font-weight: bold;
    color: var(--accent);
    line-height: 1;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

#judgeUniversity {
    font-size: 20px;
    font-weight: bold;
    color: #881337;
    margin-top: 15px;
}

.chartBox {
    flex: 1.5;
    background: var(--bg-color);
    border-radius: 12px;
    padding: 20px;
}

.scoreTable th {
    background: var(--primary);
    color: white;
}

.scoreTable tbody tr:hover {
    background: #f8fafc;
}

tfoot {
    background: #e2e8f0;
    font-weight: bold;
    font-size: 18px;
}

/* =========================================
   6. ランキング王冠（メダル）の装飾
   ========================================= */
.crown {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-weight: bold;
    font-size: 16px;
    padding: 4px 10px;
    border-radius: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* 金の王冠 */
.crown.gold {
    color: #856404;
    background-color: #fff3cd;
    border: 1px solid #ffeeba;
}

/* 銀の王冠 */
.crown.silver {
    color: #4d5154;
    background-color: #e2e3e5;
    border: 1px solid #d6d8db;
}

/* 銅の王冠 */
.crown.bronze {
    color: #721c24;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
}

/* =========================================
   7. ゲーム風プロフィール画面
   ========================================= */
.game-profile-container {
    background: var(--surface);
    border-radius: 12px;
    padding: 20px;
    color: var(--text-main);
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 30px;
    background: linear-gradient(135deg, #1e293b, #0f172a);
    padding: 30px;
    border-radius: 12px;
    color: white;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.avatar-box {
    width: 100px;
    height: 100px;
    background: white;
    border-radius: 50%;
    padding: 5px;
    border: 3px solid var(--primary);
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
}

.avatar-box img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
}

.user-info h3 {
    margin: 0 0 5px 0;
    font-size: 24px;
    letter-spacing: 1px;
}

.user-id {
    margin: 0 0 15px 0;
    color: #94a3b8;
    font-size: 14px;
}

/* レベルゲージ */
.level-container {
    width: 300px;
}

.level-text {
    font-weight: bold;
    color: #fcd34d;
    font-size: 18px;
}

.progress-bar-bg {
    width: 100%;
    height: 12px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    margin: 5px 0;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
    border-radius: 6px;
    transition: width 1s ease-in-out;
}

.exp-text {
    font-size: 12px;
    color: #cbd5e1;
}

/* フレンド等のステータス */
.profile-stats {
    display: flex;
    gap: 20px;
    margin: 30px 0;
}

.stat-box {
    flex: 1;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 15px;
    text-align: center;
}

.stat-box h4 {
    margin: 0 0 10px 0;
    color: var(--text-muted);
    font-size: 14px;
}

.stat-box p {
    margin: 0;
    font-size: 20px;
    font-weight: bold;
    color: var(--primary);
}

/* 実績バッジ */
.achievements h3 {
    border-bottom: 2px solid var(--primary);
    padding-bottom: 10px;
    margin-bottom: 20px;
}

.badges-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.badge {
    padding: 12px 20px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 14px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge.gold {
    background: linear-gradient(135deg, #fef08a, #eab308);
    color: #713f12;
    border: 1px solid #ca8a04;
}

.badge.silver {
    background: linear-gradient(135deg, #f1f5f9, #cbd5e1);
    color: #334155;
    border: 1px solid #94a3b8;
}

.badge.bronze {
    background: linear-gradient(135deg, #fed7aa, #f97316);
    color: #7c2d12;
    border: 1px solid #c2410c;
}

.badge.locked {
    background: #f1f5f9;
    color: #94a3b8;
    border: 1px dashed #cbd5e1;
    filter: grayscale(100%);
}

/* =========================================
   8. フレンド画面
   ========================================= */
.friend-search-box {
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.friend-search-box h3 {
    margin-top: 0;
    color: var(--text-main);
}

.friend-list-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.friend-card {
    display: flex;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 15px;
    box-shadow: var(--shadow);
    transition: transform 0.2s;
}

.friend-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.friend-avatar {
    width: 50px;
    height: 50px;
    background: #f1f5f9;
    border-radius: 50%;
    margin-right: 15px;
    border: 2px solid #cbd5e1;
}

.friend-info {
    flex-grow: 1;
}

.friend-info h4 {
    margin: 0 0 5px 0;
    font-size: 16px;
    color: var(--text-main);
}

.friend-info p {
    margin: 0;
    font-size: 12px;
    color: var(--text-muted);
}

.remove-btn {
    background: transparent;
    color: #ef4444;
    border: 1px solid #ef4444;
    padding: 5px 10px;
    font-size: 12px;
    box-shadow: none;
}

.remove-btn:hover {
    background: #fef2f2;
    transform: none;
    box-shadow: none;
}

/* --- 実績通知＆ポップアップ用アニメーション --- */
@keyframes slideInRight {
    0% {
        transform: translateX(120%);
        opacity: 0;
    }

    10% {
        transform: translateX(-10px);
        opacity: 1;
    }

    20% {
        transform: translateX(0);
    }

    100% {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOutUp {
    from {
        transform: translateY(0);
        opacity: 1;
    }

    to {
        transform: translateY(-20px);
        opacity: 0;
    }
}

@keyframes popIn {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.achievement-toast {
    background: linear-gradient(135deg, #1e293b, #0f172a);
    color: white;
    padding: 15px 25px;
    border-radius: 10px;
    border-left: 6px solid #fcd34d;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    gap: 15px;
    animation: slideInRight 5s ease-in-out forwards;
    min-width: 260px;
    pointer-events: auto;
}

.achievement-icon {
    font-size: 32px;
    filter: drop-shadow(0 0 8px rgba(252, 211, 77, 0.6));
}

.achievement-content h4 {
    margin: 0 0 5px 0;
    color: #fcd34d;
    font-size: 16px;
    letter-spacing: 1px;
}

.achievement-content p {
    margin: 0;
    font-size: 13px;
    color: #cbd5e1;
}

/* --- スマホ最適化：ボトムナビゲーション --- */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #ffffff;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    justify-content: space-around;
    padding: 5px 0;
    padding-bottom: env(safe-area-inset-bottom);
    /* スマホ画面下の余白対応 */
}

.bottom-nav .nav-item {
    text-align: center;
    color: #64748b;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    flex: 1;
    padding: 8px 0;
    transition: 0.2s;
}

.bottom-nav .nav-item.active {
    color: var(--primary);
}

.bottom-nav .nav-icon {
    font-size: 22px;
    margin-bottom: 3px;
}

/* --- スマホ最適化：ボトムナビゲーション --- */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #ffffff;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    justify-content: space-around;
    padding: 5px 0;
    padding-bottom: env(safe-area-inset-bottom);
    /* スマホ画面下の余白対応 */
}

.bottom-nav .nav-item {
    text-align: center;
    color: #64748b;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    flex: 1;
    padding: 8px 0;
    transition: 0.2s;
}

.bottom-nav .nav-item.active {
    color: var(--primary);
}

.bottom-nav .nav-icon {
    font-size: 22px;
    margin-bottom: 3px;
}

@media (max-width: 768px) {
    .sidebar {
        display: none;
        /* スマホでは左側のメニューを隠す */
    }

    .bottom-nav {
        display: flex;
        /* スマホでは下メニューを表示 */
    }

    .app-container {
        margin-bottom: 70px;
        /* メニューに隠れないように余白を作る */
    }
}

/* --- カウントダウン表示のレスポンシブ対応 --- */
.countdown-mobile {
    display: none !important;
    /* PCではスマホ用を隠す */
}

@media (max-width: 768px) {
    .countdown-mobile {
        display: flex !important;
        /* スマホではスマホ用を出す */
    }

    .countdown-pc {
        display: none !important;
        /* スマホでは左下のPC用を隠す */
    }
}

/* --- 一番下までスクロールできるように余白を追加 --- */
.main-content {
    padding-bottom: 100px;
}

.tab-section {
    padding-bottom: 40px;
}

/* --- スマホ表示のさらなる最適化（レイアウト崩れ防止・強力版） --- */
@media (max-width: 768px) {

    /* 表の横スクロール対応 */
    .scoreContainer {
        overflow-x: auto !important;
        padding-bottom: 15px !important;
    }

    .scoreTable {
        min-width: 500px !important;
    }

    /* ズーム防止とマークシート調整 */
    input,
    select,
    button {
        font-size: 16px !important;
    }

    .mark-row {
        gap: 5px !important;
    }

    .choice {
        width: 28px !important;
        height: 28px !important;
        font-size: 13px !important;
        margin: 1px !important;
    }

    /* ★プロフィール＆ランキングの縦並び化 */
    .profile-header {
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        gap: 15px !important;
    }

    .profile-stats {
        flex-direction: column !important;
        gap: 10px !important;
    }

    /* フレンド＆ランキングの検索枠 */
    .friend-search-box>div {
        flex-direction: column !important;
    }

    .friend-search-box button {
        width: 100% !important;
        margin-top: 5px !important;
    }

    #tab-ranking select,
    #tab-ranking button {
        width: 100% !important;
        margin-top: 5px !important;
        margin-bottom: 5px !important;
        display: block !important;
    }

    /* グリッド（バッジ・フレンド一覧）を1列にする */
    .badges-grid,
    .friend-list-grid {
        grid-template-columns: 1fr !important;
        display: grid !important;
    }
}

/* --- 成績タブ（成績・グラフ・詳細レポート）のスマホ最適化（強力版） --- */
@media (max-width: 768px) {

    /* 年度・志望校の選択プルダウンを縦並びに */
    #tab-results>div:first-of-type {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    #result-year,
    #university {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* ★ ここが修正の要：判定とグラフを強制的に縦並び（上下）にする */
    .topArea {
        display: flex !important;
        flex-direction: column !important;
        /* 横並びを解除して縦にする魔法 */
        align-items: center !important;
        width: 100% !important;
        gap: 20px !important;
    }

    /* 判定ボックスとグラフボックスの幅を画面いっぱいに広げる */
    .judgeBox,
    .chartBox {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        margin: 0 !important;
    }

    /* グラフが潰れないように、スマホでも高さをしっかり確保する */
    .chartBox {
        min-height: 320px !important;
    }

    /* 詳細レポートの横スクロール対応 */
    #detailed-results-area>div {
        overflow-x: auto !important;
        padding-bottom: 15px !important;
    }

    #detailed-results-area .scoreTable {
        min-width: 450px !important;
    }
}
