/* ========================================
   基本設定
======================================== */

body {
    margin: 0;
    overflow: hidden;
    background-color: #202020;
    font-family: sans-serif;
}

canvas {
    display: block;
    touch-action: none;
}


/* ========================================
   ツールバー
======================================== */

#toolbar {
    position: fixed;

    top: 10px;
    left: 50%;

    transform: translateX(-50%);

    display: flex;
    gap: 6px;

    padding: 8px;

    background-color: #303030;

    border: 1px solid #555;
    border-radius: 8px;

    z-index: 10;
}

#toolbar button {
    padding: 8px 14px;

    background-color: #484848;
    color: white;

    border: 1px solid #666;
    border-radius: 4px;

    cursor: pointer;
}

#toolbar button:hover {
    background-color: #606060;
}

#toolbar button.active {
    background-color: #527fa8;
    border-color: #91c4ff;
}


/* ========================================
   ノード文字編集欄
======================================== */

.node-editor {
    position: fixed;
    box-sizing: border-box;

    background-color: #252525;
    color: #ffffff;

    border: 2px solid #91c4ff;
    border-radius: 2px;

    padding: 8px;

    font-family: sans-serif;

    outline: none;
    resize: none;

    z-index: 100;
}

/* ========================================
   右クリックメニュー
======================================== */

.context-menu {

    position: fixed;

    min-width: 180px;

    padding: 5px;

    background-color: #303030;

    border: 1px solid #666;

    border-radius: 6px;

    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);

    z-index: 200;

    user-select: none;

    box-sizing: border-box;
}


/* メニュー項目 */

.context-menu-item {

    display: block;

    width: 100%;

    padding: 10px 14px;

    background-color: transparent;

    color: #ffffff;

    border: none;

    border-radius: 3px;

    font-size: 14px;

    text-align: left;

    cursor: pointer;
}


/* カーソルを合わせた場合 */

.context-menu-item:hover {

    background-color: #527fa8;
}


/* 削除などの危険な操作 */

.context-menu-item.danger {

    color: #ff9999;
}


.context-menu-item.danger:hover {

    background-color: #803838;

    color: #ffffff;
}


/* 区切り線 */

.context-menu-separator {

    height: 1px;

    margin: 4px 5px;

    background-color: #555;
}

/* ========================================
   無効状態のツールバーボタン
======================================== */

#toolbar button:disabled {

    background-color: #303030;

    color: #666666;

    border-color: #444444;

    cursor: default;
}


/* ========================================
   ツールバーの区切り線
======================================== */

.toolbar-separator {

    width: 1px;

    margin: 2px 4px;

    background-color: #666666;
}
#toolbar { max-width: calc(100vw - 36px); flex-wrap: wrap; justify-content: center; }
#groupPanel { position:fixed; left:0; top:100px; bottom:0; width:280px; box-sizing:border-box; background:#303030; color:white; border:1px solid #666; z-index:11; display:flex; flex-direction:column; }
#groupPanel[hidden] { display:none; }
#groupPanel header { display:flex; align-items:center; justify-content:space-between; padding:10px; border-bottom:1px solid #666; }
#groupTree { overflow:auto; padding:6px; flex:1; }
.group-tree-row { display:flex; align-items:center; white-space:nowrap; }
#groupPanel button { background:transparent; color:white; border:0; padding:6px; cursor:pointer; }
#groupPanel button:disabled { cursor:default; color:#888; }
#groupPanel button:not(:disabled):hover { background:#555; }
#groupPanel button:not(:disabled):active { background:#788da1; }
.group-tree-label { flex:1; text-align:left; overflow:hidden; text-overflow:ellipsis; }
#groupPanelGrip { position:absolute; right:0; top:0; bottom:0; width:7px; cursor:ew-resize; touch-action:none; }
#toolbar button:not(:disabled):active { filter:brightness(1.3); }

