:root {
    --split-ratio: 0.5;
    --utility-hidden-height: 16px;
    --const-max-playControls-height: 130px;
    --const-collapsed-playControls-height: 70px;
    --playControls-height: 130px;
    --editor-bg: #1F1F1F;
    --top-utility-bg: #0b0b0f;
    --top-utility-btn: #2c2c2c;
}

@font-face {
    font-family: 'combo';
    src: url('Fonts/Inter.ttf') format('truetype');
    font-display: swap;
}

@font-face {
    font-family: 'mono';
    src: url('Fonts/ShareTechMono-Regular.ttf') format('truetype');
    font-display: swap;
}

@font-face {
    font-family: 'title';
    src: url('Fonts/FOT-NewRodin\ Pro\ B.otf') format('truetype');
    font-display: swap;
}

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: #111;

    font-family: "Google Sans", sans-serif;
    font-optical-sizing: auto;
    font-weight: 400;
    font-style: normal;
    font-variation-settings:
        "GRAD" 0;
}

.material-symbols-outlined {
    font-variation-settings:
        'FILL' 1,
        'wght' 400,
        'GRAD' 0,
        'opsz' 32
}

#canvasContainer {
    position: absolute;
    width: calc(var(--split-ratio) * 100%);
    height: calc(100% - var(--playControls-height) - 40px);
    top: 40px;
    left: 0;
    user-select: none;
    -webkit-user-select: none;
}

#canvasContainer.expanded {
    height: calc(100% - var(--playControls-height));
    top: 0;
    left: 0;
}

#canvasContainer #canvasOutline {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    object-fit: contain;
    scale: 0.89;
}

#canvasContainer .backgroundContainer {
    z-index: -1;
    position: absolute;
}

#canvasContainer #backgroundImage {
    z-index: -1;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    object-fit: contain;
    scale: 0.98;
}

#canvasContainer #backgroundVideo {
    z-index: 0;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    object-fit: contain;
    scale: 0.98;
    background: black;
}

#main {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
}

#playControls {
    user-select: none;
    -webkit-user-select: none;
    position: absolute;
    width: 100%;
    height: var(--playControls-height);
    bottom: 0;
    left: 0;
    z-index: 10;
    background: var(--top-utility-bg);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#playControls #timeControl {
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    height: 10px;
    background: linear-gradient(90deg, #962d2d 50%, #222 50%);
    margin: 4px 0;
    border-radius: 5px;
    border: none;
    outline: none;
    transition: background 0.3s ease;
}

#timeControl::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 8px;
    height: 15px;
    background: #962d2d;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.8);
    border-radius: 10px;
    cursor: pointer;
}

#timeControl::-moz-range-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 8px;
    height: 15px;
    background: #962d2d;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.8);
    border-radius: 10px;
    cursor: pointer;
}

#playControls #miniPreviewContainer {
    position: relative;
    width: 100%;
    height: 60px;
}

#playControls #showPlayControlsBtn {
    background-color: var(--top-utility-bg);
    overflow: hidden;
    width: 30%;
    position: absolute;
    bottom: 0;
    left: 25%;
    transform: translateX(-50%);
    height: 16px;
    color: white;
    font-size: 10px;
    text-align: center;
    display: flex;
    justify-content: center;
    cursor: pointer;
    box-sizing: border-box;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
    border-radius: 10px 10px 0 0;
    transition: background-color 100ms ease;
}

#playControls #showPlayControlsBtn:hover {
    background-color: var(--top-utility-btn);
}

#miniPreviewContainer #miniPreview {
    background: black;
    position: absolute;
    width: calc(100% - 4px);
    height: 100%;
    margin: 2px;
    border: 1px solid var(--top-utility-btn);
    box-sizing: border-box;
    border-radius: 4px;
}

#miniPreviewContainer .zoomContainer {
    position: absolute;
    top: 15px;
    left: 10px;
    display: flex;
    gap: 5px;
    z-index: 5;
}

#miniPreviewContainer #mpzoomOut,
#miniPreviewContainer #mpzoomIn {
    cursor: pointer;
    width: 30px;
    height: 30px;
    background: var(--top-utility-bg);
    border: 1px solid var(--top-utility-btn);
    border-radius: 5px;
    z-index: 5;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    opacity: 0.6;
    transition: opacity 100ms ease;
}

#miniPreviewContainer #mpzoomOut:hover,
#miniPreviewContainer #mpzoomIn:hover {
    opacity: 1;
}

#playControls #playControlContainer {
    position: relative;
    width: 100%;
    height: 60px;
    bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

