* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

body {
    font-family: 'Microsoft YaHei', sans-serif;
    background: #000;
    min-height: 100vh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    touch-action: pan-x pan-y;
}

#game-container {
    width: 100vw;
    height: 100vh;
    background: #000;
    position: fixed;
    top: 0;
    left: 0;
    overflow: hidden;
}

/* iOS 移动端竖屏：旋转画面模拟横屏 */
@media (orientation: portrait) {
    html.ios-device.mobile-device #game-container {
        width: 100vh;
        height: 100vw;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) rotate(90deg);
        transform-origin: center center;
        visibility: visible;
    }

    html.ios-device.mobile-device #rotate-tip {
        display: none !important;
    }
}

/* 非 iOS 移动端竖屏：显示旋转提示（Android 锁屏 API 失败时的兜底） */
@media (orientation: portrait) {
    html.mobile-device:not(.ios-device) #rotate-tip {
        display: flex !important;
    }

    html.mobile-device:not(.ios-device) #game-container {
        visibility: hidden;
    }
}

/* 横屏或 PC 端：正常显示游戏 */
@media (orientation: landscape) {
    #rotate-tip {
        display: none !important;
    }

    #game-container {
        visibility: visible;
        width: 100vw;
        height: 100vh;
        transform: none;
    }
}

/* 旋转提示遮罩 */
#rotate-tip {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, #1a1a2e 0%, #4a1a6b 50%, #1a1a2e 100%);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    color: white;
    font-size: 18px;
    font-family: 'Microsoft YaHei', sans-serif;
    text-align: center;
    gap: 20px;
}

#rotate-icon {
    font-size: 72px;
    animation: rotateHint 1.5s ease-in-out infinite;
    display: block;
}

#rotate-tip p {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.8);
    margin-top: 8px;
}

@keyframes rotateHint {
    0%   { transform: rotate(0deg); }
    40%  { transform: rotate(90deg); }
    60%  { transform: rotate(90deg); }
    100% { transform: rotate(0deg); }
}

/* 横屏模式优化 */
@media (max-width: 900px) and (orientation: landscape) {
    #game-container {
        width: 100vw;
        height: 100vh;
    }

    #room-image {
        object-fit: cover;
        width: 100vw;
        height: 100vh;
    }
}

/* 标题画面 */
#title-screen {
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, #1a1a2e 0%, #4a1a6b 50%, #1a1a2e 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    animation: fadeIn 1s ease;
}

.title-text {
    font-size: 48px;
    font-weight: bold;
    margin-bottom: 20px;
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.8);
    animation: titlePulse 2s ease-in-out infinite;
}

.subtitle {
    font-size: 18px;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 50px;
    text-align: center;
    padding: 0 20px;
}

.start-btn {
    padding: 20px 60px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 30px;
    color: white;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.5);
    transition: all 0.3s ease;
}

.start-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 40px rgba(102, 126, 234, 0.7);
}

/* 游戏画面 */
#game-play {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
}

#room-scene {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

#room-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

#cat-image {
    position: absolute;
    left: 20%;
    top: 68%;
    width: 12%;
    height: auto;
    z-index: 50;
    pointer-events: none;
    animation: fadeIn 0.5s ease;
    transform: rotate(-5deg);
}

#pen-image {
    position: absolute;
    left: 68%;
    top: 73%;
    width: 8%;
    height: auto;
    z-index: 50;
    pointer-events: none;
    animation: fadeIn 0.5s ease;
    transition: all 0.3s ease;
}

#pen-image.fallen {
    left: 69%;
    top: 76%;
    transform: rotate(25deg);
}

#pen-holder-image {
    position: absolute;
    left: 63%;
    top: 65%;
    width: 5%;
    height: auto;
    z-index: 60;
    pointer-events: none;
    transition: transform 0.1s ease;
    user-select: none;
}

