/* 全体設定 */
body {
    margin: 0;
    padding: 0;
    font-family: "Yomogi", cursive; /* 全て手書きフォントに統一 */
    background-color: #0e2b1e; /* 壁の色（さらに暗い緑） */
    color: #fff;
    overflow-x: hidden;
}

/* モーダル表示中は背景スクロールを止める */
body.modal-open {
    overflow: hidden;
}

/* === 黒板の本体 === */
.blackboard-area {
    position: relative;
    width: 90%;
    max-width: 800px;
    min-height: 80vh;
    margin: clamp(12px, 3vh, 40px) auto;
    background-color: #1a3c28; /* 深緑 */
    
    /* 黒板の木枠 */
    border: 12px solid #5d4037;
    border-radius: 8px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);

    /* 黒板の質感（ノイズ） */
    background-image: 
        radial-gradient(circle, rgba(255,255,255,0.05) 1px, transparent 1px);
    background-size: 20px 20px;
    
    padding: clamp(16px, 3vw, 40px);
    display: flex;
    justify-content: center;
    align-items: center;
}

/* === コース選択モーダル（タイトルの上に重ねる） === */
#search-modal {
    position: absolute;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}

/* ログインモーダル */
#login-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}

/* 表示名モーダル */
#name-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}

.auth-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px dashed rgba(255,255,255,0.25);
    border-radius: 10px;
    background: rgba(0,0,0,0.18);
    margin-bottom: 18px;
}

.my-problems-box {
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 10px;
    padding: 10px;
    background: rgba(0,0,0,0.18);
    max-height: 260px;
    overflow: auto;
}

.my-problem-item {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 10px;
    padding: 8px;
    border-bottom: 1px dashed rgba(255,255,255,0.18);
}
.my-problem-item:last-child {
    border-bottom: none;
}
.my-problem-title {
    font-size: 0.95rem;
    line-height: 1.3;
    opacity: 0.92;
}
.my-problem-meta {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 4px;
}

/* === イラスト編集モーダル（PowerPoint風） === */
#illustration-editor-modal {
    position: fixed; /* スクロール位置に関係なく常に画面に出す */
    inset: 0;
    z-index: 120;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}

.illustration-editor {
    width: 100%;
    max-width: 900px;
    margin: 20px auto;
    padding: 18px;
    border: 2px solid rgba(255,255,255,0.4);
    border-radius: 10px;
    background: rgba(26, 60, 40, 0.95);
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}

.editor-header {
    margin-bottom: 12px;
}

.editor-body {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 16px;
    align-items: start;
}

.editor-controls {
    border-right: 1px dashed rgba(255,255,255,0.25);
    padding-right: 14px;
}

.editor-canvas-wrap {
    padding-left: 4px;
}

.illust-canvas {
    position: relative;
    width: 100%;
    height: 360px;
    border: 2px solid rgba(255,255,255,0.35);
    border-radius: 10px;
    background:
        linear-gradient(rgba(255,255,255,0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.06) 1px, transparent 1px);
    background-size: 24px 24px;
    overflow: hidden;
}

.illust-object {
    position: absolute;
    left: 80%;
    top: 70%;
    transform: translate(-50%, -50%);
    width: 220px;
    height: 220px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    cursor: grab;
    user-select: none;
}
.illust-object:active {
    cursor: grabbing;
}
.illust-object img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    filter: drop-shadow(2px 2px 0px rgba(255,255,255,0.5));
    pointer-events: none;
}

/* === イラスト編集：レイヤー一覧 === */
.illust-layer-list {
    max-height: 160px;
    overflow: auto;
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 8px;
    padding: 6px;
    background: rgba(0,0,0,0.25);
}
.illust-layer-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
}
.illust-layer-item:hover {
    background: rgba(255,255,255,0.08);
}
.illust-layer-item.selected {
    background: rgba(243,156,18,0.18);
    border: 1px solid rgba(243,156,18,0.45);
}
.illust-layer-name {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.85);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.illust-layer-actions {
    display: flex;
    gap: 6px;
}
.illust-layer-actions button {
    margin: 0;
}

