/* --- ベース設定 --- */
:root {
    --brand-color: #4A90E2;
    --bg-canvas: #ffffff;
    --btn-color: #f39c12;
    --btn-active: #e67e22;
    --danger: #e74c3c;
    --delete: #c0392b;
    --success: #2ecc71;
    --play: #9b59b6;
    --save: #3498db;
    --eraser: #95a5a6;
}

* { box-sizing: border-box; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

body { margin: 0; padding: 0; width: 100vw; height: 100dvh; display: flex; font-family: 'M PLUS Rounded 1c', sans-serif; overflow: hidden; background-color: #000; }

.hidden { opacity: 0; pointer-events: none; visibility: hidden; z-index: -1 !important; position: absolute; }

/* --- ホームボタン --- */
.home-btn {
    position: absolute; top: 15px; left: 15px; z-index: 9998;
    width: clamp(40px, 6vw, 60px); height: clamp(40px, 6vw, 60px); border-radius: 50%;
    background: rgba(255, 255, 255, 0.9); border: 4px solid var(--brand-color);
    font-size: clamp(1.2rem, 2.5vw, 1.8rem); cursor: pointer; display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2); transition: transform 0.1s;
}
.home-btn:active { transform: scale(0.9); }

#app-container { position: relative; width: 100vw; height: 100dvh; background-color: #2c3e50; display: flex; overflow: hidden; }

/* --- 左側（70%）：キャンバス --- */
#game-area { width: 70%; height: 100%; display: flex; flex-direction: column; padding: 2vh; padding-top: 80px; gap: 2vh; }
#canvas-container { flex-grow: 1; background-color: var(--bg-canvas); border-radius: 15px; box-shadow: inset 0 0 20px rgba(0,0,0,0.1); position: relative; overflow: hidden; }
canvas { width: 100%; height: 100%; display: block; touch-action: none; }

#play-indicator { position: absolute; bottom: 2vh; right: 2vh; font-size: clamp(1.2rem, 2vw, 1.8rem); background: rgba(255, 255, 255, 0.8); padding: 5px 15px; border-radius: 20px; color: var(--play); font-weight: bold; pointer-events: none; border: 2px solid var(--play); }
.klee-text { font-family: 'Klee One', cursive; }

/* タイムライン */
#timeline-container { height: 12vh; background: rgba(255, 255, 255, 0.1); border-radius: 15px; display: flex; align-items: center; padding: 1vh; gap: 1vh; overflow-x: auto; }
#frames-list { display: flex; gap: 1vh; height: 100%; align-items: center; }
.frame-thumb { height: 90%; aspect-ratio: 4/3; background: #fff; border-radius: 8px; border: 3px solid transparent; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 2px; cursor: pointer; transition: border-color 0.2s; }
.frame-thumb.active { border-color: var(--success); }
.frame-num { font-size: 1rem; font-weight: bold; color: #333; pointer-events: none; }
.frame-controls { display: flex; width: 100%; justify-content: space-between; }
.swap-btn { background: #bdc3c7; border: none; border-radius: 3px; color: #fff; padding: 2px 6px; font-weight: bold; cursor: pointer; font-size: 0.8rem; }
.circle-btn { height: 6vh; width: 6vh; border-radius: 50%; border: none; background: var(--success); color: #fff; font-size: 2rem; font-weight: bold; cursor: pointer; box-shadow: 0 4px 0 #27ae60; flex-shrink: 0; margin-left: 1vh; display: flex; align-items: center; justify-content: center; }
.circle-btn:active { transform: translateY(4px); box-shadow: none; }

/* --- 右側（30%）：UIエリア --- */
#ui-area { width: 30%; height: 100%; background-color: #e6dcc3; background-image: url('https://deji-lab.com/wp-content/uploads/2026/05/wood-bg.jpg'); border-left: 6px solid #8e6c4a; display: flex; flex-direction: column; padding: 2vh; gap: 1.5vh; box-shadow: -5px 0 15px rgba(0,0,0,0.5); z-index: 30; overflow-y: auto; }
.panel-title { font-size: clamp(1.2rem, 2vw, 1.8rem); text-align: center; color: #5c4033; font-weight: bold; background: rgba(255, 255, 255, 0.7); padding: 5px; border-radius: 10px; margin: 0; flex-shrink: 0; }

.settings-box { background: rgba(255, 255, 255, 0.6); padding: 10px; border-radius: 10px; flex-shrink: 0; }
.color-palette { display: flex; justify-content: space-between; margin-bottom: 10px; }
.color-btn { width: clamp(25px, 3vw, 40px); height: clamp(25px, 3vw, 40px); border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.2); cursor: pointer; transition: transform 0.1s; }
.color-btn.active { transform: scale(1.2); border-color: var(--brand-color); }
.width-slider { display: flex; align-items: center; gap: 10px; font-weight: bold; color: #5c4033; font-size: 0.9rem;}
.width-slider input { flex-grow: 1; }

.mode-group, .play-group, .delete-group { display: flex; flex-direction: column; gap: 1vh; flex-shrink: 0; }

/* 消しゴムとUndo/Redoの分割レイアウト */
.mode-row-split { display: flex; gap: 1vh; width: 100%; }
.eraser-btn { flex: 1.5; }
.undo-redo-group { display: flex; gap: 1vh; flex: 1; }
.action-btn { flex: 1; font-size: 1.5rem; background-color: #7f8c8d; padding: 0; display: flex; align-items: center; justify-content: center; }
.action-btn.disabled { opacity: 0.5; pointer-events: none; box-shadow: 0 0px 0 #7f8c8d; transform: translateY(4px); }

.ui-btn { background-color: var(--btn-color); color: #fff; border: none; border-radius: 10px; font-size: clamp(1rem, 1.5vw, 1.3rem); font-family: 'M PLUS Rounded 1c', sans-serif; font-weight: bold; padding: 1.5vh 1vh; box-shadow: 0 4px 0 #d35400, 0 4px 4px rgba(0,0,0,0.2); cursor: pointer; transition: transform 0.05s, box-shadow 0.05s; }
.ui-btn:active { transform: translateY(4px); box-shadow: 0 0px 0 #d35400; }
.mode-btn.active-mode { background-color: var(--success); box-shadow: 0 4px 0 #27ae60; }
.mode-btn.active-mode:active { box-shadow: 0 0px 0 #27ae60; }
.eraser-btn { background-color: var(--eraser); box-shadow: 0 4px 0 #7f8c8d; }
.eraser-btn:active { box-shadow: 0 0px 0 #7f8c8d; }
.play-btn { background-color: var(--play); box-shadow: 0 4px 0 #8e44ad; font-size: clamp(1.2rem, 1.8vw, 1.6rem); }
.play-btn:active { box-shadow: 0 0px 0 #8e44ad; }
.save-btn { background-color: var(--save); box-shadow: 0 4px 0 #2980b9; }
.save-btn:active { box-shadow: 0 0px 0 #2980b9; }
.danger-btn { background-color: var(--danger); box-shadow: 0 4px 0 #c0392b; }
.danger-btn:active { box-shadow: 0 0px 0 #c0392b; }
.delete-btn { background-color: #34495e; box-shadow: 0 4px 0 #2c3e50; }
.delete-btn:active { box-shadow: 0 0px 0 #2c3e50; }

.nav-cushion { height: 100px; width: 100%; flex-shrink: 0; margin-top: auto; }

/* === ジェムナビボタン === */
.gem-navi-wrapper { position: fixed; bottom: 20px; right: 20px; z-index: 9999; display: flex; align-items: stretch; background: #fff; border-radius: 30px; box-shadow: 0 4px 6px rgba(0,0,0,0.2); border: 3px solid #78C2C4; overflow: hidden; transition: box-shadow 0.2s; }
.gem-navi-handle { padding: 0 15px; background: #E6E9ED; color: #AAB2BD; cursor: grab; font-size: 1.2rem; user-select: none; touch-action: none; display: flex; align-items: center; justify-content: center; }
.gem-navi-handle:active { cursor: grabbing; background: #CCD1D9; }
.gem-navi-btn { background: linear-gradient(135deg, #A0CECB, #78C2C4); color: #fff !important; text-decoration: none; padding: 10px 20px; font-weight: bold; font-family: "M PLUS Rounded 1c", sans-serif; display: flex; align-items: center; gap: 5px; font-size: 1rem; white-space: nowrap; }
.gem-navi-btn:hover { opacity: 0.9; }
.gem-navi-icon { width: 24px !important; height: 24px !important; object-fit: cover !important; border-radius: 50% !important; flex-shrink: 0 !important; margin-right: 4px !important; display: inline-block !important; }