:root {
    --ms-dark-blue: #336699;
    --ms-yellow: #ffcc00;
    --ms-border: #555555;
    --ms-bg: #ececec;
    --ms-content-bg: #ffffff;
    --ms-wz-shadow:
        1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000,
        -1px 1px 0 #000;
    --ms-btn-gradient: linear-gradient(
        to bottom,
        #fdfdfd 0%,
        #dcdcdc 100%
    );
    --ms-btn-hover-gradient: linear-gradient(
        to bottom,
        #fff7cc 0%,
        #ffcc00 100%
    );
    --ms-modal-bg: rgba(0, 0, 0, 0.6);
}

body {
    font-family: "Microsoft JhengHei", Arial, sans-serif;
    background-color: #222;
    background-image: radial-gradient(#333 1px, transparent 1px);
    background-size: 20px 20px;
    color: #333;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100dvh;
    padding: 12px 0;
    box-sizing: border-box;
    margin: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.container {
    background-color: var(--ms-bg);
    border: 3px solid var(--ms-border);
    border-radius: 8px;
    width: 95%;
    max-width: 680px;
    height: calc(100dvh - 24px);
    box-shadow: 6px 6px 0px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.header {
    background-color: var(--ms-dark-blue);
    color: white;
    padding: 10px 15px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--ms-border);
}

.header .title {
    font-size: 15px;
    text-shadow: var(--ms-wz-shadow);
}

.header .guild {
    font-size: 11px;
    color: var(--ms-yellow);
    text-shadow: var(--ms-wz-shadow);
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 8px;
    border-radius: 4px;
}

.content {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    overflow: hidden;
}

.panel {
    background: var(--ms-content-bg);
    border: 2px solid #bbb;
    border-radius: 6px;
    padding: 8px;
    font-size: 14px;
    box-shadow: inset 1px 1px 3px rgba(0, 0, 0, 0.1);
}

.panel-label {
    font-weight: bold;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #444;
    text-shadow: 1px 1px 0 #fff;
}

.nickname-box {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.nickname-box input {
    font-weight: bold;
    color: var(--ms-dark-blue);
    flex: 1;
    min-width: 100px;
}

.action-group {
    display: flex;
    gap: 6px;
    margin-left: auto;
}

.participant-list {
    margin-top: 4px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    min-height: 18px;
}

.participant-tag {
    font-size: 11px;
    background: #e8f4f8;
    color: #336699;
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid #abd2e0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.participant-tag.host {
    background: #fff3cd;
    color: #856404;
    border-color: #ffeeba;
}

.kick-btn {
    cursor: pointer;
    color: #ff4444;
    font-weight: bold;
    margin-left: 2px;
    padding: 3px 5px;
    border-radius: 50%;
    transition: background 0.2s;
    font-size: 13px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.kick-btn:hover {
    background: rgba(255, 0, 0, 0.1);
}

.color-picker {
    display: flex;
    gap: 5px;
    margin-top: 10px;
    flex-wrap: wrap;
    padding: 8px;
    background: #f9f9f9;
    border-radius: 6px;
    border: 1px dashed #ccc;
}

.color-option {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s;
    position: relative;
    flex-shrink: 0;
}

.color-option::after {
    content: '';
    position: absolute;
    inset: -10px;
}

.color-option:hover {
    transform: scale(1.08);
}

.color-option.selected {
    border-color: #333;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

.door.mobile-pending {
    border-color: var(--ms-yellow) !important;
    box-shadow: 0 0 8px var(--ms-yellow);
}

.door.mobile-pending::before {
    content: "...";
    position: absolute;
    top: 2px;
    left: 5px;
    font-size: 10px;
    color: var(--ms-yellow);
    font-weight: bold;
}

.join-box {
    display: flex;
    gap: 6px;
    margin-top: 4px;
    margin-bottom: 0;
}

@media (max-width: 768px) {
    .pip-btn {
        display: none !important;
    }

    .map-area {
        margin-top: 8px;
        margin-bottom: 8px;
    }
}

.help-btn {
    background: #fff;
    border: 2px solid var(--ms-dark-blue);
    color: var(--ms-dark-blue);
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    text-align: center;
    font-weight: bold;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    user-select: none;
    display: block;
    width: 100%;
    font-size: 14px;
}

.help-btn:hover {
    background: var(--ms-dark-blue);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.help-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

input {
    padding: 5px 8px;
    border: 2px solid #ccc;
    border-radius: 4px;
    outline: none;
    font-family: inherit;
}

input:focus {
    outline: 2px solid var(--ms-dark-blue);
    outline-offset: 1px;
    border-color: var(--ms-dark-blue);
}

.ms-btn {
    background: var(--ms-btn-gradient);
    border: 2px solid var(--ms-border);
    border-radius: 4px;
    padding: 4px 12px;
    cursor: pointer;
    font-weight: bold;
    color: #333;
    box-shadow: inset 1px 1px 0px #fff;
    text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.9);
    transition: all 0.1s;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    white-space: nowrap;
}

.ms-btn:hover:not(:disabled) {
    background: var(--ms-btn-hover-gradient);
    border-color: #775500;
}

.ms-btn:active:not(:disabled) {
    transform: translate(1px, 1px);
    box-shadow: none;
}

.ms-btn.primary {
    background: linear-gradient(
        to bottom,
        #77aadd 0%,
        #336699 100%
    );
    color: white;
    border-color: #224466;
    text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.5);
}

.ms-btn.danger {
    background: linear-gradient(
        to bottom,
        #ef5350 0%,
        #c62828 100%
    );
    color: white;
    border-color: #b71c1c;
    text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.5);
}

.ms-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #e0e0e0;
    border-color: #bbb;
    color: #888;
    text-shadow: none;
}

#toast-container {
    position: fixed;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    pointer-events: none;
}

.toast {
    background: rgba(40, 40, 40, 0.92);
    color: #fff;
    padding: 7px 16px;
    border-radius: 20px;
    font-size: 12px;
    white-space: nowrap;
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    animation: toast-in 0.18s ease;
    transition: opacity 0.3s;
}
.toast.success { background: rgba(46, 125, 50, 0.95); }
.toast.error   { background: rgba(183, 28, 28, 0.95); }
.toast.warn    { background: rgba(200, 100, 0, 0.95); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--ms-modal-bg);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(2px);
}

