* {
    margin: 0;
    padding: 0;
    touch-action: none;
}
body {
    overflow: hidden;
    font-family: 'Arial', sans-serif;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}
.hidden {
    display: none !important;
}
#ui {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
#ui * {
    pointer-events: auto;
}
#ViewCubeContainer {
    position: absolute;
    width: 140px;
    height: 140px;
    right: 0;
    top: 0;
}
#infoPanel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.3);
}
#infoPanel > #infoPanelContent {
    position: absolute;
    top: 40px;
    left: 50%;
    transform: translate(-50%, 0);
    min-height: 280px;
    min-width: 320px;
    padding: 8px;
    border-radius: 24px;
    color: black;
    background-color: #eeed;
    display: flex;
    flex-direction: column;
}
#infoPanel > #infoPanelContent > #header {
    font-size: 24px;
    font-weight: bold;
    padding-bottom: 16px;
    color: #444;
    display: none;
}
#infoPanel > #infoPanelContent > #tabs {
    display: flex;
    gap: 16px;
    background-color: #666;
    padding: 8px;
    border-radius: 22px;
}
#infoPanel > #infoPanelContent > #tabs > .tab {
    padding: 8px;
    border-radius: 16px;
    cursor: pointer;
    flex-grow: 1;
    text-align: center;
    font-weight: bold;
    font-size: 14px;
    color: #222;
    transition: background-color 250ms ease;
}
#infoPanel > #infoPanelContent > #tabs > .tab:hover {
    background-color: #eee;
}
#infoPanel > #infoPanelContent > #tabs > .tab.active {
    background-color: #eee;
}
#infoPanel > #infoPanelContent > #infoPanels {
    padding: 16px;
}
#infoPanel > #infoPanelContent .control-item {
    display: flex;
    justify-content: space-between;
    gap: 32px;
    line-height: 1.5;
}
#infoPanel > #infoPanelContent > #infoPanels h1 {
    font-size: 14px;
    font-weight: bold;
    padding: 0 0 6px 0;
}
#infoPanel > #infoPanelContent .control-item > .control-action {
    text-align: left;
    color: #333;
}
#infoPanel > #infoPanelContent .control-item > .control-key {
    text-align: right;
    color: #666;
}
#infoPanel > #infoPanelContent .control-spacer {
    border-bottom: 1px dashed #666;
    margin: 10px 0;
}

#loadingWrap {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: black;
}

#spinner {
    width: min(30vw, 200px);
    aspect-ratio: 1 / 1;
    border: 15px solid rgb(255, 255, 255);
    border-top-color: rgba(255, 255, 255, 0);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#loadingText {
    margin-top: 25px;
    color: white;
    font-size: clamp(16px, 3vw, 28px);
    text-shadow: 0 0 4px rgba(0,0,0,0.5);
}

.ui-initially-hidden {
    display: none !important;
}

/*#loadingWrap > #loadingText {*/
/*    font-size: 18px;*/
/*    color: white;*/
/*    text-align: center;*/
/*    text-shadow: 0 0 4px rgba(0, 0, 0, 0.5);*/
/*}*/
/*#loadingWrap > #loadingBar {*/
/*    width: 100%;*/
/*    height: 10px;*/
/*    margin-top: 8px;*/
/*    border-radius: 4px;*/
/*    overflow: hidden;*/
/*}*/

#controlsWrap {
    position: absolute;
    left: max(16px, env(safe-area-inset-left));
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));

    display: flex;
    flex-direction: column;
}

#controlsWrap.faded-in {
    visibility: visible;
    opacity: 1;
    transition: opacity 0.5s ease-out;
}
#controlsWrap.faded-out {
    visibility: hidden;
    opacity: 0;
    transition: visibility 0s 0.5s, opacity 0.5s ease-out;
}

