@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;600&family=Space+Mono:wght@400&display=swap');

@font-face {
    font-family: "HackGenConsoleNF";
    src: url("./src/fonts/HackGenConsoleNF-Regular.ttf") format("truetype");
}

:root {
    --bg-app: #0b1116;
    --bg-header: #121921;
    --bg-panel: #151d26;
    --bg-panel-2: #0f1720;
    --bg-canvas: #091017;
    --bg-hover: rgba(255, 255, 255, 0.06);
    --bg-active: rgba(74, 163, 255, 0.14);
    --bg-tab: #101720;
    --border-subtle: #243244;
    --border-strong: #345171;
    --border-accent: #4aa3ff;
    --text-primary: #edf5ff;
    --text-secondary: #91a2b6;
    --text-accent: #82c2ff;
    --danger: #e16a76;
    --font-ui: 'Noto Sans JP', system-ui, sans-serif;
    --font-mono: 'HackGenConsoleNF', 'Space Mono', 'JetBrains Mono', Consolas, monospace;
    --header-height: 52px;
    --status-height: 24px;
    --panel-header-height: 34px;
    --tabbar-height: 36px;
}

* {
    box-sizing: border-box;
    color-scheme: dark;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
}

body {
    font-family: var(--font-ui);
    background: radial-gradient(circle at top left, rgba(74, 163, 255, 0.08), transparent 35%), var(--bg-app);
    color: var(--text-primary);
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.app-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 16px;
    background: rgba(18, 25, 33, 0.96);
    border-bottom: 1px solid var(--border-subtle);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.logo-text {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(74, 163, 255, 0.15);
    color: var(--text-accent);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.controls {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.header-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 12px;
}

.header-link:hover {
    color: var(--text-primary);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

label {
    font-size: 12px;
    color: var(--text-secondary);
}

select,
.btn {
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    background: var(--bg-panel-2);
    color: var(--text-primary);
    font: inherit;
    font-size: 12px;
}

select {
    padding: 4px 8px;
}

.btn {
    padding: 6px 10px;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s;
}

.btn:hover,
select:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}

.btn-danger {
    background: rgba(225, 106, 118, 0.18);
    border-color: rgba(225, 106, 118, 0.44);
    color: #ffd8de;
}

.workspace-shell {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
}

.workspace,
.split-node {
    display: flex;
    flex: 1;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.split-node.split-v,
.workspace.split-v {
    flex-direction: column;
}

.pane-slot {
    display: flex;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    position: relative;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent), var(--bg-panel);
    border: 1px solid rgba(36, 50, 68, 0.55);
}

.panel.focused {
    box-shadow: inset 0 0 0 1px rgba(74, 163, 255, 0.42);
}

.panel-zoom-badge {
    position: absolute;
    top: 8px;
    right: 10px;
    z-index: 8;
    min-width: 58px;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid rgba(130, 194, 255, 0.34);
    background: rgba(12, 18, 24, 0.88);
    color: var(--text-accent);
    font-family: var(--font-mono);
    font-size: 11px;
    text-align: center;
    letter-spacing: 0.04em;
    opacity: 0;
    transform: translateY(-4px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.16s ease, transform 0.16s ease;
}

.panel-zoom-badge.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.panel.panel-drop-left::after,
.panel.panel-drop-right::after,
.panel.panel-drop-top::after,
.panel.panel-drop-bottom::after,
.panel.panel-drop-center::after {
    content: "";
    position: absolute;
    inset: 8px;
    border: 1px dashed rgba(130, 194, 255, 0.6);
    background: rgba(74, 163, 255, 0.12);
    pointer-events: none;
    z-index: 5;
}

.panel.panel-drop-left::after { inset: 8px 58% 8px 8px; }
.panel.panel-drop-right::after { inset: 8px 8px 8px 58%; }
.panel.panel-drop-top::after { inset: 8px 8px 58% 8px; }
.panel.panel-drop-bottom::after { inset: 58% 8px 8px 8px; }
.panel.panel-drop-center::after { inset: 16px; }

.panel-header {
    height: var(--panel-header-height);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 10px;
    background: rgba(18, 25, 33, 0.9);
    border-bottom: 1px solid var(--border-subtle);
    user-select: none;
    cursor: grab;
}

.panel-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.panel-btn {
    height: 24px;
    min-width: 24px;
    padding: 0 6px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
}

.panel-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.08);
}

.panel-content {
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    position: relative;
    background: var(--bg-canvas);
}

.tabbar {
    height: var(--tabbar-height);
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    gap: 2px;
    padding: 4px 6px 0;
    overflow-x: auto;
    overflow-y: hidden;
    background: rgba(16, 23, 32, 0.96);
    border-bottom: 1px solid var(--border-subtle);
    scrollbar-width: thin;
}

.tabbar.tabbar-drop-merge {
    background:
        linear-gradient(to bottom, rgba(82, 139, 255, 0.18), rgba(82, 139, 255, 0.08)),
        rgba(16, 23, 32, 0.96);
    box-shadow: inset 0 -2px 0 rgba(82, 139, 255, 0.72);
}

.tabbar::-webkit-scrollbar {
    height: 4px;
}

.tab {
    height: calc(var(--tabbar-height) - 5px);
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border-subtle);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    background: var(--bg-tab);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.tab:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

.tab.dragging {
    opacity: 0.45;
}

.tab.active {
    background: var(--bg-canvas);
    color: var(--text-primary);
    border-top: 2px solid var(--border-accent);
}

.tab.provisional .tab-title {
    font-style: italic;
}

.tab.readonly .tab-title {
    color: var(--text-accent);
}

.tab-title {
    overflow: hidden;
    text-overflow: ellipsis;
}

.tab-close {
    opacity: 0.58;
    border-radius: 999px;
    padding: 2px;
}

.tab-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.08);
}