.editor-footer {
    margin-top: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

@media (max-width: 800px) {
    .editor-body {
        grid-template-columns: 1fr;
    }
    .editor-controls {
        border-right: none;
        padding-right: 0;
        border-bottom: 1px dashed rgba(255,255,255,0.25);
        padding-bottom: 12px;
    }
    .illust-canvas {
        height: 300px;
    }
}

/* 画面の切り替え制御 */
.screen {
    width: 100%;
    display: none; /* 基本は非表示 */
    animation: fadeIn 0.5s;
    position: relative;
    z-index: 2; /* タイトル装飾レイヤーより上 */
}
.screen.active {
    display: block; /* activeがつくと表示 */
}
.hidden {
    display: none !important;
}

/* === タイトル画面 === */
#title-screen { text-align: center; }

/* タイトル装飾レイヤー（黒板全体に散りばめる） */
.title-random-layer {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    overflow: hidden; /* 端で途切れないよう、JS側で内側に収める */
}

.title-formula {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-family: "Times New Roman", serif;
    color: rgba(255,255,255,0.9);
    text-shadow: 0 1px 0 rgba(255,255,255,0.18);
    white-space: nowrap;
    user-select: none;
    filter: blur(0.15px);
}

.title-float-img {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    object-fit: contain;
    filter: drop-shadow(2px 2px 0px rgba(255,255,255,0.45));
    opacity: 0.9;
}
.title-float-img.pop {
    animation: bounce 1s infinite;
}

.main-title {
    font-size: clamp(2.1rem, 4.6vw, 3rem);
    border: 3px solid rgba(255,255,255,0.7);
    padding: clamp(12px, 2.2vw, 20px);
    transform: rotate(-2deg); /* 少し傾ける */
    margin-bottom: clamp(12px, 2.4vh, 24px);
}

/* === 共通パーツ：チョーク風ボタン === */
.chalk-btn {
    background: transparent;
    border: 2px solid white;
    color: white;
    font-family: "Yomogi", cursive;
    font-size: 1.2rem;
    padding: 10px 30px;
    border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px; /* 手書き風の歪んだ円 */
    cursor: pointer;
    transition: 0.2s;
    margin: 10px;
}
.chalk-btn:hover {
    background: rgba(255,255,255,0.1);
    transform: scale(1.05);
}
.chalk-btn.small {
    padding: 5px 15px;
    font-size: 1rem;
}

/* === ゲーム画面 === */
.header-info {
    border-bottom: 1px solid rgba(255,255,255,0.3);
    padding-bottom: 10px;
    display: flex;
    justify-content: space-between;
    margin-bottom: 30px;
    font-size: 1.2rem;
}

.problem-box {
    font-size: 1.5rem;
    line-height: 1.8;
    margin-bottom: 40px;
}

/* 入力エリア */
.answer-area {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 30px;
}

/* 入力欄をチョーク風に（枠線を消して下線だけにする） */
input, textarea {
    background: transparent;
    border: none;
    border-bottom: 2px solid white;
    color: white;
    font-family: "Yomogi", cursive;
    font-size: 1.5rem;
    padding: 5px;
    outline: none;
    text-align: center;
}
input::placeholder, textarea::placeholder {
    color: rgba(255,255,255,0.3);
}

/* 結果表示 */
.result-box {
    border-top: 1px dashed rgba(255,255,255,0.5);
    padding-top: 20px;
    margin-top: 20px;
}
.red-pen {
    color: #ff6b6b; /* 赤チョーク色 */
    font-weight: bold;
}
#tsukkomi-content {
    color: #ff6b6b;
}

/* 戻るリンク */
.back-link {
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    text-decoration: underline;
    cursor: pointer;
    margin-top: 120px;
    font-family: "Yomogi", cursive;
}

/* === 作成画面 === */
.input-group {
    margin-bottom: 20px;
    text-align: left;
}
.input-group label {
    display: block;
    font-size: 0.9rem;
    color: rgba(255,255,255,0.7);
}
.chalk-input {
    width: 100%;
    text-align: left;
}
.row {
    display: flex;
    gap: 20px;
}

/* アニメーション */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
/* === 記号入力ボタン === */
.symbol-buttons {
    margin-top: 10px;
    display: flex;
    gap: 5px;
    flex-wrap: wrap; /* スマホではみ出さないように折り返し */
}

/* 小さなチョークボタン */
.chalk-btn.mini {
    padding: 2px 10px;
    font-size: 1rem;
    min-width: 40px;
    border-radius: 5px; /* ここは丸すぎない方が押しやすい */
    margin: 0;
}

.chalk-btn.mini:active {
    background-color: rgba(255,255,255,0.3); /* 押した感 */
}
/* === 記号入力ボタンエリア === */
.symbol-buttons {
    margin-top: 10px;
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

/* 小さなボタンのスタイル */
.chalk-btn.mini {
    padding: 2px 12px;
    font-size: 1.1rem;
    min-width: 40px;
    border-radius: 4px;
    margin: 0;
    line-height: 1.5;
}

.chalk-btn.mini:active {
    transform: scale(0.95); /* 押したときに少し凹む */
}

/* === 記号パレット（隠しエリア） === */
#symbol-palette-container {
    margin-top: 10px;
    border: 2px dashed rgba(255,255,255,0.3);
    padding: 10px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
}

