/* style.css */
/* 席替え乱数メーカー 共通デザインシステム */

/* Google Fontsの読み込み (手書き風・モダン丸ゴシック) */
@import url('https://fonts.googleapis.com/css2?family=M+PLUS+Rounded+1c:wght@400;700&family=Outfit:wght@300;400;600&display=swap');

:root {
    --bg-color: #12141c;
    --board-bg: #1c352d; /* 黒板の深い深緑 */
    --board-border: #523118; /* 黒板の木枠 */
    --board-shadow: rgba(0, 0, 0, 0.4);
    --text-chalk: #f8f9fa; /* チョークの白 */
    --text-chalk-muted: #bdc3c7;
    --chalk-yellow: #fcd34d;
    --chalk-pink: #f472b6;
    --chalk-blue: #60a5fa;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --accent-color: #3b82f6;
    --font-family: 'M PLUS Rounded 1c', 'Outfit', sans-serif;
}

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

body {
    background-color: var(--bg-color);
    color: #e2e8f0;
    font-family: var(--font-family);
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 12px;
    overflow: hidden;
    box-sizing: border-box;
}

/* 上部：黒板コンテナ */
.blackboard-container {
    background: var(--board-border);
    padding: 10px;
    border-radius: 12px;
    box-shadow: 0 8px 20px var(--board-shadow), inset 0 2px 4px rgba(255, 255, 255, 0.2);
    width: 100%;
    flex-shrink: 0;
}

.blackboard {
    background-color: var(--board-bg);
    background-image: 
        radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.03) 0%, transparent 80%),
        repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.005) 0px, rgba(255, 255, 255, 0.005) 1px, transparent 1px, transparent 10px);
    border: 2px solid rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 10px 20px;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.6);
    color: var(--text-chalk);
}

/* 黒板のタイトル表示 */
.blackboard-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-chalk);
    text-shadow: 
        0 0 2px rgba(255, 255, 255, 0.4),
        0 0 8px rgba(255, 255, 255, 0.2);
    letter-spacing: 0.15em;
    margin: auto;
}

/* バージョン表記 */
.blackboard-version {
    position: absolute;
    bottom: 8px;
    right: 16px;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.2);
    font-family: 'Outfit', monospace;
    letter-spacing: 0.05em;
}

/* 右上の数値デコレーションボックス */
.digit-boxes-container {
    display: flex;
    gap: 6px;
    position: absolute;
    top: 14px;
    right: 16px;
}