#playControls .controlsContainer {
    display: flex;
    gap: 20px;
    align-items: center;
    justify-content: center;
}

.controlsContainer .controlButton {
    display: flex;
    width: 40px;
    height: 40px;
    border: 1px solid var(--top-utility-btn);
    padding: 5px;
    border-radius: 5px;
    color: white;
    font-size: 14px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-sizing: border-box;
}

.a {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 2px;
    left: -12px;
    object-fit: contain;
    opacity: 0.5;
    scale: 0.99;
}

#utilityContainer {
    position: absolute;
    width: 100%;
    height: calc(40px + var(--utility-hidden-height));
    top: 0;
    right: 0;
    z-index: 10;
    user-select: none;
    -webkit-user-select: none;
}

#utilityContainer.expanded {
    position: absolute;
    height: var(--utility-hidden-height);
    top: 0;
    right: 0;
    z-index: 5;
    user-select: none;
    -webkit-user-select: none;
}

#utilityContainer .closeBtn {
    background-color: var(--top-utility-bg);
    overflow: hidden;
    width: 30%;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    height: var(--utility-hidden-height);
    color: white;
    font-size: 10px;
    text-align: center;
    display: flex;
    justify-content: center;
    cursor: pointer;
    box-sizing: border-box;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
    border-radius: 0 0 10px 10px;
    transition: background-color 100ms ease;
}

#utilityContainer .closeBtn:hover {
    background-color: var(--top-utility-btn);
}

#utilityContainer .warnbtn {
    visibility: hidden;
    position: inherit;
    background: rgba(0, 0, 0, 0.3);
    width: 60px;
    height: 20px;
    color: white;
    margin: 4px;
    right: 0;
    display: flex;
    align-items: center;
    border-radius: 20px;
    cursor: pointer;
    justify-content: space-around;
}

.warnbtn span {
    font-size: 10px;
    line-height: 16px;
}

.warnbtn span.material-symbols-outlined {
    font-size: 12px;
    color: #FE8D59;
}

#topUtilityBtns {
    background: var(--top-utility-bg);
    width: 100%;
    height: 40px;
    padding: 5px;
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    gap: 5px;
    scrollbar-width: none;
    box-sizing: border-box;
    font-family: "Google Sans", sans-serif;
}

.utilityButton {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    padding: 5px;
    background: transparent;
    border: var(--top-utility-btn) 1px solid;
    box-sizing: border-box;
    color: white;
    width: 60px;
    height: 30px;
    text-align: center;
    font-size: 12px;
    border-radius: 5px;
    word-break: keep-all;
    cursor: pointer;
    overflow: hidden;
}

.utilityButton.noFixedsize {
    width: auto;
    padding: 5px 10px;
}

.utilityButton.miniButton {
    width: 30px;
    height: 30px;
    padding: 5px;
}

.utilityButton span.material-symbols-outlined {
    font-size: 22px;
    font-variation-settings:
        'FILL' 0,
        'wght' 300,
        'GRAD' 0,
        'opsz' 22
}

.utilityButton input[type="number"] {
    width: 50px;
    margin-left: 5px;
    background: transparent;
    border: none;
    border-bottom: 1px solid #838383;
    box-sizing: border-box;
    color: white;
    text-align: center;
    font-family: "Google Sans", sans-serif;
}

.utilityButton input[type="checkbox"] {
    margin-left: 5px;
    width: 16px;
    height: 16px;
}

.utilityButton input[type="file"] {
    display: none;
}

.utilityButton select {
    min-width: 30px;
    margin-left: 5px;
    background: transparent;
    border: none;
    border-bottom: 1px solid #838383;
    box-sizing: border-box;
    color: white;
    text-align: center;
    font-family: "Google Sans", sans-serif;
}

.utilityButton select option {
    background: #202020;
    color: white;
    border: none;
}

#editorContainer {
    position: absolute;
    top: 40px;
    bottom: 30px;
    left: calc(var(--split-ratio) * 100%);
    width: calc((1 - var(--split-ratio)) * 100%);
    height: calc(100% - var(--playControls-height) - 40px);
    background: var(--editor-bg);
    /* 背景深色 */
}

#panelSplitter {
    position: absolute;
    top: 40px;
    height: calc(100% - var(--playControls-height) - 40px);
    left: calc(var(--split-ratio) * 100% - 3px);
    width: 6px;
    cursor: col-resize;
    z-index: 4;
    background: transparent;
    transition: background 0.15s ease;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