#pen-holder-hotspot {
    position: absolute;
    left: 60%;
    top: 62%;
    width: 13%;
    height: 13%;
    z-index: 61;
    cursor: grab;
    user-select: none;
    touch-action: none;
}

#pen-holder-hotspot:active {
    cursor: grabbing;
}

#pen-holder-image.shaking {
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% { transform: translate(var(--tx, 0), var(--ty, 0)) rotate(0deg); }
    25% { transform: translate(var(--tx, 0), var(--ty, 0)) rotate(-8deg); }
    75% { transform: translate(var(--tx, 0), var(--ty, 0)) rotate(8deg); }
}

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

.hotspot {
    position: absolute;
    cursor: pointer;
    border: none;
    background: transparent;
    animation: none;
}

.hotspot:hover {
    transform: none;
}

/* 调试模式样式 */
.debug-mode .hotspot {
    background: rgba(255, 0, 0, 0.3);
    border: 2px solid red;
    animation: none;
}

.debug-mode #pen-holder-hotspot {
    background: rgba(0, 255, 0, 0.5) !important;
    border: 3px solid lime !important;
}

.debug-mode .hotspot::after {
    content: attr(data-label);
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    background: red;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 1000;
}

#debug-toggle {
    position: absolute;
    top: 20px;
    left: 20px;
    width: auto;
    height: 40px;
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 20px;
    color: white;
    font-size: 14px;
    cursor: pointer;
    z-index: 1000;
    transition: all 0.3s ease;
}

#debug-toggle:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: scale(1.05);
}

.debug-mode #debug-toggle {
    background: rgba(255, 0, 0, 0.7);
    border-color: red;
}

/* 对话框 */
#dialog-box {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 400px;
    background: rgba(0, 0, 0, 0.85);
    border: 2px solid rgba(255, 215, 0, 0.5);
    border-radius: 15px;
    padding: 20px;
    padding-bottom: 35px;
    color: #fff;
    font-size: 16px;
    line-height: 1.8;
    z-index: 200;
    animation: slideUp 0.3s ease;
    cursor: default;
    touch-action: none;
    user-select: none;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

#dialog-continue {
    position: absolute;
    bottom: 8px;
    right: 15px;
    color: rgba(255, 255, 255, 0.4);
    font-size: 11px;
    pointer-events: none;
    animation: fadeInOut 2s ease-in-out infinite;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.6; }
}

/* 移动端优化 */
@media screen and (max-width: 768px) {
    body {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
        touch-action: none;
        overscroll-behavior: none;
    }
    
    #game-container {
        touch-action: none;
        overflow: hidden;
    }
    
    #room-image {
        touch-action: none;
    }
    
    .hotspot {
        touch-action: manipulation;
    }
    
    .title-text {
        font-size: 36px;
    }
    
    .subtitle {
        font-size: 16px;
    }
    
    .start-btn {
        padding: 15px 40px;
        font-size: 18px;
    }
    
    #dialog-box {
        font-size: 14px;
        padding: 15px;
        padding-bottom: 30px;
        bottom: 10px;
    }
    
    #inventory-toggle {
        width: 50px;
        height: 50px;
        font-size: 24px;
    }
    
    #inventory-panel {
        width: 200px;
        font-size: 13px;
    }
    
    .password-content {
        padding: 20px;
    }
    
    .password-content h3 {
        font-size: 20px;
    }
    
    #password-input {
        font-size: 20px;
    }
}

/* 防止iOS橡皮筋效果 */
body {
    overscroll-behavior: none;
}

/* 确保游戏元素不会覆盖对话框 */
#pen-holder-image,
#pen-image,
#cat-image {
    pointer-events: none;
}

#pen-holder-hotspot {
    pointer-events: auto;
}

/* 选项框 */
#choice-box {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 400px;
    background: rgba(0, 0, 0, 0.85);
    border: 2px solid rgba(255, 215, 0, 0.5);
    border-radius: 15px;
    padding: 20px;
    z-index: 200;
    animation: slideUp 0.3s ease;
}