#controlsWrap > #timelineContainer {
    height: 30px;
    cursor: pointer;
}
#controlsWrap > #timelineContainer > #line {
    width: 100%;
    height: 50%;
    border-bottom: 1px solid #8888;
}
#controlsWrap > #timelineContainer > #handle {
    position: absolute;
    top: 15.5px;
    width: 10px;
    height: 10px;
    transform: translate(-50%, -50%);
    border: 1px solid black;
    border-radius: 50%;
    background-color: #fff8;
}
#controlsWrap > #timelineContainer > #time {
    position: absolute;
    top: 0;
    padding: 2px 4px;
    transform: translate(-50%, -100%);
    font-size: 12px;
    color: white;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 4px;
}
#controlsWrap > #buttonContainer {
    display: flex;
    gap: 8px;
}

/* spacer */

.spacer {
    flex-grow: 1;
}

/* settingsPanel */

#settingsPanel {
    position: fixed;
    right: max(16px, env(safe-area-inset-right));
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 70px);
    padding: 10px;
    color: #eee;
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 8px;

    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;

    font-size: 14px;
}
#settingsPanel > .settingsRow {
    display: flex;
    gap: 4px;
    width: 100%;
    
}
#settingsPanel > .settingsRow > .button {
    padding: 10px 0px;
    flex-grow: 1;
}

/* toggleWrap */

.toggleWrap {
    position: relative;
    background-color: #dddd;
    border: 1px solid #888;
    border-radius: 8px;
    height: 40px;
    width: 120px;
}
.toggleWrap > .toggleHighlight {
    position: absolute;
    left: 0;
    width: 50%;
    height: 100%;
    background-color: #eee;
    border-radius: 8px;
    transition: left 0.1s ease-out;
}
.toggleWrap > .toggleHighlight.right {
    left: 60px;
}
.toggleWrap > button {
    position: absolute;
    width: 60px;
    height: 100%;
    border: 0;
    border-radius: 8px;

    cursor: pointer;
    font-size: 14px;
    letter-spacing: -0.25px;

    color: #222;
    background-color: transparent;

    appearance: none;
}
.toggleWrap > button:hover {
    color: black;
}
.toggleWrap > button.left {
    left: 0;
}
.toggleWrap > button.right {
    right: 0;
}

/* button */
.button {
    width: 40px;
    height: 40px;
    padding: 0;
    margin: 0;
    color: #222;
    background-color: #dddd;
    border: 1px solid #888;
    border-radius: 8px;
    cursor: pointer;

    /* font-weight: bold; */
    font-size: 14px;
    letter-spacing: -0.25px;
}
.button:hover {
    background-color: #eee;
}
.button > svg {
    display: block;
    margin: auto;
}
#poster {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}
button {
    color: #222;
}
button:active {
    outline: none;
}
#joystickBase {
    position: absolute;
    width: 96px;
    height: 96px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    touch-action: none;

    background: radial-gradient(circle at center, #0000 50%, #000f 100%);
    background-color: #0002;
}

#joystickBase > #joystick {
    position: absolute;
    width: 48px;
    height: 48px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    touch-action: none;

    background-color: #fff8;
}

/* === [RulerMarking] === */
.rm-ui-container{
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    height: 100vh;
    background-color: #eeed;
    color: black;
    font-family: Arial, sans-serif;
    transition: width 0.3s ease-in-out, right 0.3s ease-in-out;
    box-sizing: border-box;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    border-radius: 24px;
    gap: 10px;
    padding-top: 10px;
    padding-right: 10px;
    padding-left: 10px;
    padding-bottom: 10px;
}

.rm-toggle-button{
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 60px;
    background-color: #00000000;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-top-left-radius: 5px;
    border-bottom-left-radius: 5px;
    border-top-left-radius: 5px;
    border-bottom-left-radius: 5px;
    z-index: 1001;
}

/* switch button */
.rm-switch-button{
    position: relative;
    width: 280px;
    height: 5vh;
    background-color: #444;
    color: black;
    font-family: Arial, sans-serif;
    box-sizing: border-box;
    z-index: 1000;
    display: flex;
    border-radius: 12px;
}

.rm-switch-slider{
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 2.5%;
    width: 30%;
    height: 80%;
    background-color: #eeed;
    color: black;
    font-family: Arial, sans-serif;
    transition: left 0.3s ease, right 0.3s ease;
    box-sizing: border-box;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    border-radius: 12px;
}