#panelSplitter::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 2px;
    width: 2px;
    background: #3a3a3a;
    transition: background 0.15s ease, width 0.15s ease, left 0.15s ease;
}

#panelSplitter:hover::after,
#panelSplitter.dragging::after {
    left: 1px;
    width: 4px;
    background: #4a90e2;
}

#panelSplitter.expanded {
    top: 0;
    height: calc(100% - var(--playControls-height));
}

/* snap 狀態：canvas 被隱藏，splitter 固定在左緣並變粗 */
#panelSplitter.snapped {
    left: 0 !important;
    width: 10px;
    cursor: e-resize;
    z-index: 100;
    background: rgba(74, 144, 226, 0.08);
    transition: background 0.15s ease;
}

#panelSplitter.snapped::after {
    left: 3px;
    width: 4px;
    background: #3a3a3a;
    border-radius: 2px;
}

#panelSplitter.snapped:hover {
    background: rgba(74, 144, 226, 0.18);
}

#panelSplitter.snapped:hover::after,
#panelSplitter.snapped.dragging::after {
    left: 2px;
    width: 8px;
    background: #6ab0ff;
}

#visualEditor {
    position: absolute;
    left: 0;
    width: 100%;
    height: 100%;
}

#editorContainer.expanded {
    top: 0;
    height: calc(100% - var(--playControls-height));
}

.editor-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 5px;
    padding-top: calc(var(--utility-hidden-height) + 5px);
    box-sizing: border-box;
    font-family: 'Consolas', monospace;
    /* 必須設置寬度 */
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-wrap: normal;
    word-break: break-all;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    -webkit-overflow-scrolling: touch;
    border: none;
    outline: none;
    overflow: auto;
    scrollbar-width: thin;
    /* auto or thin */
    scrollbar-color: #838383 transparent;
    /* 滾動條顏色 */
}

#editor-input {
    background: transparent;
    color: transparent;
    /* 文字透明，我們看底層的字 */
    caret-color: #ffffff;
    /* 但要讓閃爍游標看得見 */
    resize: none;
    z-index: 2;
}

#highlight-layer {
    user-select: none;
    -webkit-user-select: none;
    pointer-events: none;
    color: #d4d4d4;
    /* 預設文字顏色 */
    z-index: 1;
}

#highlight-layer .highlight-warning {
    background: rgba(255, 77, 77, 0.3);
    text-decoration: underline wavy 1px rgba(255, 80, 80, 0.9);
    border-radius: 3px;
}

.utilityButton.expanded {
    width: 100%;
    height: 30px;
    border: none;
    padding: 0;
    height: var(--utility-hidden-height);
}

.utilityDropdown {
    position: static;
    display: flex;
    align-items: center;
    padding-bottom: 5px;
    margin-bottom: -5px;
}

.utilityDropdown.open .utilityDropdown-content,
.utilityDropdown:hover .utilityDropdown-content {
    left: 20px;
    display: flex;
    opacity: 1;
    pointer-events: auto;
}

.utilityDropdown-content {
    display: none;
    position: absolute;
    top: 40px;
    left: 0px;
    background-color: var(--top-utility-bg);
    min-width: 120px;
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.5);
    z-index: 100;
    border: 1px solid var(--top-utility-btn);
    border-radius: 10px;
    padding: 5px;
    flex-direction: column;
    gap: 5px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease-out;
}

.utilityDropdown-content .utilityButton {
    padding: 10px;
    border: none;
    width: 100%;
    box-sizing: border-box;
    text-align: left;
    justify-content: flex-start;
    height: 28px;
}

.utilityDropdown-content .utilityButton:hover {
    background-color: var(--top-utility-btn);
}

.utilityDropdown-content .utilityMenuTitle {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-right: 0px;
    cursor: default;
    overflow: visible;
}

.utilityDropdown-content .utilityMenuTitle .utilityMenuArrow {
    margin-left: 0px;
    font-size: 20px;
    color: #d4d4d4;
}

.utilitySubmenu {
    display: none;
    position: absolute;
    top: 0;
    left: 100%;
    min-width: 150px;
    background-color: var(--top-utility-bg);
    border: 1px solid var(--top-utility-btn);
    border-radius: 10px;
    padding: 5px;
    flex-direction: column;
    gap: 5px;
    box-shadow: 0px 8px 16px rgba(0, 0, 0, 0.5);
    z-index: 110;
}

.utilityDropdown-content .utilityMenuTitle:hover .utilitySubmenu {
    display: flex;
}