#choice-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.choice-btn {
    padding: 15px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.choice-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.choice-btn:active {
    transform: translateY(0);
}

/* 物品栏 */
#inventory-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border: none;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(240, 147, 251, 0.5);
    transition: all 0.3s ease;
    z-index: 50;
    touch-action: none;
    user-select: none;
}

#inventory-toggle:hover {
    transform: scale(1.1);
}

#inventory-panel {
    position: absolute;
    top: 90px;
    right: 20px;
    width: 220px;
    background: rgba(0, 0, 0, 0.9);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 15px;
    padding: 15px;
    z-index: 50;
    animation: fadeInRight 0.3s ease;
    touch-action: none;
    user-select: none;
}

.inventory-header {
    color: #f093fb;
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 15px;
    text-align: center;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

#inventory-items {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.inventory-item {
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #ecf0f1;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s ease;
}

.inventory-item:hover {
    background: rgba(255, 255, 255, 0.2);
}

.item-icon {
    font-size: 24px;
}

/* 密码输入框 */
#password-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 300;
    animation: fadeIn 0.3s ease;
    touch-action: none;
    user-select: none;
}

.password-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    width: 90%;
    max-width: 350px;
}

.password-content h3 {
    color: white;
    margin-bottom: 20px;
    font-size: 24px;
}

#password-input {
    width: 100%;
    padding: 15px;
    font-size: 24px;
    text-align: center;
    border: none;
    border-radius: 10px;
    margin-bottom: 20px;
    letter-spacing: 10px;
    text-transform: uppercase;
}

.password-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.password-buttons button {
    padding: 12px 30px;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.password-buttons button:first-child {
    background: #fff;
    color: #667eea;
}

.password-buttons button:last-child {
    background: rgba(255, 255, 255, 0.3);
    color: white;
}

.password-buttons button:hover {
    transform: scale(1.05);
}

/* 结局画面 */
#ending-screen {
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, #1a1a2e 0%, #4a1a6b 50%, #1a1a2e 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    text-align: center;
    padding: 20px;
    animation: fadeIn 1s ease;
}

#ending-title {
    font-size: 48px;
    margin-bottom: 30px;
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.8);
}

#ending-text {
    font-size: 18px;
    line-height: 1.8;
    max-width: 400px;
    margin-bottom: 40px;
    color: rgba(255, 255, 255, 0.9);
}

/* Fallback场景 */
#fallback-scene {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(180deg, #2c3e50 0%, #34495e 100%);
    position: absolute;
    top: 0;
    left: 0;
}

.fallback-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
}

.instruction {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    margin-bottom: 20px;
    text-align: center;
}

.room-layout {
    flex: 1;
    width: 100%;
    position: relative;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 20px;
    border: 2px dashed rgba(255, 255, 255, 0.2);
}

.room-object {
    position: absolute;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 15px;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.room-object:hover {
    background: rgba(255, 255, 255, 0.2);
}

.room-object:active {
    background: rgba(255, 255, 255, 0.15);
}

.door {
    width: 60px;
    height: 120px;
    left: 5%;
    top: 50%;
    transform: translateY(-50%);
}

.window {
    width: 60px;
    height: 80px;
    right: 5%;
    top: 30%;
}

.clock {
    width: 70px;
    height: 70px;
    left: 50%;
    top: 15%;
    transform: translateX(-50%);
    border-radius: 50%;
}

.sofa {
    width: 120px;
    height: 80px;
    left: 30%;
    top: 65%;
}

.table {
    width: 100px;
    height: 70px;
    right: 10%;
    top: 70%;
}

.drawer {
    width: 60px;
    height: 50px;
    right: 25%;
    top: 50%;
}

.hidden {
    display: none !important;
}

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

@keyframes fadeInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes titlePulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}