#groupTree[hidden], #searchPane[hidden] { display:none; }
#groupPanel header button.active { background:#527fa8; }
#searchPane { flex:1; min-height:0; display:flex; flex-direction:column; gap:8px; padding:10px; }
#searchPane select, #searchQuery { width:100%; box-sizing:border-box; background:#222; color:white; border:1px solid #777; padding:6px; }
#searchFields { display:flex; flex-wrap:wrap; gap:6px 12px; font-size:13px; }
#searchResults { overflow:auto; flex:1; }
#searchResults button { display:block; width:100%; text-align:left; border-bottom:1px solid #555; overflow-wrap:anywhere; }
#searchResults small { display:block; color:#ccc; margin-top:4px; white-space:pre-wrap; }
#searchResults mark { background:#ffe36b; color:#222; }

#minimapPanel { position:fixed; right:12px; top:80px; width:300px; height:236px; max-width:calc(100vw - 24px); max-height:calc(100vh - 110px); display:flex; flex-direction:column; background:#303030; color:white; border:1px solid #777; box-sizing:border-box; z-index:12; }
#minimapPanel[hidden] { display:none; }
#minimapPanel header { display:flex; align-items:center; gap:5px; padding:5px 8px; }
#minimapPanel header span { flex:1; }
#minimapPanel button { background:#484848; color:white; border:1px solid #666; border-radius:3px; cursor:pointer; }
#minimapPanel button:hover { background:#666; }
#minimapPanel button:active { background:#8296aa; }
#minimapCanvas { width:100%; flex:1; min-height:0; cursor:crosshair; touch-action:none; }
#minimapGrip { position:absolute; bottom:0; left:0; width:12px; height:12px; cursor:nesw-resize; touch-action:none; }
#minimapPanel.folded { height:auto!important; }
#minimapPanel.folded #minimapCanvas, #minimapPanel.folded #minimapGrip { display:none; }

#minimapCanvas { cursor:grab; }
.tree-node-mark { display:inline-block; width:1.2em; text-align:center; color:#eee; }
.tree-node-mark.start { color:#64bc83; }
.tree-node-mark.middle { color:#719ed8; }
.tree-node-mark.end { color:#df7777; }
.tree-node-mark.memo { color:#e1c16b; }

/* 用途別ツールバー */
#toolbar { box-sizing:border-box; width:max-content; max-width:calc(100vw - 20px); gap:0; align-items:stretch; }
.toolbar-block { display:flex; flex-direction:column; justify-content:center; gap:6px; padding:0 10px; }
.toolbar-block + .toolbar-block { border-left:1px solid #666; }
.toolbar-row { display:flex; justify-content:center; gap:6px; }
#toolbar button { display:inline-flex; align-items:center; justify-content:center; gap:5px; padding:5px 8px; min-height:36px; white-space:nowrap; font-size:13px; }
.toolbar-row > button { flex:1; }
#toolbar svg { width:21px; height:21px; flex:none; }
.toolbar-histories { display:flex; gap:10px; }
.toolbar-caption { text-align:center; color:#ddd; font-size:11px; margin-bottom:3px; }
.toolbar-histories button { min-width:38px; }
#nodeSnapToggle { flex:0 1 auto; }
#groupPanel { top:var(--toolbar-bottom,110px); }
#minimapPanel { top:var(--toolbar-bottom,110px); max-height:calc(100vh - var(--toolbar-bottom,110px) - 12px); }
@media(max-width:1000px) { #toolbar { flex-wrap:wrap; row-gap:8px; } }
@media(max-width:600px) { .toolbar-block + .toolbar-block { border-left:0; } .toolbar-block { padding:0 4px; } }

/* ミニマップのタイトルバーでパネルを移動 */
#minimapPanel header { cursor:move; touch-action:none; user-select:none; }
#minimapPanel header.moving { cursor:grabbing; }

#touchControls[hidden] { display:none; }
#mainCanvas { touch-action:none; -webkit-user-select:none; user-select:none; -webkit-touch-callout:none; }
@media (pointer:coarse) {
    #touchControls[hidden] { display:flex; }
    #toolbar button { min-height:44px; }
    #toolbar { max-height:45vh; overflow-y:auto; }
    .context-menu-item { min-height:44px; box-sizing:border-box; }
    .node-editor, #searchQuery, #searchPane select { font-size:16px; }
}
