/* リセット & 基本スタイル */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

/* ログイン画面 */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 1rem;
}

.login-container h1 {
    color: white;
    margin-bottom: 20px;
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    text-align: center;
}

.login-container p {
    color: white;
    margin-bottom: 30px;
    text-align: center;
}

/* ヘッダー */
header {
    background-color: #4285f4;
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    flex-wrap: wrap;
    gap: 0.5rem;
}

header h1 {
    font-size: clamp(1.2rem, 4vw, 1.5rem);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.user-info button {
    background-color: white;
    color: #4285f4;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    transition: opacity 0.3s;
    font-size: 0.9rem;
    touch-action: manipulation;
}

.user-info button:hover {
    opacity: 0.9;
}

/* タブメニュー */
.tab-menu {
    background-color: white;
    display: flex;
    border-bottom: 2px solid #e0e0e0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.tab-menu::-webkit-scrollbar {
    height: 4px;
}

.tab-menu::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.tab-menu::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 2px;
}

.tab-button {
    background: none;
    border: none;
    padding: 1rem 1.5rem;
    cursor: pointer;
    font-size: 1rem;
    color: #666;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
    white-space: nowrap;
    flex-shrink: 0;
    touch-action: manipulation;
}

.tab-button:hover {
    color: #4285f4;
}

.tab-button.active {
    color: #4285f4;
    border-bottom-color: #4285f4;
}

/* タブコンテンツ */
.tab-content {
    padding: 1rem;
    background-color: white;
    margin: 1rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* コントロール */
.controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.controls input[type="text"],
.controls select {
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    min-height: 44px;
}

.controls input[type="text"] {
    flex: 1;
    min-width: 150px;
}

/* テーブル */
.table-container {
    overflow-x: auto;
    margin-bottom: 2rem;
    -webkit-overflow-scrolling: touch;
}

#exam-table {
    width: 100%;
    border-collapse: collapse;
    background-color: white;
    min-width: 800px;
}

#exam-table th,
#exam-table td {
    padding: 0.75rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
    font-size: 0.9rem;
}

#exam-table th {
    background-color: #1f4e78;
    color: white;
    font-weight: bold;
    position: sticky;
    top: 0;
    z-index: 10;
}

#exam-table tr:nth-child(even) {
    background-color: #f9f9f9;
}

#exam-table tr:hover {
    background-color: #f0f0f0;
}