.modal {
    background: var(--ms-bg);
    border: 3px solid var(--ms-border);
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    box-shadow: 8px 8px 0px rgba(0, 0, 0, 0.5);
    animation: modalPop 0.2s ease-out;
}

@keyframes modalPop {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-header {
    background: var(--ms-dark-blue);
    color: white;
    padding: 8px 12px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--ms-border);
}

.modal-content {
    padding: 15px;
    font-size: 13px;
    line-height: 1.6;
    max-height: 70vh;
    overflow-y: auto;
}

.modal-section {
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 8px 10px;
}

.section-label {
    font-size: 10px;
    font-weight: bold;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 7px;
}

.modal-close {
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: -8px -8px -8px 0;
    border-radius: 4px;
}

.log-section {
    margin-top: 5px;
}

.log-header {
    font-size: 12px;
    font-weight: bold;
    color: #666;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

#btn-log-toggle {
    font-size: 10px;
    height: 18px;
    padding: 0 6px;
}

.log-panel {
    background: #111;
    color: #00ff00;
    font-family: "Consolas", monospace;
    font-size: 11px;
    height: 100px;
    overflow-y: auto;
    padding: 8px;
    border: 2px solid #444;
    border-radius: 4px;
    display: none;
    flex-direction: column-reverse;
}

.log-entry {
    margin-bottom: 2px;
}

.log-warn {
    color: #ffcc00;
}

.log-error {
    color: #ff4444;
}

.status-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--ms-content-bg);
    border: 2px solid #bbb;
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 11px;
    box-shadow: inset 1px 1px 3px rgba(0, 0, 0, 0.1);
}

