@import url('https://fonts.googleapis.com/css2?family=Zen+Maru+Gothic:wght@400;500;700&family=Shippori+Mincho:wght@500;700&display=swap');

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

@view-transition {
    navigation: auto;
}

body {
    font-family: 'Zen Maru Gothic', sans-serif;
    background: #EFEDE1;
    color: #2B2B24;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
    animation: appPageEnter 0.45s ease-out forwards;
}

@keyframes appPageEnter {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

body.page-exit {
    opacity: 0;
    transform: scale(0.99);
    transition: opacity 0.2s ease-in, transform 0.2s ease-in;
}

.app-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 14px;
    min-height: 100vh;
}

.screen { display: none; }
.screen.active { display: block; }

/* ---------- 共通パネル ---------- */
.hb-panel {
    border: 1px solid #c9c0a8;
    background: #F7F5EC;
    padding: 10px 16px;
    margin-bottom: 10px;
}

.panel-heading {
    font-family: 'Shippori Mincho', serif;
    font-size: 15px;
    margin: 0 0 8px 0;
}

/* ---------- ヘッダー ---------- */
.game-header { text-align: center; margin-bottom: 10px; }
.hb-title {
    font-family: 'Shippori Mincho', serif;
    font-size: 22px;
    font-weight: 700;
    margin: 0;
}
.hb-title span {
    display: block;
    font-size: 15px;
    color: #6b6552;
    font-family: 'Zen Maru Gothic', sans-serif;
    font-weight: 500;
    margin-top: 2px;
}
.hb-subtitle { font-size: 12px; color: #6b6552; margin-top: 4px; }

/* ---------- 遊び方カード ---------- */
.intro-card { padding: 10px 16px; }
.intro-card-header { display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.intro-card-header .panel-heading { margin: 0; }
.intro-body { margin-top: 10px; }
.intro-card ul { margin: 0; padding-left: 20px; font-size: 12px; line-height: 1.7; }
.intro-card strong { color: #2C4F6B; }

/* ---------- 学習記録カード ---------- */
.progress-card { text-align: center; }
.progress-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    row-gap: 8px;
    margin-bottom: 8px;
}
.progress-filter-options { justify-content: center; }
.progress-card-header .panel-heading { margin: 0; }
.progress-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-bottom: 8px;
}
.progress-stat {
    border: 1px solid #ded6bd;
    background: #EFEDE1;
    padding: 6px 6px;
}
.progress-stat--clickable {
    cursor: pointer;
    transition: background .12s, border-color .12s;
}
.progress-stat--clickable:hover,
.progress-stat--clickable:focus-visible {
    background: #E4E0CC;
    border-color: #2C4F6B;
    outline: none;
}
.ps-value { font-size: 17px; font-weight: 700; color: #2C4F6B; font-variant-numeric: tabular-nums; }
.ps-label { font-size: 10px; color: #6b6552; margin-top: 2px; }
.progress-reset-btn {
    font-family: 'Zen Maru Gothic', sans-serif;
    border: 1px solid #9a5a4a;
    background: #F7F5EC;
    color: #9a5a4a;
    padding: 5px 12px;
    font-size: 11px;
    cursor: pointer;
    flex-shrink: 0;
}
.progress-reset-btn:hover { background: #9a5a4a; color: #F7F5EC; }
.priority-toggle-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 8px;
}
.priority-toggle-label { font-size: 12px; color: #4b4636; }

/* ---------- 設定カード ---------- */
.difficulty-card { text-align: center; }
.difficulty-card .settings-heading { text-align: left; }
.settings-row {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 12px;
}
.settings-row:last-of-type { margin-bottom: 0; }
.difficulty-label { font-size: 13px; color: #6b6552; flex-shrink: 0; }
.difficulty-options { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.diff-option {
    border: 1px solid #b9b09a;
    background: #F7F5EC;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    position: relative;
}
.diff-option input { position: absolute; opacity: 0; pointer-events: none; }
.diff-option.active { background: #2C4F6B; color: #F7F5EC; border-color: #2C4F6B; }

/* ---------- モード選択 ---------- */
.mode-selection { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.hb-btn {
    font-family: 'Zen Maru Gothic', sans-serif;
    border: 1px solid #2C4F6B;
    background: #F7F5EC;
    color: #2B2B24;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 14px;
}
button.hb-btn.btn-primary, button.hb-btn.btn-secondary {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    text-align: left;
    width: 100%;
}
.btn-primary { border-color: #2C4F6B; }
.btn-primary:hover { background: #2C4F6B; color: #F7F5EC; }
.btn-secondary { border-color: #B5652D; }
.btn-secondary:hover { background: #B5652D; color: #F7F5EC; }
.btn-icon { font-size: 20px; }
.btn-text { display: flex; flex-direction: column; }
.btn-text strong { font-size: 14px; }
.btn-text span { font-size: 11px; color: #6b6552; }
.btn-text .btn-best { font-size: 11px; color: #2C4F6B; font-weight: 700; margin-top: 1px; }
.btn-primary:hover .btn-text span, .btn-secondary:hover .btn-text span { color: #eee; }

.back-home-container { text-align: center; margin-top: 4px; }
.back-link { color: #6b6552; font-size: 12px; text-decoration: none; border-bottom: 1px dashed #6b6552; }

/* ---------- ベスト記録カード ---------- */
.records-card { padding: 10px 16px; }
.records-card-header { display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.records-card-header .panel-heading { margin: 0; }
.records-toggle-icon { font-size: 12px; color: #6b6552; transition: transform .15s; }
.records-toggle-icon.open { transform: rotate(90deg); }
.records-body { margin-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.records-hint { font-size: 11px; color: #6b6552; margin: 0; }
.records-col-title { font-size: 12px; font-weight: 700; color: #2C4F6B; margin-bottom: 6px; }
.records-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.record-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    background: #EFEDE1;
    border-left: 3px solid #b9b09a;
    font-size: 12px;
}
.record-item.rank-1 { border-left-color: #B5652D; }
.record-rank { font-weight: 700; width: 18px; text-align: center; color: #6b6552; }
.record-value { font-weight: 700; min-width: 64px; }
.record-date { color: #6b6552; font-size: 11px; flex: 1; }
.record-delete-btn {
    border: 1px solid #9a5a4a;
    background: #F7F5EC;
    color: #9a5a4a;
    width: 22px;
    height: 22px;
    line-height: 1;
    font-size: 12px;
    cursor: pointer;
    flex-shrink: 0;
}
.record-delete-btn:hover { background: #9a5a4a; color: #F7F5EC; }
.records-empty { font-size: 12px; color: #a39a80; padding: 4px 2px; }

.record-mode-toggle-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 10px 0 0 0;
    padding-top: 10px;
    border-top: 1px dashed #ded6bd;
}
.record-mode-toggle-label { font-size: 12px; color: #4b4636; }

/* ---------- ゲームHUD ---------- */
.game-hud { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
.hud-btn { border-color: #9a5a4a; font-size: 12px; padding: 6px 12px; }
.hud-btn:hover { background: #9a5a4a; color: #F7F5EC; }
.hud-stats { display: flex; gap: 16px; }
.stat-item { text-align: center; }
.stat-label { display: block; font-size: 11px; color: #6b6552; }
.stat-value { display: block; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

.game-instruction { text-align: center; font-size: 12px; color: #6b6552; margin-bottom: 12px; }

/* ---------- 例文パネル ---------- */
.sentence-panel { text-align: center; position: relative; }
.sentence-header { font-size: 12px; color: #6b6552; margin-bottom: 6px; }
.sentence-text {
    font-size: 1.15rem;
    line-height: 1.9;
    font-weight: 500;
    min-height: 3.5em;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 6px;
}
/* ---------- 共通トグルスイッチ ---------- */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider.round { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: #ded6bd; border-radius: 22px; transition: .2s; }
.slider.round:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background: #F7F5EC; border-radius: 50%; transition: .2s; }
input:checked + .slider.round { background: #2C4F6B; }
input:checked + .slider.round:before { transform: translateX(18px); }

.hint-text-box { font-size: 12px; color: #4b4636; margin-top: 4px; min-height: 1.2em; }
.hint-text-box.show { background: #EFEDE1; padding: 6px 8px; border-left: 3px solid #2C4F6B; display: inline-block; }

/* ---------- 組み立てエリア ---------- */
.idiom-board { display: flex; flex-direction: column; gap: 4px; }

.assembly-row {
    display: grid;
    grid-template-columns: 1fr 1.6fr 1fr;
    gap: 12px;
    align-items: stretch;
}

.shelf-box {
    border: 1px solid #c9c0a8;
    background: #F7F5EC;
    padding: 10px;
    display: flex;
    flex-direction: column;
}
.shelf-title {
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    padding: 4px 0;
    margin-bottom: 8px;
    color: #F7F5EC;
}
.bg-front { background: #2C4F6B; }
.bg-back { background: #B5652D; }
.bg-meaning { background: #4F7A45; }

.balloon-shelf {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-content: flex-start;
    flex: 1;
    min-height: 90px;
}

.meaning-shelf-box { padding-top: 10px; }
.meaning-shelf { min-height: 70px; }

/* ---------- 中央コンボパネル ---------- */
.combo-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; margin-bottom: 0; text-align: center; }
.combo-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 8px;
    gap: 8px;
}
.combo-header .combo-label { margin-bottom: 0; text-align: left; }
.hint-toggle-container { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.hint-label { font-size: 11px; color: #6b6552; white-space: nowrap; }
.hint-toggle-container .switch { width: 32px; height: 18px; }
.hint-toggle-container .slider.round:before { height: 12px; width: 12px; left: 3px; bottom: 3px; }
.hint-toggle-container input:checked + .slider.round:before { transform: translateX(14px); }
.combo-label { font-size: 12px; color: #6b6552; margin-bottom: 8px; }
.meaning-label { margin-top: 16px; }
.combo-slots { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.combo-slot {
    min-width: 96px;
    min-height: 56px;
    border: 2px dashed #b9b09a;
    background: #EFEDE1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    font-weight: 700;
    font-size: 15px;
    transition: border-color .15s, background .15s;
}
.combo-slot.meaning-slot { min-width: 220px; font-size: 13px; font-weight: 500; }
.slot-placeholder { color: #a39a80; font-size: 12px; font-weight: 500; }
.combo-slot.filled { border-style: solid; border-color: #4F7A45; background: #E7EFE1; }
.combo-slot.drag-over { border-color: #2C4F6B; background: #E6EBEF; }
.combo-slot.wrong-flash { border-color: #9a5a4a; background: #F6E1E8; }

/* ---------- バルーン ---------- */
.balloon {
    border: 1.5px solid #2B2B2450;
    background: #F7F5EC;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 700;
    cursor: grab;
    user-select: none;
    touch-action: none;
    animation: bob 3s ease-in-out infinite;
    line-height: 1.4;
}
.balloon[data-slot="front"] { border-color: #2C4F6B; color: #2C4F6B; }
.balloon[data-slot="back"] { border-color: #B5652D; color: #B5652D; }
.balloon[data-slot="meaning"] { border-color: #4F7A45; color: #4F7A45; font-size: 12px; max-width: 220px; }

.balloon.dragging { opacity: 0.25; }
.balloon.used { visibility: hidden; }

@keyframes bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

.drag-balloon {
    position: fixed;
    z-index: 999;
    transform: translate(-50%, -50%);
    border: 2px solid #2B2B24;
    background: #F7F5EC;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 700;
    pointer-events: none;
    max-width: 220px;
    text-align: center;
}

/* ---------- ポップアップ ---------- */
.correct-popup, .incorrect-popup {
    position: fixed;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Shippori Mincho', serif;
    font-size: 1.6rem;
    font-weight: 700;
    padding: 10px 26px;
    border: 2px solid;
    background: #F7F5EC;
    z-index: 1000;
    animation: pop-in-out 0.85s ease forwards;
}
.correct-popup { color: #4F7A45; border-color: #4F7A45; }
.incorrect-popup { color: #9a5a4a; border-color: #9a5a4a; }
@keyframes pop-in-out {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
    15% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    80% { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%, -60%) scale(0.9); }
}

/* ---------- リザルト画面 ---------- */
.result-card { max-width: 700px; margin: 0 auto; }
.result-best-badge {
    text-align: center;
    font-family: 'Shippori Mincho', serif;
    font-size: 15px;
    font-weight: 700;
    color: #B5652D;
    border: 1.5px solid #B5652D;
    background: #FBF1E7;
    padding: 6px 10px;
    margin-bottom: 14px;
}
.result-best-badge.result-best-badge--off {
    font-family: 'Zen Maru Gothic', sans-serif;
    font-size: 12px;
    font-weight: 500;
    color: #6b6552;
    border-color: #b9b09a;
    background: #EFEDE1;
}
.result-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    text-align: center;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid #c9c0a8;
}
.res-label { font-size: 11px; color: #6b6552; }
.res-value { font-size: 16px; font-weight: 700; margin-top: 2px; }

.played-questions-list { display: flex; flex-direction: column; gap: 0; max-height: 360px; overflow-y: auto; }
.played-q-wrapper { border-bottom: 1px dashed #c9c0a8; }
.played-q-item { display: flex; align-items: center; gap: 10px; padding: 8px 4px; font-size: 13px; }
.q-status { width: 20px; text-align: center; font-weight: 700; }
.q-status.correct { color: #4F7A45; }
.q-status.incorrect { color: #9a5a4a; }
.q-info { flex: 1; }
.q-ans-info { font-size: 12px; color: #6b6552; text-align: right; white-space: nowrap; }
.wrong-ans { text-decoration: line-through; color: #9a5a4a; margin-right: 6px; }
.correct-val { color: #4F7A45; font-weight: 700; }
.btn-explain {
    font-family: 'Zen Maru Gothic', sans-serif;
    border: 1px solid #8C7BA6;
    background: #F7F5EC;
    color: #5c4d78;
    padding: 3px 10px;
    font-size: 11px;
    cursor: pointer;
}
.btn-explain.active, .btn-explain:hover { background: #8C7BA6; color: #F7F5EC; }
.explain-bubble-box {
    margin: 0 4px 10px 30px;
    padding: 8px 10px;
    font-size: 12px;
    background: #EFEDE1;
    border-left: 3px solid #8C7BA6;
    color: #4b4636;
}

.result-actions { display: flex; gap: 10px; margin-top: 18px; }
.result-actions .hb-btn { flex: 1; padding: 12px; font-weight: 700; }

/* ---------- 学習記録 詳細モーダル ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(43, 43, 36, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 1100;
}
.modal-box {
    background: #F7F5EC;
    border: 1px solid #c9c0a8;
    width: 100%;
    max-width: 480px;
    max-height: 82vh;
    display: flex;
    flex-direction: column;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid #ded6bd;
    flex-shrink: 0;
}
.modal-header .panel-heading { margin: 0; }
.modal-close-btn {
    border: 1px solid #9a5a4a;
    background: #F7F5EC;
    color: #9a5a4a;
    width: 26px;
    height: 26px;
    line-height: 1;
    font-size: 13px;
    cursor: pointer;
    flex-shrink: 0;
}
.modal-close-btn:hover { background: #9a5a4a; color: #F7F5EC; }
.modal-body {
    padding: 10px 14px 14px;
    overflow-y: auto;
}
.progress-modal-empty { font-size: 13px; color: #6b6552; text-align: center; padding: 12px 0; }
.progress-modal-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.progress-modal-item {
    border-left: 3px solid #b9b09a;
    background: #EFEDE1;
    padding: 6px 10px;
}
.pm-idiom-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pm-idiom { font-weight: 700; font-size: 14px; }
.pm-meaning { font-size: 11px; color: #6b6552; margin-top: 2px; }
.pm-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 5px; }
.pm-badge { font-size: 11px; font-weight: 700; padding: 1px 7px; border: 1px solid; }
.pm-badge--correct { color: #4F7A45; border-color: #4F7A45; background: #E7EFE1; }
.pm-badge--wrong { color: #9a5a4a; border-color: #9a5a4a; background: #F6E1E8; }
.pm-tier { font-size: 10px; font-weight: 700; padding: 1px 6px; flex-shrink: 0; }
.pm-tier--review { color: #B5652D; border: 1px solid #B5652D; background: #FBF1E7; }
.pm-tier--mastered { color: #2C4F6B; border: 1px solid #2C4F6B; background: #E6EBEF; }
.pm-count { font-size: 11px; color: #4b4636; }

/* ---------- レスポンシブ ---------- */
@media (min-width: 560px) {
    .records-body { flex-direction: row; flex-wrap: wrap; gap: 10px 20px; }
    .records-hint { flex-basis: 100%; }
    .records-col { flex: 1; min-width: 200px; }
}

@media (max-width: 720px) {
    .assembly-row { grid-template-columns: 1fr; }
    .shelf-box { min-height: unset; }
    .balloon-shelf { min-height: unset; }
    .combo-slot.meaning-slot { min-width: 160px; }
    .mode-selection { gap: 8px; }
}

@media (max-width: 480px) {
    .app-container { padding: 8px; }
    .game-hud { margin-bottom: 6px; }
    .game-instruction { margin-bottom: 6px; font-size: 11px; }
    .idiom-board { gap: 6px; }
    .sentence-panel { padding: 8px 10px; }
    .sentence-text { font-size: 0.95rem; line-height: 1.5; min-height: 2.6em; padding: 2px 4px; }
    .assembly-row { gap: 6px; }
    .shelf-box { padding: 6px; }
    .shelf-title { padding: 3px 0; margin-bottom: 5px; font-size: 11px; }
    .balloon-shelf { gap: 5px; }
    .combo-panel { padding: 8px 10px; }
    .combo-header { margin-bottom: 5px; }
    .combo-label { margin-bottom: 5px; font-size: 11px; }
    .meaning-label { margin-top: 8px; }
    .combo-slots { gap: 5px; }
    .combo-slot { min-width: 74px; min-height: 42px; font-size: 13px; padding: 4px 6px; }
    .combo-slot.meaning-slot { min-width: 130px; font-size: 11px; }
    .balloon { padding: 5px 9px; font-size: 12px; }
    .balloon[data-slot="meaning"] { font-size: 10px; max-width: 150px; }
    .meaning-shelf-box { padding-top: 6px; }
}
