/* ===== お絵描き自由帳 v3 ===== */

.da-wrap {
    box-sizing: border-box;
    font-family: 'M PLUS Rounded 1c', 'BIZ UDGothic', sans-serif;
    font-size: 13px;
    user-select: none;
    margin: 0 !important;
    padding: 0 !important;
}
.da-wrap * { box-sizing: border-box; }
.da-hidden { display: none !important; }

/* ===== キャンバスサイズ選択 POPUP ===== */
.da-size-popup {
    position: fixed;
    inset: 0;
    background: rgba(20, 40, 70, 0.92);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.da-size-popup-inner {
    background: #fff;
    border-radius: 16px;
    padding: 36px 40px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.4);
    text-align: center;
    max-width: 520px;
    width: 90%;
}
.da-size-title {
    font-size: 18px;
    font-weight: 700;
    color: #1e3a5f;
    margin: 0 0 24px;
}
.da-size-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.da-size-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px 16px;
    border: 2px solid #d1dbe8;
    border-radius: 12px;
    background: #f8fafc;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.da-size-btn:hover {
    border-color: #1e3a5f;
    background: #eaf0f8;
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(30,58,95,0.15);
}
.da-size-icon { color: #1e3a5f; line-height: 1; }
.da-size-name {
    font-size: 15px;
    font-weight: 700;
    color: #1e3a5f;
}
.da-size-px {
    font-size: 11px;
    color: #888;
}

/* ===== アプリ外枠 ===== */
.da-app {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
    background: #1e3a5f;
    overflow: hidden;
}

/* ===== 上部タブバー ===== */
.da-tabbar {
    height: 42px;
    flex-shrink: 0;
    background: #162d4a;
    display: flex;
    align-items: flex-end;
    padding: 0 8px 0 58px; /* 左サイドバー幅(58px)分だけ内側からスタート */
    gap: 3px;
    overflow-x: auto;
    overflow-y: hidden;
}
.da-tabbar::-webkit-scrollbar { height: 0; }

.da-tab {
    height: 34px;
    min-width: 80px;
    max-width: 130px;
    padding: 0 10px;
    border: none;
    border-radius: 7px 7px 0 0;
    background: rgba(255,255,255,0.12);
    color: rgba(255,255,255,0.65);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 5px;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
    white-space: nowrap;
}
.da-tab:hover { background: rgba(255,255,255,0.2); color: #fff; }
.da-tab.active { background: #fff; color: #1e3a5f; }

.da-tab-name { flex: 1; text-align: center; }

.da-tab-del {
    width: 16px; height: 16px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: inherit;
    font-size: 12px;
    cursor: pointer;
    padding: 0;
    display: flex; align-items: center; justify-content: center;
    opacity: 0.6;
    font-family: inherit;
    flex-shrink: 0;
    line-height: 1;
}
.da-tab-del:hover { background: #e24b4a; color: #fff; opacity: 1; }

.da-tab-add {
    height: 28px; width: 28px;
    border-radius: 6px;
    border: 2px dashed rgba(255,255,255,0.3);
    background: transparent;
    color: rgba(255,255,255,0.6);
    font-size: 18px; font-weight: 700;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    align-self: center;
    padding: 0;
    font-family: inherit;
    transition: all 0.15s;
}
.da-tab-add:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
    border-color: rgba(255,255,255,0.6);
}

/* ===== キャンバス行 ===== */
.da-canvas-row {
    flex: 1;
    display: flex;
    flex-direction: row;
    min-height: 0;
    align-items: stretch;
    position: relative;
}

/* ===== 左右ツール列 共通 ===== */
.da-side {
    width: 58px;
    flex-shrink: 0;
    background: #1e3a5f;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0;
    gap: 4px;
    overflow-y: auto;
    overflow-x: hidden;
}
.da-side::-webkit-scrollbar { width: 0; }

/* ツールボタン共通 */
.da-btn {
    width: 46px; height: 46px;
    border-radius: 10px;
    border: 2px solid transparent;
    background: rgba(255,255,255,0.10);
    color: #fff;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    flex-shrink: 0;
    font-family: inherit;
}
.da-btn:hover { background: rgba(255,255,255,0.22); transform: scale(1.05); }
.da-btn.active { background: #d4af37; border-color: #f0cc55; color: #1e3a5f; }
.da-btn.da-danger { border-color: #e24b4a; color: #ff8080; }
.da-btn.da-danger:hover { background: #e24b4a; color: #fff; }
.da-btn.da-save  { border-color: #3dbf7b; color: #7fefb8; }
.da-btn.da-save:hover  { background: #3dbf7b; color: #fff; }
.da-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

.da-btn svg {
    width: 22px; height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}
.da-btn.active svg { stroke: #1e3a5f; }
.da-btn-label { font-size: 9px; font-weight: 700; line-height: 1; color: inherit; }

.da-divider {
    width: 32px; height: 1px;
    background: rgba(255,255,255,0.18);
    margin: 3px 0;
    flex-shrink: 0;
}

/* クイックカラー */
.da-qdot {
    width: 30px; height: 30px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.3);
    flex-shrink: 0;
    transition: transform 0.12s;
}
.da-qdot:hover { transform: scale(1.15); }
.da-qdot.active { outline: 2.5px solid #d4af37; outline-offset: 2px; }

/* 現在色ボタン */
.da-cur-color {
    width: 46px; height: 46px;
    border-radius: 10px;
    border: 2px solid rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.08);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    transition: border-color 0.15s;
    flex-shrink: 0;
}
.da-cur-color:hover { border-color: #d4af37; }
.da-cur-dot { width: 28px; height: 28px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.4); }
.da-cur-label { font-size: 9px; color: rgba(255,255,255,0.8); font-weight: 700; }

/* 縦スライダー */
.da-vslider-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
}
.da-vslider-val { font-size: 9px; color: rgba(255,255,255,0.85); font-weight: 700; line-height: 1; }
.da-vslider {
    writing-mode: vertical-lr;
    direction: rtl;
    width: 24px; height: 80px;
    cursor: pointer;
    accent-color: #d4af37;
    background: transparent;
}

/* ===== キャンバスエリア ===== */
.da-canvas-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e8edf3;
    position: relative;
    min-width: 0;
    overflow: hidden;
    padding: 16px;
}
.da-canvas-area canvas {
    display: block;
    background: #fff;
    cursor: crosshair;
    box-shadow: 0 4px 24px rgba(0,0,0,0.18);
    /* アスペクト比を保ちエリアに収める */
    max-width: 100%;
    max-height: 100%;
    width: auto !important;
    height: auto !important;
    object-fit: contain;
}

/* ===== カラーPOPUP ===== */
.da-color-popup {
    position: absolute;
    right: 62px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 200;
    background: #fff;
    border: 2px solid #1e3a5f;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.22);
    display: none;
}
.da-color-popup.open { display: block; }

.da-popup-grid {
    display: grid;
    grid-template-columns: repeat(5, 28px);
    gap: 6px;
    margin-bottom: 10px;
}
.da-popup-dot {
    width: 28px; height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s;
}
.da-popup-dot:hover { transform: scale(1.15); }
.da-popup-dot.active { outline: 2px solid #1e3a5f; outline-offset: 2px; }

.da-popup-custom {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}
.da-popup-custom input[type=color] {
    width: 42px; height: 42px;
    border: none; border-radius: 50%;
    cursor: pointer; padding: 0; background: none;
}
.da-popup-custom span { font-size: 10px; color: #555; font-weight: 700; }

/* ===== レスポンシブ ===== */
@media (max-width: 600px) {
    .da-app { height: 100svh; }
    .da-side { width: 46px; }
    .da-btn { width: 38px; height: 38px; }
    .da-qdot { width: 24px; height: 24px; }
    .da-cur-color { width: 38px; height: 38px; }
    .da-cur-dot { width: 22px; height: 22px; }
    .da-vslider { height: 60px; }
    .da-tabbar { padding-left: 46px; }
    .da-size-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .da-size-popup-inner { padding: 24px 20px; }
}