.map-area {
    background: #bbb;
    padding: 6px 6px 10px;
    border-radius: 6px;
    border: 2px solid #555;
    box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    overflow: hidden;
}

.floor {
    display: flex;
    align-items: stretch;
    gap: 4px;
    flex: 1;
}

.f-label {
    width: 24px;
    font-weight: bold;
    font-size: 11px;
    color: #fff;
    background: #444;
    border-radius: 3px;
    text-shadow: 1px 1px 0 #000;
    text-align: center;
    padding: 0;
    box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.door-grid-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.door-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    flex: 1;
}

.door {
    position: relative;
    height: 100%;
    min-height: 36px;
    width: 100%;
    border: 1.5px solid #888;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: border-color 0.1s;
    background: #fff;
    overflow: hidden;
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.8);
}

.door.state-pass {
    background: rgba(
        var(--marker-color-rgb, 66, 133, 244),
        1
    );
    border-color: var(--marker-color, #4285f4);
    border-width: 2px;
}

/* 死路小點容器 */
.dead-end-dots {
    position: absolute;
    top: 2px;
    right: 2px;
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    max-width: 50%;
    justify-content: flex-end;
    pointer-events: none;
}

.dead-dot {
    font-size: 20px;
    font-weight: bold;
    line-height: 1;
    text-shadow:
        1px 1px 0 #fff,
        -1px -1px 0 #fff,
        1px -1px 0 #fff,
        -1px 1px 0 #fff,
        0 1px 2px rgba(0, 0, 0, 0.3);
}

.door:hover {
    border-color: #333;
}

.door:active {
    border-bottom-width: 2px;
    transform: translateY(2px);
}


.door-cell-id {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: rgba(0, 0, 0, 0.55);
    font-weight: 900;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
    pointer-events: none;
}

.door.state-pass .door-cell-id {
    color: rgba(255, 255, 255, 0.75);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.door-tag {
    position: absolute;
    bottom: 1px;
    right: 0;
    font-size: 10px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    padding: 0 3px;
    border-radius: 2px;
    transform: scale(0.8);
    pointer-events: none;
    display: none;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    z-index: 3;
}

.door.state-pass .door-tag {
    display: block;
}

.footer-tools {
    display: flex;
    gap: 8px;
    margin-top: 5px;
}

.instructions-btn-container {
    display: flex;
    justify-content: center;
    margin-top: 5px;
}

.help-btn {
    font-size: 12px;
    color: var(--ms-dark-blue);
    text-decoration: underline;
    cursor: pointer;
    padding: 5px;
}

#pip-btn {
    display: none;
    background: linear-gradient(
        to bottom,
        #e1f5fe 0%,
        #b3e5fc 100%
    );
    border-color: #0288d1;
    color: #01579b;
}

/* 懸浮模式：僅顯示地圖、狀態列（僅 pip 按鈕）與清空標記 */
.container.pip-active .header,
.container.pip-active .log-section,
.container.pip-active .instructions-btn-container,
.container.pip-active #btn-reset-settings,
.container.pip-active #btn-summary {
    display: none !important;
}

.container.pip-active .status-bar > *:not(#pip-btn) {
    display: none !important;
}

.container.pip-active #pip-btn {
    display: inline-flex !important;
    font-size: 10px;
    padding: 4px 8px;
    margin-left: 0;
}

.container.pip-active .participants-container {
    margin-top: 5px !important;
    padding-top: 5px !important;
    border-top: none !important;
}

#loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.7);
    z-index: 1000;
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 10px;
}

.spinner {
    width: 30px;
    height: 30px;
    border: 4px solid #eee;
    border-top: 4px solid var(--ms-dark-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .spinner {
        animation: none;
        border-top-color: var(--ms-dark-blue);
        border-color: var(--ms-dark-blue);
        opacity: 0.6;
    }

    @keyframes modalPop {
        from { opacity: 0; }
        to   { opacity: 1; }
    }

    @keyframes toast-in {
        from { opacity: 0; }
        to   { opacity: 1; }
    }
}
