/* ===== 棋譜暗記改 スタイル ===== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
    margin: 0; padding: 0;
    font-family: 'Hiragino Kaku Gothic ProN','Yu Gothic',sans-serif;
    background: linear-gradient(135deg,#1f2933,#3b4252);
    color: #f0f4f8;
    overflow: hidden;
    height: 100%;
    /* ダブルタップ拡大防止 */
    touch-action: manipulation;
}
.hidden { display: none !important; }

/* ---- ボタン ---- */
.btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    padding: 7px 12px;
    font-size: 0.82rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
    min-height: 34px;
    touch-action: manipulation;
}
.btn:hover, .btn:active { background: rgba(255,255,255,0.22); }
.btn.primary { background: linear-gradient(135deg,#d97706,#b45309); border-color:#92400e; }
.btn.primary:hover { background: linear-gradient(135deg,#f59e0b,#d97706); }
.btn.danger { background: #b91c1c; border-color:#991b1b; }
.btn.danger:hover { background: #dc2626; }
.btn:disabled { opacity:0.4; cursor:not-allowed; }
.btn-sm { padding:3px 8px; font-size:0.72rem; min-height:24px; }
.btn.active { background: #16a34a; border-color: #15803d; }

/* ---- レイアウト ---- */
.app { display:flex; flex-direction:column; height:100vh; }
.topbar { display:flex; align-items:center; gap:16px; padding:6px 14px; background:rgba(0,0,0,0.3); }
.topbar h1 { margin:0; font-size:1.05rem; font-weight:600; color:#fbbf24; }
.status { font-size:0.8rem; color:#cbd5e1; flex:1; }
.topbar-right { display:flex; align-items:center; gap:6px; margin-left:auto; }

.main { flex:1; display:flex; gap:10px; padding:8px; overflow:hidden; }
.left { display:flex; flex-direction:column; align-items:center; gap:4px; }
.right { flex:1; display:flex; flex-direction:column; gap:6px; min-width:260px; overflow:hidden; }

/* ---- 盤面 ---- */
.board-wrap { position:relative; }
.board {
    width: 450px; height:450px;
    display:grid;
    grid-template-columns: repeat(9, 50px);
    grid-template-rows: repeat(9, 50px);
    background: #d2a374;
    border:2px solid #5b3a1a;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.cell {
    position: relative;
    border: 1px solid rgba(80,40,10,0.5);
    display:flex; align-items:center; justify-content:center;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
}
.cell.selected { background: rgba(255,215,0,0.4); }
.cell.valid-move::after {
    content:''; position:absolute;
    width:14px; height:14px; border-radius:50%;
    background: rgba(34,197,94,0.6);
}
.cell.last-move { background: rgba(96,165,250,0.25); }
.piece {
    font-size: 26px; font-weight:700;
    color: #1a1a1a;
    background: #f5deb3;
    width:42px; height:42px;
    display:flex; align-items:center; justify-content:center;
    border-radius:3px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
    line-height: 1;
}
.piece.gote { transform: rotate(180deg); }
.piece.promoted { color: #b91c1c; }

/* ---- 正解マーク ---- */
.correct-mark {
    position: absolute;
    top: -8px; right: -36px;
    font-size: 32px;
    color: #16a34a;
    font-weight: bold;
    text-shadow: 0 1px 4px rgba(0,0,0,0.4);
    z-index: 10;
    animation: correctPop 0.4s ease-out;
    pointer-events: none;
}
@keyframes correctPop {
    0% { transform: scale(0.3); opacity:0; }
    50% { transform: scale(1.3); opacity:1; }
    100% { transform: scale(1); opacity:1; }
}

/* ---- 持ち駒 ---- */
.hand {
    width: 450px;
    min-height: 36px;
    display:flex; flex-wrap:wrap; gap:4px;
    padding: 4px 6px;
    background: rgba(0,0,0,0.25);
    border-radius:4px;
}
.hand-piece {
    position: relative;
    background: #f5deb3; color:#1a1a1a;
    width: 36px; height:36px;
    display:flex; align-items:center; justify-content:center;
    border-radius:3px;
    font-size: 22px; font-weight:700;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,0.4);
    touch-action: manipulation;
}
.hand-piece.gote { transform: rotate(180deg); }
.hand-piece .count {
    position:absolute; right:-2px; bottom:-2px;
    background:#dc2626; color:#fff;
    font-size:11px; padding:1px 4px;
    border-radius:8px; line-height:1;
    transform: rotate(0);
}
.hand-piece.gote .count { transform: rotate(180deg); }
.hand-piece.selected { box-shadow: 0 0 0 3px rgba(255,215,0,0.8); }

/* ---- 情報 / コントロール ---- */
.controls { display:flex; flex-wrap:wrap; gap:5px; }
.controls-nav { display:flex; flex-wrap:wrap; gap:5px; }
.info {
    background: rgba(0,0,0,0.25);
    padding:5px 10px;
    border-radius:4px;
    font-size:0.85rem;
    display:flex; align-items:center; gap:10px;
}
.mode-badge {
    background: #4f46e5; color:#fff;
    padding:2px 8px; border-radius:10px;
    font-size:0.72rem; font-weight:600;
}
.mode-badge.edit { background: #dc2626; }
.mode-badge.memorize { background: #d97706; }
#memorize-info { margin-top:2px; color:#fbbf24; font-weight:600; font-size:0.8rem; }

/* ---- 棋譜ツリー ---- */
.tree-panel {
    flex:1;
    background: rgba(0,0,0,0.3);
    border-radius: 6px;
    padding: 6px;
    display:flex; flex-direction:column; overflow:hidden;
    min-height: 120px;
}
.tree-panel h3 { margin:0 0 4px 0; font-size:0.8rem; color:#fbbf24; }
.tip { color:#94a3b8; font-weight:normal; font-size:0.65rem; }
.tree-list {
    flex:1;
    background: #f4f4f4;
    color: #222;
    border-radius:4px;
    overflow:auto;
    position:relative;
    cursor: grab;
}
.tree-graph .tree-col-header {
    position:absolute; top:4px; height:18px;
    text-align:center; font-size:0.68rem; color:#555;
    pointer-events:none; user-select:none;
}
.tree-graph .tree-lines {
    position:absolute; left:0; top:0; pointer-events:none;
}
.tree-line { stroke:#888; stroke-width:1.4; fill:none; }
.tree-graph .tree-node-box {
    position:absolute;
    box-sizing:border-box;
    border:1px solid #6b6b6b;
    border-radius:3px;
    text-align:center;
    line-height:24px;
    font-size:0.72rem;
    background:#fff; color:#111;
    cursor:pointer; user-select:none;
    overflow:visible; white-space:nowrap;
    padding:0 4px;
    z-index:1;
}
.tree-graph .tree-node-box.root { background:#d9e7f5; border-color:#6e8aaa; font-weight:bold; }
.tree-graph .tree-node-box.odd-move { background:#cfe2f7; border-color:#4f7ba8; }
.tree-graph .tree-node-box.even-move { background:#fde9b8; border-color:#b89244; color:#5a4720; }
.tree-graph .tree-node-box.current { border:2px solid #d9352b; line-height:22px; z-index:2; }

/* 分岐数バッジ（右上） */
.tree-badge-branch {
    position:absolute;
    top:-6px; right:-6px;
    background:#dc2626; color:#fff;
    font-size:9px; font-weight:bold;
    padding:1px 4px;
    border-radius:8px;
    line-height:1.2;
    z-index:3;
    pointer-events:none;
}
.tree-badge-branch.done { background:#16a34a; }
/* 最終手マーク（左上） */
.tree-badge-leaf {
    position:absolute;
    top:-6px; left:-6px;
    background:#facc15; color:#3b2c00;
    font-size:10px; font-weight:bold;
    width:14px; height:14px;
    border-radius:50%;
    display:flex; align-items:center; justify-content:center;
    z-index:3;
    pointer-events:none;
}

/* 暗記開始点マーク */
.tree-graph .tree-node-box.memo-start {
    box-shadow: 0 0 0 2px #fbbf24;
}

/* ---- 棋譜Box ---- */
.kif-box-panel {
    background: rgba(0,0,0,0.3);
    border-radius: 6px;
    padding: 6px;
    max-height: 140px;
    overflow: hidden;
    display: flex; flex-direction: column;
}
.kif-box-panel h3 {
    margin:0 0 4px 0; font-size:0.8rem; color:#fbbf24;
    display:flex; align-items:center; gap:8px;
}
.kif-box-list {
    flex:1; overflow-y:auto;
    display:flex; flex-direction:column; gap:2px;
}
.kif-box-item {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex; justify-content: space-between; align-items:center;
    transition: background 0.15s;
}
.kif-box-item:hover { background: rgba(255,255,255,0.18); }
.kif-box-item.active { background: rgba(251,191,36,0.2); border-color:#fbbf24; }
.kif-box-item .kif-box-delete {
    background: none; border:none; color:#ef4444; cursor:pointer;
    font-size:0.8rem; padding:2px 4px;
}

/* ---- ダイアログ ---- */
.dialog {
    position:fixed; inset:0;
    background: rgba(0,0,0,0.6);
    display:flex; align-items:center; justify-content:center;
    z-index:100;
}
.dialog-content {
    background:#1f2933; padding:20px;
    border-radius:8px; min-width:240px;
    text-align:center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.dialog-buttons { display:flex; gap:10px; justify-content:center; margin-top:14px; }
.paste-dialog-content { min-width:320px; }
.paste-dialog-content textarea {
    width:100%; resize:vertical;
    background:#111; color:#f0f4f8;
    border:1px solid rgba(255,255,255,0.2);
    border-radius:4px; padding:8px;
    font-size:0.8rem; font-family:monospace;
    margin-top:8px;
}

/* ---- プランバッジ ---- */
.plan-badge {
    font-size:0.68rem; font-weight:600;
    padding:2px 8px; border-radius:10px;
    white-space:nowrap;
}
.plan-badge.free { background:#374151; color:#9ca3af; }
.plan-badge.premium { background:linear-gradient(135deg,#d97706,#b45309); color:#fff; }

/* ---- 認証ダイアログ ---- */
.auth-dialog-content { min-width:280px; }
.auth-dialog-content h3 { margin:0 0 12px 0; color:#fbbf24; }
.auth-dialog-content input {
    display:block; width:100%; margin-bottom:8px;
    padding:8px; border-radius:4px;
    border:1px solid rgba(255,255,255,0.2);
    background:#111; color:#f0f4f8; font-size:0.85rem;
}
.auth-error { color:#ef4444; font-size:0.75rem; min-height:18px; }
.auth-toggle-wrap { margin-top:10px; }
.auth-toggle { color:#60a5fa; cursor:pointer; font-size:0.78rem; }
.auth-toggle:hover { text-decoration:underline; }

/* ---- ×オーバーレイ ---- */
.cross-overlay {
    position:fixed; inset:0;
    display:flex; align-items:center; justify-content:center;
    font-size: 240px; color:#dc2626; font-weight:bold;
    pointer-events:none;
    text-shadow: 0 4px 16px rgba(0,0,0,0.6);
    z-index:200;
    animation: crossPop 0.5s ease-out;
}
@keyframes crossPop {
    0% { transform: scale(0.3); opacity:0; }
    30% { transform: scale(1.2); opacity:1; }
    100% { transform: scale(1); opacity:1; }
}

.memorize-group {
    display: flex;
    gap: 5px;
    flex: 1 1 100%;
}
.memorize-group .btn { flex: 1 1 0; }

/* ---- タブレット対応 ---- */
@media (max-width: 900px) {
    html, body { overflow:auto; }
    .app { height:auto; min-height:100vh; }
    .main { flex-direction:column; padding: 6px; gap: 6px; overflow:visible; }
    .left { width: 100%; align-items:center; }
    .right { width: 100%; min-width: 0; }
    .board {
        width: 360px; height:360px;
        grid-template-columns: repeat(9, 40px);
        grid-template-rows: repeat(9, 40px);
    }
    .hand { width: 360px; }
    .piece { width:34px; height:34px; font-size:22px; }
    .hand-piece { width:30px; height:30px; font-size:18px; }
    .topbar { flex-wrap:wrap; gap:6px; }
    .topbar h1 { font-size:0.9rem; }
    .status { display:none; }
    .topbar-right { margin-left:auto; gap:4px; }
    .tree-panel { min-height:150px; max-height:200px; }
}

/* ---- スマホ対応 ---- */
@media (max-width: 480px) {
    .topbar { padding:4px 8px; gap:4px; }
    .topbar h1 { font-size:0.82rem; }
    .topbar-right { width:auto; }
    .plan-badge { font-size:0.6rem; padding:1px 6px; }
    #subscribe-btn { font-size:0.65rem; padding:2px 6px; }
    #account-btn { font-size:0.65rem; padding:2px 6px; }
    .board {
        --cell: min(calc((100vw - 16px) / 9), 40px);
        width: calc(var(--cell) * 9); height: calc(var(--cell) * 9);
        grid-template-columns: repeat(9, var(--cell));
        grid-template-rows: repeat(9, var(--cell));
    }
    .hand { width: calc(min(calc((100vw - 16px) / 9), 40px) * 9); }
    .piece { width:calc(var(--cell, 35px) - 5px); height:calc(var(--cell, 35px) - 5px); font-size:18px; }
    .hand-piece { width:28px; height:28px; font-size:16px; }
    .controls { gap:3px; }
    .controls .btn { padding:4px 7px; font-size:0.7rem; min-height:28px; }
    .controls-nav .btn { padding:4px 7px; font-size:0.7rem; min-height:28px; }
    .info { padding:3px 6px; font-size:0.75rem; gap:6px; }
    .tree-panel { min-height:120px; max-height:180px; }
    .kif-box-panel { max-height:100px; }
    .dialog-content { min-width:auto; width:90vw; max-width:320px; }
    .paste-dialog-content { min-width:auto; }
    .auth-dialog-content { min-width:auto; }
}