.pane-split {
    flex-shrink: 0;
    background: rgba(36, 50, 68, 0.9);
    transition: background-color 0.12s;
}

.pane-split.split-h {
    width: 4px;
    cursor: col-resize;
}

.pane-split.split-v {
    height: 4px;
    cursor: row-resize;
}

.pane-split:hover,
.pane-split.active {
    background: var(--border-accent);
}

body.is-resizing-panels * {
    user-select: none !important;
}

.canvas-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-canvas);
}

.gui-preview-panel {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.gui-preview-canvas {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    cursor: default;
}

.gui-window-layer {
    position: absolute;
    inset: 0;
    z-index: 40;
    overflow: hidden;
    pointer-events: none;
}

.gui-floating-window {
    position: absolute;
    display: flex;
    flex-direction: column;
    min-width: 240px;
    min-height: 180px;
    border: 1px solid rgba(93, 162, 223, 0.82);
    border-radius: 7px;
    background: #0c1218;
    box-shadow: 0 0 16px rgba(72, 145, 210, 0.42), 0 18px 44px rgba(0, 0, 0, 0.54);
    overflow: hidden;
    pointer-events: auto;
}

.gui-floating-window.is-active {
    border-color: rgba(111, 186, 245, 0.96);
    box-shadow: 0 0 22px rgba(86, 164, 232, 0.54), 0 22px 58px rgba(0, 0, 0, 0.62);
}

.gui-floating-window.is-minimized {
    display: none;
}

.gui-floating-window.is-maximized {
    border-radius: 6px;
}

.gui-window-titlebar {
    height: 34px;
    flex: 0 0 34px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 12px;
    border-bottom: 1px solid #1d3348;
    background: linear-gradient(to bottom, #182636, #101923 48%, #0b1219);
    cursor: move;
    user-select: none;
}

.gui-window-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #f1f5f9;
    text-shadow: 0 1px 2px #000;
    font-size: 13px;
    font-weight: 500;
}

.gui-window-controls {
    display: flex;
    align-items: center;
    align-self: stretch;
    flex: 0 0 auto;
    height: 100%;
    margin-right: 6px;
}

.gui-window-control {
    width: 45px;
    height: 25px;
    padding: 0;
    border: 1px solid #30485f;
    border-top: 0;
    border-radius: 0;
    background: linear-gradient(to bottom, #1b2a3a, #0f1822 50%, #0a1017);
    color: #e5edf5;
    font-family: var(--font-mono);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
}

.gui-window-control + .gui-window-control {
    border-left: 0;
}

.gui-window-control:hover {
    background: linear-gradient(to bottom, #22364a, #152437 50%, #0d1722);
    color: #ffffff;
}

.gui-window-control.is-close {
    border-color: #5f1712;
    background: linear-gradient(to bottom, #ee9b92, #d64e3f 50%, #8f1d16);
    color: #ffffff;
}

.gui-window-control.is-close:hover {
    background: linear-gradient(to bottom, #ffb0a7, #ea6657 50%, #a92821);
}

.gui-window-content {
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #0b1117;
}

.gui-window-resize {
    position: absolute;
    z-index: 2;
    pointer-events: auto;
}

.gui-window-resize-n,
.gui-window-resize-s {
    left: 8px;
    right: 8px;
    height: 7px;
    cursor: ns-resize;
}

.gui-window-resize-n {
    top: -3px;
}

.gui-window-resize-s {
    bottom: -3px;
}

.gui-window-resize-e,
.gui-window-resize-w {
    top: 8px;
    bottom: 8px;
    width: 7px;
    cursor: ew-resize;
}

.gui-window-resize-e {
    right: -3px;
}

.gui-window-resize-w {
    left: -3px;
}

.gui-window-resize-ne,
.gui-window-resize-nw,
.gui-window-resize-se,
.gui-window-resize-sw {
    width: 12px;
    height: 12px;
}

.gui-window-resize-ne {
    top: -4px;
    right: -4px;
    cursor: nesw-resize;
}

.gui-window-resize-nw {
    top: -4px;
    left: -4px;
    cursor: nwse-resize;
}

.gui-window-resize-se {
    right: -4px;
    bottom: -4px;
    cursor: nwse-resize;
}

.gui-window-resize-sw {
    left: -4px;
    bottom: -4px;
    cursor: nesw-resize;
}

.gui-window-dock {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 0;
    pointer-events: none;
}

.gui-window-dock-item {
    max-width: min(220px, 48vw);
    padding: 6px 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: 1px solid rgba(93, 162, 223, 0.58);
    border-radius: 5px;
    background: linear-gradient(to bottom, #1b2a3a, #0f1822 50%, #0a1017);
    color: #eaf4ff;
    font-size: 12px;
    cursor: pointer;
    pointer-events: auto;
}

.gui-window-dock-item:hover {
    border-color: rgba(111, 186, 245, 0.92);
    background: linear-gradient(to bottom, #2d4860, #1a3045 50%, #102236);
}

.gui-debug-panel {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 70;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    max-width: min(420px, 52vw);
    border: 1px solid rgba(93, 162, 223, 0.48);
    border-radius: 5px;
    background: rgba(9, 13, 18, 0.92);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.38);
    color: #dbeafe;
    font-family: var(--font-mono);
    font-size: 11px;
    pointer-events: none;
}

.gui-debug-toggle {
    min-width: 58px;
    height: 28px;
    padding: 0 8px;
    border: 0;
    border-right: 1px solid rgba(93, 162, 223, 0.34);
    border-radius: 4px 0 0 4px;
    background: linear-gradient(to bottom, #1b2a3a, #0f1822 50%, #0a1017);
    color: #eaf4ff;
    font: inherit;
    cursor: pointer;
    pointer-events: auto;
}

.gui-debug-toggle:hover {
    background: linear-gradient(to bottom, #253b50, #17283a 50%, #0f1b28);
}

.gui-debug-summary {
    min-width: 0;
    height: 28px;
    padding: 7px 10px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #b8cbe0;
}

.gui-debug-detail {
    grid-column: 1 / -1;
    display: grid;
    gap: 2px;
    max-height: 150px;
    overflow: auto;
    padding: 8px 10px 10px;
    border-top: 1px solid rgba(93, 162, 223, 0.24);
    pointer-events: auto;
}

.gui-debug-panel.is-collapsed {
    max-width: 86px;
}

.gui-debug-panel.is-collapsed .gui-debug-summary,
.gui-debug-panel.is-collapsed .gui-debug-detail {
    display: none;
}

.gui-debug-row {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #9fb4c9;
}

body.is-moving-gui-window *,
body.is-resizing-gui-window * {
    user-select: none !important;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: text;
}

.hidden-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    padding: 0;
    border: none;
    z-index: 5;
    pointer-events: none;
    background: transparent;
    color: transparent;
    caret-color: transparent;
    resize: none;
    overflow: hidden;
    white-space: pre;
}

.popup-tooltip {
    position: fixed;
    display: none;
    max-width: min(520px, calc(100vw - 24px));
    padding: 10px 12px;
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    background: rgba(8, 14, 20, 0.98);
    color: var(--text-primary);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.34);
    white-space: pre-wrap;
    font-size: 12px;
    line-height: 1.5;
    z-index: 60;
    pointer-events: none;
}

.popup-menu {
    position: absolute;
    display: none;
    min-width: 240px;
    max-width: min(420px, calc(100% - 16px));
    max-height: 280px;
    margin: 0;
    padding: 6px;
    overflow: auto;
    list-style: none;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    background: rgba(13, 19, 28, 0.98);
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.4);
    z-index: 30;
}

.popup-menu li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 8px;
    border-radius: 6px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    cursor: pointer;
}

.popup-menu li.selected,
.popup-menu li:hover {
    background: var(--bg-hover);
}

.completion-item-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.completion-type {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    background: rgba(74, 163, 255, 0.18);
    color: var(--text-accent);
    font-size: 10px;
    flex: 0 0 auto;
}

.completion-detail {
    color: var(--text-secondary);
    font-size: 11px;
    flex: 0 0 auto;
}

.explorer-content {
    padding: 10px 0 16px;
    overflow: auto;
    background: var(--bg-panel-2);
}

.explorer-item {
    padding: 4px 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    color: var(--text-secondary);
}

.explorer-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.explorer-item.file {
    cursor: grab;
}

.explorer-item.dragging {
    opacity: 0.45;
}

.explorer-disclosure {
    width: 10px;
    height: 10px;
    flex: 0 0 10px;
    position: relative;
}

.explorer-disclosure::before {
    content: "";
    position: absolute;
    left: 1px;
    top: 1px;
    width: 0;
    height: 0;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-left: 5px solid var(--text-secondary);
    transition: transform 0.14s ease;
}

.explorer-disclosure.open::before {
    transform: rotate(90deg) translateX(-1px);
    transform-origin: 2px 50%;
}

.explorer-disclosure.empty::before {
    display: none;
}

.explorer-icon {
    position: relative;
    display: inline-block;
    flex: 0 0 auto;
}

.explorer-icon-folder {
    width: 14px;
    height: 10px;
    border: 1px solid rgba(130, 194, 255, 0.55);
    border-radius: 2px;
    background: rgba(74, 163, 255, 0.14);
}

.explorer-icon-folder::before {
    content: "";
    position: absolute;
    left: 1px;
    top: -4px;
    width: 7px;
    height: 4px;
    border: 1px solid rgba(130, 194, 255, 0.55);
    border-bottom: none;
    border-radius: 2px 2px 0 0;
    background: rgba(74, 163, 255, 0.18);
}

.explorer-icon-folder.open {
    background: rgba(130, 194, 255, 0.18);
    border-color: rgba(130, 194, 255, 0.72);
}

.explorer-icon-file {
    width: 12px;
    height: 14px;
    border: 1px solid rgba(237, 245, 255, 0.34);
    border-radius: 2px;
    background: rgba(237, 245, 255, 0.08);
}

.explorer-icon-file::before {
    content: "";
    position: absolute;
    top: -1px;
    right: -1px;
    width: 5px;
    height: 5px;
    background: linear-gradient(135deg, transparent 50%, rgba(237, 245, 255, 0.34) 50%);
}

.explorer-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.explorer-children {
    padding-left: 16px;
}

.status-bar {
    height: var(--status-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 12px;
    background: rgba(18, 25, 33, 0.96);
    border-top: 1px solid var(--border-subtle);
    font-size: 11px;
    color: var(--text-secondary);
}

.status-left,
.status-right {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.hidden {
    display: none !important;
}

@media (max-width: 960px) {
    .app-header {
        height: auto;
        padding: 10px 12px;
        align-items: flex-start;
    }

    .controls {
        justify-content: flex-start;
    }

    .workspace,
    .split-node {
        flex-direction: column;
    }

    .pane-split.split-h {
        width: 100%;
        height: 4px;
        cursor: row-resize;
    }

    .panel-header {
        cursor: default;
    }
}