.rm-switch-span{
    position: absolute; 
    width: 30%; 
    height: 5vh; 
    display: flex;
    justify-content: center; 
    align-items: center; 
    font-weight: bold;
    color: black;
    pointer-events: auto; 
    cursor: pointer; 
    border-radius: 12px;
    font-family: Arial, sans-serif;
    z-index: 1002;
}

.rm-switch-span-a { left: 2.5%; }
.rm-switch-span-b { left: 35%; }
.rm-switch-span-c { left: 67.5%; }

/* page */
.rm-page-container{
    position: relative;
    width: 280px;
    height: 95vh;
    background-color: hsla(0, 0%, 50%, 0.2);
    color: black;
    font-family: Arial, sans-serif;
    box-sizing: border-box;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    overflow-y: auto;
}

/* mode switch */
.rm-bin-switch{
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    border-bottom: 1px dashed #444444;
    /* height: 120px;       */
    flex-shrink: 0;     
}

.rm-bin-switch-label{
    width: 260px;
    height: 1vh; 
    font-weight: bold;
}

.rm-bin-switch-button{
    position: relative;
    width: 260px;
    height: 4vh;
    background-color: #444;
    color: black;
    font-family: Arial, sans-serif;
    box-sizing: border-box;
    z-index: 1000;
    display: flex;
    border-radius: 12px;
}

.rm-bin-switch-slider{
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 2.5%;
    width: 46.25%;
    height: 80%;
    background-color: #eeed;
    color: black;
    font-family: Arial, sans-serif;
    transition: left 0.3s ease, right 0.3s ease;
    box-sizing: border-box;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    border-radius: 12px;
}

.rm-bin-switch-span{
    position: absolute; 
    width: 46.25%; 
    height: 4vh; 
    display: flex;
    justify-content: center; 
    align-items: center; 
    font-weight: bold;
    color: black;
    pointer-events: auto; 
    cursor: pointer; 
    border-radius: 12px;
    font-family: Arial, sans-serif;
    z-index: 1002;
}

/* draw page */
.rm-line-container{
    flex-grow: 1;
    padding: 10px;
    overflow-y: auto;
    box-sizing: border-box;
}

.rm-line-button-container{
    display: flex;
    justify-content: space-around;
    padding: 10px;
    border-top: 1px dashed #444444;
    flex-shrink: 0;
}