.digit-box {
    width: 28px;
    height: 38px;
    border: 1.5px solid var(--box-color, #fff);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    background: rgba(255, 255, 255, 0.02);
    box-shadow: inset 0 0 4px rgba(255, 255, 255, 0.05);
}

.digit-box .digit-text {
    font-size: 0.95rem;
    font-weight: bold;
    color: var(--text-chalk);
    font-family: 'Outfit', monospace;
    line-height: 1;
    margin-top: -6px;
}

/* ボックスごとの異なる枠線カラー */
.digit-box[data-digit="0"] { --box-color: #ff79c6; }
.digit-box[data-digit="1"] { --box-color: #ffb86c; }
.digit-box[data-digit="2"] { --box-color: #8be9fd; }
.digit-box[data-digit="3"] { --box-color: #50fa7b; }
.digit-box[data-digit="4"] { --box-color: #ff5555; }
.digit-box[data-digit="5"] { --box-color: #bd93f9; }
.digit-box[data-digit="6"] { --box-color: #f1fa8c; }
.digit-box[data-digit="7"] { --box-color: #06b6d4; }
.digit-box[data-digit="8"] { --box-color: #f43f5e; }
.digit-box[data-digit="9"] { --box-color: #a855f7; }

/* インジケータドットの配置 */
.indicator-dots {
    display: flex;
    justify-content: center;
    gap: 2px;
    position: absolute;
    bottom: 3px;
    width: 100%;
}

.indicator-dots .dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: transparent;
    transition: all 0.2s;
}

/* ドットの光り方 */
.indicator-dots .dot.d-blue.active {
    background-color: #60a5fa;
    box-shadow: 0 0 4px #60a5fa;
}

.indicator-dots .dot.d-yellow.active {
    background-color: #fcd34d;
    box-shadow: 0 0 4px #fcd34d;
}

.indicator-dots .dot.d-red.active {
    background-color: #ef4444;
    box-shadow: 0 0 4px #ef4444;
}

/* 下部メインレイアウト */
.main-content-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    gap: 12px;
    width: 100%;
}

.left-panel {
    flex: 3;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.right-panel {
    flex: 1;
    min-width: 260px;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 100%;
}

/* コントロールパネル */
.control-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
    justify-content: space-between;
    height: 100%;
}

.panel-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-chalk-muted);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 6px;
    text-align: center;
    letter-spacing: 0.1em;
}

.credit {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.18);
    text-align: right;
    margin-top: 4px;
    font-family: var(--font-family);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.input-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

label {
    font-size: 0.85rem;
    color: var(--text-chalk-muted);
}

input[type="number"], input[type="text"] {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: #fff;
    padding: 6px 10px;
    font-family: var(--font-family);
    font-size: 0.9rem;
    width: 75px;
    outline: none;
    transition: all 0.3s;
}

input[type="number"]:focus, input[type="text"]:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
    background: rgba(255, 255, 255, 0.1);
}

/* ボタンのスタイリング */
.btn {
    font-family: var(--font-family);
    font-size: 0.95rem;
    font-weight: 700;
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.btn-primary {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: #fff;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.4);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.6);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* 座席レイアウトコンテナ */
.seating-chart-container {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 12px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    gap: 8px;
}

/* 教卓インジケータ */
.teacher-desk {
    background: linear-gradient(135deg, #8c5630 0%, #5c3a21 100%);
    color: #fff;
    text-align: center;
    font-weight: 700;
    padding: 6px;
    border-radius: 6px;
    width: 140px;
    margin: 0 auto;
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

/* 座席グリッド */
.seats-grid {
    display: grid;
    grid-template-columns: repeat(var(--cols, 6), 1fr);
    grid-template-rows: repeat(var(--rows, 5), 1fr);
    gap: 6px;
    flex: 1;
    min-height: 0;
    width: 100%;
}

/* 個々の座席 (1画面に収まるように伸縮自在) */
.seat-card {
    width: 100%;
    height: 100%;
    min-height: 0;
    background: rgba(255, 255, 255, 0.02);
    border: 2px dashed rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    padding: 2px;
}

.seat-card.active {
    background: rgba(255, 255, 255, 0.04);
    border-style: solid;
    border-color: rgba(255, 255, 255, 0.18);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
}

.seat-label {
    position: absolute;
    top: 3px;
    left: 5px;
    font-size: 0.6rem;
    color: var(--text-chalk-muted);
}

/* 座席番号 (行数に応じて自動調整) */
.seat-number {
    font-size: clamp(0.85rem, calc(min(6vh, 4.8vw) * (5 / var(--rows, 5))), 2.2rem);
    font-weight: 700;
    color: var(--text-chalk);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
    line-height: 1;
}

/* 不正設定されている座席のスタイル（生徒画面用または検証用） */
.seat-card.cheated {
    border-color: var(--chalk-pink);
    background: rgba(244, 114, 182, 0.04);
}
.seat-card.cheated .seat-number {
    color: var(--chalk-pink);
    text-shadow: 0 0 8px rgba(244, 114, 182, 0.4);
}

/* 固定席のスタイル（先生画面および生徒画面用） */
.seat-card.fixed {
    border-color: var(--chalk-yellow) !important;
    background: rgba(252, 211, 77, 0.06) !important;
    border-style: solid !important;
}
.seat-card.fixed .seat-number {
    color: var(--chalk-yellow) !important;
    text-shadow: none !important;
}

/* シャッフル時の回転アニメーション */
@keyframes spin3D {
    0% { transform: rotateX(0deg); filter: blur(0px); }
    50% { transform: rotateX(180deg); filter: blur(1px); }
    100% { transform: rotateX(360deg); filter: blur(0px); }
}

.shuffling .seat-number {
    animation: spin3D 0.15s infinite linear;
}

.seat-card.pop-effect {
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0.5; }
    70% { transform: scale(1.06); }
    100% { transform: scale(1); opacity: 1; }
}

/* レスポンシブ調整 */
@media (max-width: 768px) {
    body {
        height: auto;
        overflow-y: auto;
    }
    .blackboard {
        height: auto;
        min-height: 110px;
        flex-direction: column;
        padding: 15px 20px 25px 20px;
        gap: 10px;
    }
    .blackboard-title {
        font-size: 1.4rem;
        margin: 0;
        text-align: center;
    }
    .digit-boxes-container {
        position: static;
        margin-top: 5px;
        justify-content: center;
    }
    .blackboard-version {
        bottom: 4px;
        right: 12px;
    }
    .main-content-layout {
        flex-direction: column;
        height: auto;
    }
    .left-panel {
        height: 60vh;
    }
    .right-panel {
        max-width: none;
        height: auto;
    }
}

/* 生徒用コンテナ */
.container {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 12px;
}

/* 不正設定画面 (cheat.php) 固有のスタイル */
.cheat-setup {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 20px;
    width: 100%;
}

.cheat-instructions {
    margin-bottom: 20px;
    font-size: 0.85rem;
    color: var(--text-chalk-muted);
    line-height: 1.6;
}

#cheatSeatsGrid {
    display: grid;
    grid-template-columns: repeat(var(--cols, 6), 1fr);
    gap: 8px;
    width: 100%;
}

#cheatSeatsGrid .seat-card {
    aspect-ratio: 1.2 / 1;
    cursor: pointer;
}

#cheatSeatsGrid .seat-card:hover {
    transform: scale(1.05);
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.4);
}

.bottom-actions {
    margin-top: 20px;
    display: flex;
    gap: 12px;
}

/* 席をクリックして選択したときのハイライト */
.seat-card.selected {
    border-color: var(--chalk-pink);
    background: rgba(244, 114, 182, 0.1);
    box-shadow: 0 0 15px rgba(244, 114, 182, 0.2);
}
.seat-card.selected .seat-number {
    color: var(--chalk-pink);
}

/* モーダル / ダイアログ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
    transform: translateY(20px);
    transition: transform 0.3s;
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: #f8fafc;
}

.modal-body {
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* 出席番号選択用グリッド */
.number-selector-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
    padding: 4px;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.05);
}

.number-btn {
    aspect-ratio: 1;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.03);
    color: #fff;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.number-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.number-btn.used {
    opacity: 0.3;
    cursor: not-allowed;
    background: rgba(0,0,0,0.4);
}

.number-btn.selected {
    background: var(--accent-color);
    border-color: var(--accent-color);
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.5);
}

/* 通知メッセージ */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: #10b981;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 700;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 2000;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.error {
    background: #ef4444;
}