.utilitySubmenu .utilityButton {
    white-space: nowrap;
}

.utilitySubmenu hr {
    width: 90%;
    margin: 0;
    align-self: center;
    border: 1px solid var(--top-utility-btn);
}

.quick-panel {
    position: fixed;
    transform-origin: center center;
    transform: translate(-50%, -50%);
    aspect-ratio: 1/1;
    display: none;
    z-index: 1500;

    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 8px;
}

#center,
#select-up,
#select-down,
#select-left,
#select-right,
#select-up-left,
#select-up-right,
#select-down-left,
#select-down-right {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    border: 2px solid #ffffffaa;
    color: #ffffffaa;
    border-radius: 4px;
    transition: all 0.15s ease-out;
    background-color: var(--top-utility-bg);
    isolation: isolate;
}

#select-up-left {
    grid-area: 1 / 1 / 2 / 2;
}

#select-up {
    grid-area: 1 / 2 / 2 / 3;
}

#select-up-right {
    grid-area: 1 / 3 / 2 / 4;
}

#select-left {
    grid-area: 2 / 1 / 3 / 2;
}

#center {
    grid-area: 2 / 2 / 3 / 3;
    border-radius: 50%;
    width: 50%;
    height: 50%;
    margin: auto;
}

#select-right {
    grid-area: 2 / 3 / 3 / 4;
}

#select-down-left {
    grid-area: 3 / 1 / 4 / 2;
}

#select-down {
    grid-area: 3 / 2 / 4 / 3;
}

#select-down-right {
    grid-area: 3 / 3 / 4 / 4;
}

.quick-panel[data-active-dir="middle"] #center,
.quick-panel[data-active-dir="up"] #select-up,
.quick-panel[data-active-dir="down"] #select-down,
.quick-panel[data-active-dir="left"] #select-left,
.quick-panel[data-active-dir="right"] #select-right,
.quick-panel[data-active-dir="up-left"] #select-up-left,
.quick-panel[data-active-dir="up-right"] #select-up-right,
.quick-panel[data-active-dir="down-left"] #select-down-left,
.quick-panel[data-active-dir="down-right"] #select-down-right {
    border-color: #ffffff;
    background-color: #ffffff;
    color: #ffffff;
    transform: scale(1.1);
}

.quick-panel[data-active-dir="up"] #select-up span,
.quick-panel[data-active-dir="down"] #select-down span,
.quick-panel[data-active-dir="left"] #select-left span,
.quick-panel[data-active-dir="right"] #select-right span,
.quick-panel[data-active-dir="up-left"] #select-up-left span,
.quick-panel[data-active-dir="up-right"] #select-up-right span,
.quick-panel[data-active-dir="down-left"] #select-down-left span,
.quick-panel[data-active-dir="down-right"] #select-down-right span {
    color: #000000;
    mix-blend-mode: destination-out;
}

/* 尋找與取代浮動視窗樣式 */
.find-replace-bar {
    position: absolute;
    top: 10px;
    right: 25px;
    z-index: 100;
    background: rgba(22, 22, 28, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 8px 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    color: #eee;
}

.findbar-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.findbar-drag-handle {
    cursor: grab;
    color: #666;
    font-size: 18px;
    user-select: none;
    -webkit-user-select: none;
    transition: color 0.15s ease;
    margin-right: -2px;
}

.findbar-drag-handle:hover,
.find-replace-bar.dragging .findbar-drag-handle {
    color: #4a90e2;
    cursor: grabbing;
}

.findbar-input {
    background: #121216;
    border: 1px solid #333;
    border-radius: 4px;
    color: #fff;
    padding: 4px 8px;
    font-size: 13px;
    outline: none;
    width: 170px;
    transition: border-color 0.15s ease;
}

.findbar-input:focus {
    border-color: #4a90e2;
}

.findbar-count {
    font-size: 12px;
    color: #888;
    min-width: 45px;
    text-align: center;
}

.findbar-btn {
    background: #2a2a35;
    border: 1px solid #444;
    border-radius: 4px;
    color: #ddd;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
}

.findbar-btn:hover {
    background: #3b3b4a;
    color: #fff;
}

.findbar-btn.close-btn {
    background: transparent;
    border: none;
    color: #aaa;
    font-size: 14px;
    padding: 2px 6px;
}

.findbar-btn.close-btn:hover {
    color: #ff5555;
}

.findbar-btn.action-btn {
    background: #3a4a60;
    border-color: #4a5a70;
}

.findbar-btn.action-btn:hover {
    background: #4a6080;
}