/* ステータスと難易度の色 */
.status-未 { background-color: #f4cccc !important; }
.status-進行中 { background-color: #d0e0e3 !important; }
.status-要復習 { background-color: #fff2cc !important; }
.status-済 { background-color: #d9ead3 !important; }

.difficulty-易 { background-color: #d9ead3 !important; }
.difficulty-中 { background-color: #fff2cc !important; }
.difficulty-難 { background-color: #f4cccc !important; }

/* 科目の色 */
.subject-数学 { background-color: #d9d2e9 !important; }
.subject-物理 { background-color: #d9ead3 !important; }
.subject-化学 { background-color: #fff2cc !important; }
.subject-英語 { background-color: #f9cb9c !important; }
.subject-専門 { background-color: #cfe2f3 !important; }

/* リンク */
.exam-link {
    color: #4285f4;
    text-decoration: none;
    font-weight: bold;
}

.exam-link:hover {
    text-decoration: underline;
}

/* 進捗状況 */
.progress-stats {
    background-color: #f8f9fa;
    padding: 1.5rem;
    border-radius: 8px;
}

.progress-stats h3 {
    margin-bottom: 1rem;
    color: #1f4e78;
}

#progress-info {
    font-size: 1rem;
    line-height: 1.8;
}

/* ランダム出題レイアウト */
.random-layout {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 2rem;
}

/* フィルターセクション */
.filter-section {
    background-color: #f8f9fa;
    padding: 1.5rem;
    border-radius: 8px;
}

.filter-section h2 {
    color: #4285f4;
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.filter-form {
    margin-bottom: 2rem;
}

.filter-item {
    margin-bottom: 1rem;
}

.filter-item label {
    display: block;
    color: #5f6368;
    font-weight: bold;
    margin-bottom: 0.3rem;
}

.filter-item input,
.filter-item select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #4285f4;
    border-radius: 4px;
    font-size: 1rem;
    min-height: 44px;
    touch-action: manipulation;
}

.select-problem-btn {
    width: 100%;
    background-color: #4285f4;
    color: white;
    border: none;
    padding: 1rem;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
    min-height: 48px;
    touch-action: manipulation;
}

.select-problem-btn:hover {
    background-color: #3367d6;
}

.select-problem-btn:active {
    background-color: #2851a3;
}

/* 学習記録更新 */
.update-section {
    background-color: white;
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.update-section h3 {
    color: #4285f4;
    margin-bottom: 1rem;
}

.update-form {
    margin-bottom: 1rem;
}

.update-item {
    margin-bottom: 0.75rem;
}

.update-item label {
    display: block;
    color: #5f6368;
    font-weight: bold;
    margin-bottom: 0.3rem;
}

.update-item select,
.update-item textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-size: 1rem;
    min-height: 44px;
    touch-action: manipulation;
}

.update-item textarea {
    min-height: 80px;
    resize: vertical;
}

.update-form button {
    background-color: #34a853;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1rem;
    min-height: 44px;
    touch-action: manipulation;
}

.update-form button:hover {
    background-color: #2e8b47;
}

.update-form button:active {
    background-color: #267238;
}

#update-message {
    margin-top: 0.5rem;
    padding: 0.5rem;
    border-radius: 4px;
    text-align: center;
    display: none;
}

#update-message.success {
    background-color: #e8f5e9;
    color: #2e7d32;
    display: block;
}

#update-message.error {
    background-color: #ffebee;
    color: #d32f2f;
    display: block;
}

/* 問題表示セクション */
.problem-section {
    background-color: white;
    padding: 1.5rem;
    border-radius: 8px;
}

.problem-section h2 {
    color: #4285f4;
    margin-bottom: 1rem;
}

.problem-info {
    background-color: #f8f9fa;
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1.5rem;
}

.info-row {
    display: flex;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.info-row span:first-child {
    color: #5f6368;
    font-weight: bold;
    min-width: 100px;
}

.info-row span:last-child {
    color: #333;
    font-weight: bold;
    word-break: break-word;
}

/* リンクカード */
.problem-links {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.link-card {
    flex: 1;
    min-width: 200px;
    background-color: #f8f9fa;
    padding: 1rem;
    border-radius: 4px;
    text-align: center;
}

.link-card h4 {
    color: #5f6368;
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
}

.link-button {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background-color: #4285f4;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-weight: bold;
    transition: background-color 0.3s;
    min-height: 44px;
    line-height: 1.5;
    touch-action: manipulation;
}

.link-button:hover:not(.disabled) {
    background-color: #3367d6;
}

.link-button:active:not(.disabled) {
    background-color: #2851a3;
}

.link-button.answer {
    background-color: #ea4335;
}

.link-button.answer:hover:not(.disabled) {
    background-color: #c62828;
}

.link-button.answer:active:not(.disabled) {
    background-color: #a52020;
}

.link-button.disabled {
    background-color: #ccc;
    cursor: not-allowed;
    pointer-events: none;
}

/* 問題画像表示 */
.problem-image-section {
    margin-top: 2rem;
}

.problem-image-section h3 {
    color: #4285f4;
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

#problem-image-container {
    background-color: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 1rem;
    min-height: 300px;
    text-align: center;
    overflow: auto;
}

#problem-image-container img {
    width: 100%;
    height: auto;
    max-width: none;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: block;
    margin: 0 auto;
}

#problem-image-container p {
    color: #666;
    font-style: italic;
    margin: 2rem auto;
}

/* スキャンセクション */
.scan-section {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
}

.scan-section h2 {
    color: #4285f4;
    margin-bottom: 1rem;
}

.scan-section p {
    margin-bottom: 2rem;
    color: #666;
}

.scan-options {
    margin-bottom: 2rem;
}

.scan-options label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.1rem;
    cursor: pointer;
}

.scan-options input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.scan-button {
    background-color: #4285f4;
    color: white;
    border: none;
    padding: 1rem 3rem;
    font-size: 1.2rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
    min-height: 48px;
    touch-action: manipulation;
}

.scan-button:hover {
    background-color: #3367d6;
}

.scan-button:active {
    background-color: #2851a3;
}

#scan-progress {
    margin-top: 2rem;
    font-size: 1.1rem;
    color: #666;
}

#scan-result {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 4px;
    display: none;
}

#scan-result.success {
    background-color: #e8f5e9;
    color: #2e7d32;
    display: block;
}

#scan-result.error {
    background-color: #ffebee;
    color: #d32f2f;
    display: block;
}

/* 管理者機能のスタイル */
.admin-section {
    max-width: 1200px;
    margin: 0 auto;
}

.admin-card {
    background-color: #f8f9fa;
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.admin-card h3 {
    color: #1f4e78;
    margin-bottom: 1.5rem;
    font-size: 1.3rem;
}

#user-progress-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

.user-progress-card {
    background-color: white;
    padding: 1rem;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
}

.user-progress-card h4 {
    color: #4285f4;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
    word-break: break-word;
}

.progress-bar {
    background-color: #e0e0e0;
    height: 20px;
    border-radius: 10px;
    overflow: hidden;
    margin: 0.5rem 0;
}

.progress-bar-fill {
    background-color: #34a853;
    height: 100%;
    transition: width 0.3s ease;
}

.progress-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: #666;
    margin-top: 0.5rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.progress-stats span {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.stat-label {
    font-weight: bold;
    color: #333;
}

#admin-exam-table {
    font-size: 0.9rem;
}

#admin-exam-table td {
    white-space: nowrap;
}

.difficulty-bar {
    display: flex;
    gap: 2px;
    align-items: center;
    font-size: 0.85rem;
    flex-wrap: wrap;
}

.difficulty-bar span {
    padding: 2px 6px;
    border-radius: 3px;
    color: white;
    min-width: 30px;
    text-align: center;
}

.diff-easy {
    background-color: #34a853;
}

.diff-medium {
    background-color: #fbbc04;
}

.diff-hard {
    background-color: #ea4335;
}

.user-management {
    background-color: #fff;
    padding: 1.5rem;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
}

.user-management code {
    background-color: #f5f5f5;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: monospace;
    word-break: break-all;
}

/* 表示設定 */
.display-settings {
    background-color: white;
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    margin-top: 1.5rem;
}

.display-settings h3 {
    color: #4285f4;
    margin-bottom: 1rem;
}

.setting-item {
    margin-bottom: 1rem;
}

.toggle-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.toggle-label input[type="checkbox"] {
    margin-right: 0.5rem;
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.toggle-text {
    font-weight: 500;
    color: #333;
}

.setting-description {
    margin-top: 0.25rem;
    margin-left: 1.75rem;
    font-size: 0.9rem;
    color: #666;
}

/* タグを非表示にする場合のスタイル */
.tags-hidden .info-row:nth-child(6) .tag-content {
    display: none;
}

.tags-hidden .info-row:nth-child(6) .tag-toggle-btn {
    display: inline-block;
}

.tag-toggle-btn {
    display: none;
    background-color: #4285f4;
    color: white;
    border: none;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    margin-left: 0.5rem;
    transition: background-color 0.3s;
}

.tag-toggle-btn:hover {
    background-color: #3367d6;
}

.tag-toggle-btn:active {
    background-color: #2851a3;
}

.tag-content {
    display: inline;
}

.tag-content.show {
    display: inline !important;
}

/* スマホ・タブレット対応（タブレット） */
@media (max-width: 1024px) {
    .random-layout {
        grid-template-columns: 1fr;
    }
    
    .filter-section {
        max-width: 100%;
        margin-bottom: 2rem;
    }
    
    .problem-links {
        flex-direction: column;
    }
    
    .link-card {
        min-width: 100%;
    }
}

/* スマホ対応 */
@media (max-width: 768px) {
    /* 全体的な余白調整 */
    .tab-content {
        margin: 0.5rem;
        padding: 1rem;
    }
    
    /* ヘッダー */
    header {
        flex-direction: column;
        text-align: center;
        padding: 0.75rem;
    }
    
    header h1 {
        font-size: 1.3rem;
        margin-bottom: 0.5rem;
    }
    
    .user-info {
        width: 100%;
        justify-content: center;
    }
    
    #user-email {
        font-size: 0.85rem;
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    /* タブメニュー */
    .tab-menu {
        padding: 0;
    }
    
    .tab-button {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
    
    /* フォーム要素 */
    .controls {
        flex-direction: column;
    }
    
    .controls input[type="text"],
    .controls select {
        width: 100%;
        font-size: 16px; /* iOS zoom防止 */
    }
    
    /* テーブル */
    .table-container {
        margin: 0 -1rem;
        padding: 0 0.5rem;
    }
    
    #exam-table th,
    #exam-table td {
        padding: 0.5rem 0.25rem;
        font-size: 0.8rem;
    }
    
    /* ランダム出題 */
    .filter-section,
    .update-section,
    .display-settings {
        padding: 1rem;
    }
    
    .filter-section h2 {
        font-size: 1.1rem;
    }
    
    .filter-item input,
    .filter-item select,
    .update-item select,
    .update-item textarea {
        font-size: 16px; /* iOS zoom防止 */
    }
    
    /* 問題表示 */
    .problem-section {
        padding: 1rem;
    }
    
    .problem-section h2 {
        font-size: 1.1rem;
    }
    
    .problem-info {
        padding: 0.75rem;
    }
    
    .info-row {
        margin-bottom: 0.75rem;
    }
    
    .info-row span:first-child {
        min-width: 80px;
        font-size: 0.9rem;
    }
    
    .info-row span:last-child {
        font-size: 0.9rem;
    }
    
    /* タグボタン（スマホ用） */
    .tag-toggle-btn {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
        margin-top: 0.25rem;
        margin-left: 0.5rem;
    }
    
    /* リンクボタン */
    .link-button {
        padding: 0.75rem 1rem;
        font-size: 0.95rem;
        width: 100%;
        display: block;
    }
    
    /* 画像表示 */
    #problem-image-container {
        padding: 0.5rem;
        min-height: 200px;
    }
    
    #problem-image-container img {
        width: 100%;
        max-width: none;
    }
    
    /* スキャン */
    .scan-button {
        padding: 0.75rem 2rem;
        font-size: 1.1rem;
    }
    
    /* 管理者画面 */
    .admin-card {
        padding: 1rem;
    }
    
    .admin-card h3 {
        font-size: 1.1rem;
    }
    
    #user-progress-summary {
        grid-template-columns: 1fr;
    }
    
    /* 進捗統計 */
    #progress-info {
        font-size: 0.9rem;
    }
    
    /* その他の調整 */
    .update-form button {
        width: 100%;
    }
    
    .select-problem-btn {
        font-size: 1rem;
    }
}

/* 超小型スマホ対応 */
@media (max-width: 380px) {
    header h1 {
        font-size: 1.1rem;
    }
    
    .tab-button {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }
    
    .filter-section h2,
    .problem-section h2,
    .update-section h3,
    .display-settings h3 {
        font-size: 1rem;
    }
    
    .info-row {
        flex-direction: column;
        gap: 0.25rem;
    }
    
    .info-row span:first-child {
        min-width: auto;
    }
    
    /* タグボタンをブロック表示 */
    .tag-toggle-btn {
        display: block;
        margin-left: 0;
        margin-top: 0.5rem;
    }
}

/* タッチデバイス向けのホバー無効化 */
@media (hover: none) {
    .tab-button:hover,
    .link-button:hover:not(.disabled),
    .select-problem-btn:hover,
    .update-form button:hover,
    .scan-button:hover {
        background-color: inherit;
    }
}

/* 印刷対応 */
@media print {
    header,
    .tab-menu,
    .controls,
    .filter-section,
    .update-section,
    .display-settings,
    .problem-links,
    .scan-section {
        display: none !important;
    }
    
    .tab-content {
        margin: 0;
        padding: 0;
        box-shadow: none;
    }
    
    #exam-table {
        font-size: 10pt;
    }
}