/* カテゴリごとの区切り */
.symbol-category {
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 8px;
}

.symbol-category:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.symbol-category strong {
    display: block;
    font-size: 0.8rem;
    color: #aaa;
    margin-bottom: 5px;
}

/* パレット内のボタンリスト */
.symbol-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* パレット内の各ボタン */
.symbol-btn {
    font-family: "Times New Roman", serif; /* 数学記号らしく */
    font-size: 1rem;
    width: 36px;
    padding: 4px 0;
}

/* === 解説機能のスタイル === */

/* 薄く表示されるボタン（ゴーストボタン） */
.ghost-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9rem;
    padding: 8px 16px;
    transition: all 0.3s;
}

.ghost-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border-color: #fff;
    transform: scale(1.02);
}

/* 解説リストのコンテナ */
.explanation-container {
    max-height: 400px;
    overflow-y: auto;
    text-align: left;
}

/* 解説カード（知恵袋の回答っぽいデザイン） */
.explanation-card {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    border-left: 4px solid #aaa; /* デフォルトの線 */
}

/* ベストアンサー（いいね一番多いやつ） */
.explanation-card.best-answer {
    border-left: 4px solid #f39c12; /* 金色 */
    background: rgba(243, 156, 18, 0.15);
}

.best-badge {
    color: #f39c12;
    font-weight: bold;
    font-size: 0.8rem;
    margin-bottom: 5px;
    display: block;
}

.exp-header {
    font-size: 0.8rem;
    color: #ccc;
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.exp-body {
    font-size: 1rem;
    white-space: pre-wrap; /* 改行を反映 */
    line-height: 1.5;
}

/* いいねボタンエリア */
.vote-area {
    margin-top: 8px;
    text-align: right;
}

.vote-btn {
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    font-size: 0.9rem;
}

.vote-btn:hover {
    color: #ff6b6b;
}
/* 隠すときは「存在自体」を消す設定にします */
.hidden {
    display: none !important;
}

/* 念のため、画面が表示されたときはブロック要素にする設定 */
.screen.active {
    display: block;
}

/* === イラスト表示エリア（ゲーム画面の上に重ねる） === */
.illustration-box {
    position: absolute;
    inset: 0;
    pointer-events: none;  /* クリックを邪魔しないように */
    z-index: 10;
}

.illustration-item {
    position: absolute;
    width: 250px;     /* 画像の基本サイズ */
    height: 250px;
    display: flex;
    justify-content: center;
    align-items: flex-end; /* 画像を底辺に合わせる */
}

/* 表示位置バリエーション（上書き） */
.illustration-item.pos-right-bottom {
    right: 50px;
    bottom: 50px;
    left: auto;
    top: auto;
}
.illustration-item.pos-right-middle {
    right: 50px;
    top: 50%;
    bottom: auto;
    left: auto;
    transform: translateY(-50%);
}
.illustration-item.pos-left-bottom {
    left: 50px;
    bottom: 50px;
    right: auto;
    top: auto;
}
.illustration-item.pos-left-middle {
    left: 50px;
    top: 50%;
    bottom: auto;
    right: auto;
    transform: translateY(-50%);
}
.illustration-item.pos-bottom-center {
    left: 50%;
    bottom: 80px;
    right: auto;
    top: auto;
    transform: translateX(-50%);
}

.illustration-item img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    filter: drop-shadow(2px 2px 0px rgba(255,255,255,0.5)); /* 白いフチ取り風 */
}

/* === アニメーションの定義 === */

/* 1. ぷるぷる震える（爆弾や怒り） */
@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}
.anim-shake img {
    animation: shake 0.5s infinite;
}

/* 2. 左からスライドイン（登場） */
@keyframes slideIn {
    0% { transform: translateX(200px); opacity: 0; }
    100% { transform: translateX(0); opacity: 1; }
}
.anim-slide img {
    animation: slideIn 1s ease-out forwards;
}

/* 3. ずっと回ってる（混乱・タイヤ） */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
.anim-spin img {
    animation: spin 3s linear infinite;
}

/* 4. ぴょんぴょん跳ねる（楽しい・ボール） */
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}
.anim-bounce img {
    animation: bounce 1s infinite;
}

/* スマホ対応：画面が狭いときは画像を小さくして位置調整 */
@media (max-width: 600px) {
    .illustration-item {
        width: 120px;
        height: 120px;
        opacity: 0.7; /* 文字が見えるように少し薄く */
    }
}