/* ベーススタイル */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Noto Sans JP', sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
    -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea {
    font-family: 'Noto Sans JP', sans-serif;
}

/* 問題セット選択画面 */
.set-selection-screen {
    padding: 20px;
}

.user-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    margin-bottom: 8px;
    font-size: 14px;
}

.user-bar a {
    color: #2196F3;
    text-decoration: none;
    font-weight: 500;
}

h1 {
    text-align: center;
    font-size: 24px;
    margin-bottom: 20px;
}

.problem-sets-list {
    max-width: 600px;
    margin: 0 auto;
}

.problem-set-item {
    background: white;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.2s ease;
}

.problem-set-item:active {
    transform: scale(0.98);
}

.problem-set-title {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 8px;
}

.problem-set-description {
    font-size: 14px;
    color: #666;
}

.problem-set-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    font-size: 14px;
}

/* ゲーム設定画面 */
.game-settings-screen {
    padding: 20px;
}

.settings-header {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
}

.back-button {
    background: none;
    border: none;
    font-size: 24px;
    padding: 10px;
    margin-right: 10px;
}

.mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.mode-button {
    padding: 15px;
    border: 2px solid #ccc;
    border-radius: 8px;
    background: white;
    color: #888;
    font-size: 16px;
    font-weight: bold;
    transition: all 0.2s ease;
    cursor: pointer;
    font-family: 'Noto Sans JP', sans-serif;
}
.mode-button:hover {
    border-color: #2196F3;
    color: #2196F3;
}
.mode-button.active {
    background: #2196F3;
    color: white;
    border-color: #2196F3;
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

.mode-button.active {
    background: #2196F3;
    opacity: 1;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}
.start-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* タイマー設定 */
.timer-options {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.timer-option {
    flex: 1;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: white;
}

.timer-option.active {
    background: #2196F3;
    color: white;
    border-color: #1976D2;
}

/* サウンド設定 */
.sound-settings {
    margin-bottom: 20px;
}

.sound-settings label {
    display: block;
    margin-bottom: 10px;
}

.volume-control {
    margin-top: 15px;
}

.volume-control input[type="range"] {
    width: 100%;
    height: 20px;
}

/* ゲーム画面 - キーボード表示前提 */
.game-screen {
    padding: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #f5f5f5;
    z-index: 100;
}

/* 上部バー: 終了 + ステータス + タイマーを1行に圧縮 */
.game-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: white;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
    min-height: 36px;
}

.quit-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: #f44336;
    color: white;
    font-size: 14px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.topbar-stats {
    display: flex;
    gap: 12px;
    font-size: 13px;
    color: #555;
}

.topbar-stats b {
    color: #2196F3;
}

.topbar-timer {
    font-size: 14px;
    font-weight: bold;
    color: #333;
    flex-shrink: 0;
}

/* メイン表示エリア - 残りスペースを埋める */
.game-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    overflow: hidden;
    min-height: 0;
}

.game-main .chinese-text {
    font-size: 26px;
    font-weight: bold;
    margin-bottom: 6px;
    text-align: center;
    line-height: 1.3;
}

.game-main .pinyin-text {
    font-size: 20px;
    color: #666;
    margin-bottom: 4px;
    text-align: center;
    min-height: 28px;
    word-break: break-all;
    line-height: 1.6;
    letter-spacing: 0.5px;
}

.game-main .japanese-text {
    font-size: 14px;
    color: #999;
    text-align: center;
}

/* 下部: プログレス + 入力フィールド */
.game-bottom {
    flex-shrink: 0;
    padding: 4px 12px 8px;
    background: white;
    border-top: 1px solid #eee;
}

.game-bottom .progress-bar {
    margin-bottom: 6px;
}

.game-bottom .typing-input {
    width: 100%;
    padding: 12px;
    font-size: 18px;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: white;
    margin: 0;
    font-family: 'Source Sans Pro', 'Noto Sans JP', sans-serif;
    letter-spacing: 1px;
    caret-color: #2196F3;
}

.game-bottom .typing-input:focus {
    border-color: #2196F3;
    outline: none;
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.15);
}

/* プログレスバー */
.progress-bar {
    height: 4px;
    background: #eee;
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 20px;
}