.rm-line-button{
    padding: 8px 15px;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.rm-line-button-add{
    background-color: #4CAF50;
}

.rm-line-button-del{
    background-color: #fa2424;
}

/* url button */
.rm-url-button-container{
    display: flex;
    padding: 10px 10px;
    gap: 10px;
    border-bottom: 1px dashed #444444;
    flex-shrink: 0;
    flex-direction: column;
}

.rm-url-button-label{
    width: 260px;
    height: 1vh; 
    font-weight: bold;
}

.rm-url-button{
    width: 100%; 
    height: 4vh; 
    display: flex;
    justify-content: center; 
    align-items: center; 
    font-weight: bold;
    color: black;
    pointer-events: auto; 
    cursor: pointer; 
    border-radius: 12px;
    font-family: Arial, sans-serif;
    z-index: 1002;
    background-color: #4CAF50;
}

/* scale/length input label */
.rm-input-label{
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 6px;
    background: rgba(254, 255, 186, 0.9);
    color: #333;
    pointer-events: auto;
    text-align: center;
    width: 75px;
    outline: none;        
    position: absolute;
    transform: translate(-50%, -50%);
}

/* input field */
.rm-input-field-container{
    display: flex;
    padding: 10px 10px;
    gap: 10px;
    border-bottom: 1px dashed #444444;
    flex-shrink: 0;
    flex-direction: column;
    align-items: center; 
}

.rm-input-field-label{
    width: 100%;
    height: 1vh; 
    font-weight: bold;
}

.rm-input-field{
    width: 80%; 
    height: 3vh;
    display: flex;
    justify-content: center;
    align-items: center; 
    font-weight: bold;
    color: rgb(255, 255, 255);
    pointer-events: auto; 
    cursor: pointer; 
    border-radius: 12px;
    font-family: Arial, sans-serif;
    z-index: 1002;
    background-color: #333;
    text-align: center;
}

/* line container */
.rm-line-pos-container{
    margin-bottom: 2px;
    padding: 2px;
    border: 1px solid #333;
    border-radius: 6px;
    cursor: pointer;
}

.rm-line-pos{
    padding: 2px;
    margin-top: 2px;
    margin-bottom: 2px;
    font-weight: bold;
    border: 1px solid #444444;
    background-color: #444444;
}

.rm-pos-label{
    display: flex;
    gap: 1px;
    margin-bottom: 5px;
}

.-rm-position-input-wrapper{
    display: flex;
    align-items: center;
    border: 1px solid #777;
    border-radius: 3px;
    overflow: hidden;
}

.rm-axis-label{
    padding: 3px;
    /* background-color: #666; */
    cursor: e-resize;
    position: relative;
}

.rm-hover-pointer{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    font-size: 0.8em;
    color: #ddd;
}

.rm-pos-input{
    width: 70%;
    padding: 5px;
    border: none;
    background-color: #555555;
    color: #fff;
    outline: none;
    box-sizing: border-box;
    border: 1px solid #333;
    border-radius: 6px;
    margin-top: 5px;
}

/* === File Size Dialog === */
.file-size-dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.file-size-dialog-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.file-size-dialog-content {
    position: relative;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    max-width: 90vw;
    max-height: 90vh;
    width: 400px;
    overflow: hidden;
    animation: fileSizeDialogSlideIn 0.3s ease-out;
}

@keyframes fileSizeDialogSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.file-size-dialog-header {
    padding: 24px 24px 16px 24px;
    border-bottom: 1px solid #e0e0e0;
}

.file-size-dialog-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: #333;
    text-align: center;
}

.file-size-dialog-body {
    padding: 24px;
    text-align: center;
}

.file-size-icon {
    margin-bottom: 16px;
    color: #666;
}

.file-size-message {
    margin: 0 0 12px 0;
    font-size: 16px;
    line-height: 1.5;
    color: #555;
}

.file-size-sub-message {
    margin: 0 0 20px 0;
    font-size: 14px;
    line-height: 1.4;
    color: #888;
    font-style: italic;
}

.file-size-message #file-size-value {
    font-weight: 600;
    color: #2196F3;
}

.file-size-options {
    margin-top: 20px;
}

.file-size-checkbox-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: #666;
    user-select: none;
}

.file-size-checkbox-label input[type="checkbox"] {
    display: none;
}

.checkmark {
    position: relative;
    width: 18px;
    height: 18px;
    border: 2px solid #ddd;
    border-radius: 4px;
    background-color: white;
    transition: all 0.2s ease;
}

.file-size-checkbox-label input[type="checkbox"]:checked + .checkmark {
    background-color: #2196F3;
    border-color: #2196F3;
}

.file-size-checkbox-label input[type="checkbox"]:checked + .checkmark::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.file-size-dialog-footer {
    padding: 16px 24px 24px 24px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.file-size-button {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 80px;
}

.file-size-button-cancel {
    background-color: #f5f5f5;
    color: #666;
    border: 1px solid #ddd;
}

.file-size-button-cancel:hover {
    background-color: #e0e0e0;
    color: #333;
}

.file-size-button-continue {
    background-color: #2196F3;
    color: white;
}

.file-size-button-continue:hover {
    background-color: #1976D2;
}

.file-size-button:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.3);
}

/* 行動裝置適配 */
@media (max-width: 768px) {
    .file-size-dialog-content {
        width: 95vw;
        margin: 20px;
    }
    
    .file-size-dialog-header h3 {
        font-size: 18px;
    }
    
    .file-size-message {
        font-size: 14px;
    }
    
    .file-size-dialog-footer {
        flex-direction: column;
    }
    
    .file-size-button {
        width: 100%;
    }
}