.progress-fill {
    height: 100%;
    background: #4CAF50;
    width: 0%;
    transition: width 0.3s ease;
}

/* 結果画面 */
.result-screen {
    padding: 20px;
    background: white;
    height: 100vh;
}

.result-screen h2 {
    text-align: center;
    margin-bottom: 30px;
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 30px;
}

.result-item {
    text-align: center;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
}

.result-label {
    font-size: 14px;
    color: #666;
    margin-bottom: 5px;
}

.result-value {
    font-size: 24px;
    font-weight: bold;
}

.username-input {
    margin-bottom: 30px;
}

.username-input label {
    display: block;
    margin-bottom: 10px;
}

.username-input input {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
}

.result-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.result-buttons button {
    padding: 15px;
    border: none;
    border-radius: 8px;
    background: #4CAF50;
    color: white;
    font-size: 16px;
    font-weight: bold;
}

.result-buttons button:last-child {
    background: #2196F3;
}

/* 共通のユーティリティクラス */
.hidden {
    display: none !important;
}

/* スタートボタン: 常に下部に固定表示 */
.start-button {
    position: sticky;
    bottom: 0;
    width: 100%;
    padding: 18px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 17px;
    font-weight: bold;
    margin-top: 20px;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.12);
    z-index: 50;
    cursor: pointer;
}
.start-button:active { background: #388e3c; }
.game-settings-screen { padding-bottom: 20px; }

/* アニメーション */
@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-in {
    animation: fade-in 0.3s ease;
}

/* サーフェイスのスタイル調整 */
input[type="text"],
input[type="checkbox"],
input[type="radio"],
button {
    -webkit-appearance: none;
    appearance: none;
    border-radius: 0;
}

/* カスタムチェックボックスとラジオボタン */
input[type="checkbox"] {
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-radius: 4px;
    position: relative;
    margin-right: 8px;
    vertical-align: middle;
}

input[type="checkbox"]:checked::after {
    content: "";
    position: absolute;
    left: 6px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid #4CAF50;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

input[type="radio"] {
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-radius: 50%;
    position: relative;
    margin-right: 8px;
    vertical-align: middle;
}

input[type="radio"]:checked::after {
    content: "";
    position: absolute;
    left: 4px;
    top: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4CAF50;
}

/* タップ時のハイライトを防止 */
* {
    -webkit-tap-highlight-color: transparent;
}

/* iOS用の入力フィールドスタイル調整 */
input[type="text"] {
    -webkit-appearance: none;
    border-radius: 8px;
}

/* セーフエリアの考慮 */
@supports (padding: max(0px)) {
    .game-screen,
    .result-screen {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}

/* 小さい画面での調整 */
@media (max-width: 320px) {
    .game-main .chinese-text { font-size: 22px; }
    .game-main .pinyin-text { font-size: 17px; }
}

/* 横向き時の調整 */
@media screen and (orientation: landscape) {
    .game-main { padding: 4px 16px; }
    .game-main .chinese-text { font-size: 22px; margin-bottom: 2px; }
    .game-main .pinyin-text { font-size: 17px; }
    .game-main .japanese-text { font-size: 12px; }
}
/* 現在入力すべき文字のハイライト */
.current-char {
    color: #FF9800;
    font-weight: bold;
    text-decoration: underline;
    text-underline-offset: 4px;
}

/* ミスタイプ時のフラッシュ */
.game-main.mistake-flash {
    background: #fff0f0;
    transition: background 0.1s;
}

/* 単語完了アニメーション */
.game-main.word-complete {
    background: #f0fff0;
    transition: background 0.2s;
}

/* 音声モード: 全ての視覚情報を隠す */
body.audio-mode .chinese-text,
body.audio-mode .pinyin-text,
body.audio-mode .japanese-text {
    visibility: hidden;
    height: 0;
    overflow: hidden;
}
body.audio-mode .audio-mode-notice {
    display: block !important;
}
body:not(.audio-mode) .audio-only-btn { display: none !important; }
body.audio-mode .visual-only-btn { display: none !important; }

/* iOS簡体字/繁体字フォント指定 */
[lang="zh-Hans"], .chinese-text[lang="zh-Hans"] {
    font-family: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}
[lang="zh-Hant"], .chinese-text[lang="zh-Hant"] {
    font-family: 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
}
