/* 纸上的魔法使 - Web版样式 */

:root {
    --game-width: 1280px;
    --game-height: 720px;
    --primary-color: #2a1a4a;
    --text-color: #f0e6d8;
    --accent-color: #8b5cf6;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    width: 100%;
    height: 100%;
}

body {
    background: #000;
    font-family: 'Microsoft YaHei', 'Hiragino Sans GB', sans-serif;
    overflow: hidden;
}

#game-container,
#game-container * {
    user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
}

#game-stage {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    overflow: hidden;
}

#game-scale {
    position: relative;
    width: var(--game-width);
    height: var(--game-height);
}

#game-container {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--game-width);
    height: var(--game-height);
    background: #1a0a2e;
    overflow: hidden;
    cursor: pointer;
    transform: scale(var(--game-scale, 1));
    transform-origin: top left;
}

.layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.hidden {
    display: none !important;
}

/* 背景层 */
#background-layer {
    z-index: 10;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* 背景淡入层 */
.background-fade {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* 立绘层 */
#character-layer {
    z-index: 50;
}

.character {
    position: absolute;
    bottom: 0;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease, left 0.3s ease;
}

.character.visible {
    opacity: 1;
}

.character[data-position="left"] {
    left: 100px;
}

.character[data-position="center"] {
    left: 50%;
    transform: translateX(-50%);
}

.character[data-position="right"] {
    right: 100px;
    left: auto;
}

/* 对话框层 */
#message-layer {
    z-index: 100;
    font-family: 'SimHei', '华文细黑', 'STXihei', 'Microsoft YaHei', 'Hiragino Sans GB', sans-serif;
}

#message-box {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    pointer-events: auto;
}

#message-bg {
    position: absolute;
    inset: 0;
    background-color: transparent;
    background-repeat: no-repeat;
    background-position: center bottom;
    background-size: 100% 100%;
    opacity: var(--message-window-opacity, 1);
    pointer-events: none;
}

#name-box {
    position: absolute;
    top: 527px;
    left: 182px;
    width: 350px;
    height: 100px;
    color: #514610;
    font-size: 24px;
    font-weight: 600;
    text-align: center;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 20px;
    opacity: 0;
    transition: opacity 0.2s ease;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}

#name-bg {
    position: absolute;
    inset: 0;
    background-color: transparent;
    background-repeat: no-repeat;
    background-position: center center;
    background-size: 100% 100%;
    opacity: var(--message-window-opacity, 1);
    pointer-events: none;
}

#name-text {
    position: relative;
    z-index: 1;
    width: 100%;
}

#name-box.visible {
    opacity: 1;
}

#text-box {
    position: absolute;
    left: 276px;
    top: 600px;
    width: 654px;
    color: #514610;
    font-size: 24px;
    line-height: 30px;
    font-weight: 600;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
    min-height: 112px;
}

#click-indicator {
    display: none;
}

#click-indicator.visible {
    opacity: 1;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(5px);
    }
}

/* 选择支层 */
#choice-layer {
    z-index: 150;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.6);
    pointer-events: auto;
}

.choice-button {
    width: 700px;
    margin: 10px 0;
    padding: 20px 40px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.3), rgba(109, 40, 217, 0.3));
    border: 2px solid var(--accent-color);
    color: var(--text-color);
    font-size: 22px;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 8px;
}

.choice-button:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.6), rgba(109, 40, 217, 0.6));
    transform: scale(1.02);
    box-shadow: 0 0 30px rgba(139, 92, 246, 0.5);
}

/* UI控制层 */
#ui-layer {
    z-index: 200;
    pointer-events: none;
}

#system-buttons {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease;
}

#game-container.ui-visible #system-buttons {
    opacity: 1;
    visibility: visible;
}

#game-container.overlay-active #system-buttons {
    opacity: 0;
    visibility: hidden;
}

.sys-btn {
    --btn-frame-width: 96px;
    --btn-frame-height: 26px;
    position: absolute;
    width: var(--btn-frame-width);
    height: var(--btn-frame-height);
    padding: 0;
    background: transparent;
    border: 0;
    background-repeat: no-repeat;
    background-position: 0 0;
    background-size: calc(var(--btn-frame-width) * 3) var(--btn-frame-height);
    color: transparent;
    font-size: 0;
    cursor: pointer;
    transition: filter 0.15s ease;
    pointer-events: auto;
}

.sys-btn:hover {
    background-position: calc(-1 * var(--btn-frame-width)) 0;
}

.sys-btn:active {
    background-position: calc(-2 * var(--btn-frame-width)) 0;
}

.sys-btn.active {
    background-position: calc(-2 * var(--btn-frame-width)) 0;
}

#btn-auto {
    left: 520px;
    top: 559px;
}

#btn-skip {
    left: 620px;
    top: 559px;
}

#btn-save {
    left: 720px;
    top: 559px;
}

#btn-load {
    left: 819px;
    top: 559px;
}

#btn-log {
    left: 919px;
    top: 559px;
}

#btn-config {
    left: 1019px;
    top: 559px;
}

#btn-win {
    left: 1094px;
    top: 598px;
    --btn-frame-width: 24px;
    --btn-frame-height: 24px;
}

/* 加载画面 */
#loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a0a2e, #2d1b4e);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.5s ease;
}

#loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

#loading-text {
    color: var(--text-color);
    font-size: 28px;
    margin-bottom: 30px;
    text-shadow: 0 0 20px var(--accent-color);
}

#loading-bar {
    width: 400px;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

#loading-progress {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color), #a78bfa);
    transition: width 0.3s ease;
}

/* 文字渐显效果 */
.char {
    opacity: 0;
    animation: fadeIn 0.05s forwards;
}

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

/* 响应式适配 */

/* Overlays */
.overlay {
    position: absolute;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    background-size: 100% 100%;
    background-position: center center;
}

.overlay.hidden {
    display: none;
}

#confirm-screen {
    z-index: 220;
    background: rgba(0, 0, 0, 0.35);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

#confirm-screen.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.title-menu {
    position: absolute;
    left: 991px;
    top: 188px;
    display: flex;
    flex-direction: column;
    gap: 22px;
    align-items: flex-start;
}

.title-btn {
    width: 230px;
    height: 30px;
    background-color: transparent;
    border: 0;
    background-repeat: no-repeat;
    background-position: 0 0;
    background-size: 300% 100%;
    cursor: pointer;
    filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.35));
    transition: transform 0.2s ease, filter 0.2s ease;
}

.title-btn:hover {
    background-position: 50% 0;
    filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.45)) brightness(1.05);
}

.title-btn:active {
    background-position: 100% 0;
    transform: translateY(1px);
}

.overlay-header {
    width: 100%;
    max-width: 980px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 30px 40px 10px;
    color: #f0e6d8;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

#save-load-screen .overlay-header,
#log-screen .overlay-header {
    position: absolute;
    top: 20px;
    right: 20px;
    width: auto;
    max-width: none;
    padding: 0;
    z-index: 2;
}

#save-load-screen .overlay-header {
    display: none;
}

#log-screen .overlay-header {
    top: auto;
    bottom: 8px;
    left: 0;
    right: 0;
    width: 100%;
    display: flex;
    justify-content: center;
}

#save-load-screen .overlay-title,
#log-screen .overlay-title {
    display: none;
}

#save-load-screen .overlay-close,
#log-screen .overlay-close {
    border: 0;
    background: transparent;
}

#log-screen .overlay-close {
    --log-close-width: 114px;
    --log-close-height: 30px;
    width: var(--log-close-width);
    height: var(--log-close-height);
    background-repeat: no-repeat;
    background-position: 0 0;
    background-size: calc(var(--log-close-width) * 3) var(--log-close-height);
    color: transparent;
    font-size: 0;
    cursor: pointer;
}

#log-screen .overlay-close:hover {
    background-position: calc(-1 * var(--log-close-width)) 0;
}

#log-screen .overlay-close:active {
    background-position: calc(-2 * var(--log-close-width)) 0;
}

.overlay-title {
    font-size: 24px;
    letter-spacing: 2px;
}

.overlay-close {
    width: 32px;
    height: 32px;
    border: 1px solid rgba(240, 230, 216, 0.5);
    background: rgba(20, 10, 40, 0.6);
    color: #f0e6d8;
    cursor: pointer;
}

.save-load-list {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.save-slot {
    --slot-frame-width: 208px;
    --slot-frame-height: 240px;
    position: absolute;
    width: var(--slot-frame-width);
    height: var(--slot-frame-height);
    --thumb-width: 170px;
    --thumb-height: 96px;
    background-size: calc(var(--slot-frame-width) * 3) var(--slot-frame-height);
    background-repeat: no-repeat;
    background-position: 0 0;
    border: 0;
    background-color: transparent;
    color: #514610;
    text-align: left;
    cursor: pointer;
    padding: 0;
    overflow: hidden;
}

.save-slot:hover {}

.save-slot:active {}

.save-slot-thumb {
    position: absolute;
    left: 19px;
    top: 16px;
    width: var(--thumb-width);
    height: var(--thumb-height);
    background-size: cover;
    background-position: center;
    pointer-events: none;
    filter: saturate(0) brightness(0.85);
    transition: filter 0.2s ease;
}

.save-slot:hover .save-slot-thumb {
    filter: saturate(1) brightness(1);
}

.save-slot-index {
    display: none;
}

.save-slot-meta {
    position: absolute;
    left: 22px;
    top: 146px;
    width: 164px;
    height: 80px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow: hidden;
}

.save-slot-hover {
    position: absolute;
    left: 19px;
    top: 16px;
    width: var(--thumb-width);
    height: var(--thumb-height);
    background-repeat: no-repeat;
    background-size: calc(var(--thumb-width) * 3) var(--thumb-height);
    background-position: 0 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.save-slot:hover .save-slot-hover {
    opacity: 1;
    background-position: calc(-1 * var(--thumb-width)) 0;
}

.save-slot:active .save-slot-hover {
    background-position: calc(-2 * var(--thumb-width)) 0;
}

.save-slot-title {
    font-size: 16px;
    font-weight: 600;
    line-height: 20px;
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
}

.save-slot-time {
    font-size: 14px;
    opacity: 0.9;
}

.save-load-pages {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
}

.save-load-page-btn {
    --page-frame-width: 46px;
    --page-frame-height: 46px;
    position: absolute;
    width: var(--page-frame-width);
    height: var(--page-frame-height);
    border: 0;
    background-color: transparent;
    background-repeat: no-repeat;
    background-size: calc(var(--page-frame-width) * 3) var(--page-frame-height);
    background-position: 0 0;
    cursor: pointer;
    pointer-events: auto;
}

.save-load-page-btn:hover {
    background-position: calc(-1 * var(--page-frame-width)) 0;
}

.save-load-page-btn:active {
    background-position: calc(-2 * var(--page-frame-width)) 0;
}

.save-load-actions {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
}

.save-action-btn {
    --action-frame-width: 114px;
    --action-frame-height: 30px;
    position: absolute;
    width: var(--action-frame-width);
    height: var(--action-frame-height);
    border: 0;
    background-color: transparent;
    background-repeat: no-repeat;
    background-size: calc(var(--action-frame-width) * 3) var(--action-frame-height);
    background-position: 0 0;
    cursor: pointer;
    pointer-events: auto;
}

.save-action-btn:hover {
    background-position: calc(-1 * var(--action-frame-width)) 0;
}

.save-action-btn:active {
    background-position: calc(-2 * var(--action-frame-width)) 0;
}

.confirm-dialog {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 574px;
    height: 175px;
    transform: translate(-50%, -50%) scale(0.98);
    background-repeat: no-repeat;
    background-size: 100% 100%;
    transition: transform 0.2s ease;
}

#confirm-screen.is-visible .confirm-dialog {
    transform: translate(-50%, -50%) scale(1);
}

.confirm-text {
    position: absolute;
    left: 0;
    top: 40px;
    width: 573px;
    height: 54px;
    text-align: center;
    font-size: 20px;
    font-weight: 600;
    color: #514610;
}

.confirm-btn {
    --confirm-frame-width: 164px;
    --confirm-frame-height: 38px;
    position: absolute;
    width: var(--confirm-frame-width);
    height: var(--confirm-frame-height);
    border: 0;
    background-color: transparent;
    background-repeat: no-repeat;
    background-size: calc(var(--confirm-frame-width) * 3) var(--confirm-frame-height);
    background-position: 0 0;
    cursor: pointer;
}

.confirm-btn:hover {
    background-position: calc(-1 * var(--confirm-frame-width)) 0;
}

.confirm-btn:active {
    background-position: calc(-2 * var(--confirm-frame-width)) 0;
}

.confirm-yes {
    left: 115px;
    top: 100px;
}

.confirm-no {
    left: 295px;
    top: 100px;
}

.log-entries {
    position: absolute;
    left: 120px;
    top: 120px;
    width: 1040px;
    height: 480px;
    overflow-y: auto;
    padding: 10px 0;
    background: transparent;
    border: 0;
    color: #514610;
    font-size: 20px;
}

.log-entry {
    padding-bottom: 12px;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(81, 70, 16, 0.25);
}

.log-name {
    font-weight: 600;
    color: #514610;
    margin-bottom: 4px;
}

.log-text {
    white-space: pre-wrap;
}

.log-empty {
    text-align: center;
    opacity: 0.7;
    padding: 40px 0;
}

.ui-toast {
    position: absolute;
    bottom: 30px;
    right: 40px;
    padding: 10px 16px;
    border: 1px solid rgba(240, 230, 216, 0.4);
    background: rgba(10, 5, 20, 0.7);
    color: #f0e6d8;
    z-index: 220;
}

.ui-toast.hidden {
    display: none;
}

/* Config */
#config-screen {
    background-repeat: no-repeat;
    background-position: center center;
    background-size: 100% 100%;
}

.config-page,
.config-tabs,
.config-actions {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.config-page.hidden {
    display: none;
}

.config-btn {
    --frame-width: 100px;
    --frame-height: 30px;
    position: absolute;
    width: var(--frame-width);
    height: var(--frame-height);
    padding: 0;
    border: 0;
    background-color: transparent;
    background-repeat: no-repeat;
    background-position: 0 0;
    background-size: calc(var(--frame-width) * 3) var(--frame-height);
    color: transparent;
    font-size: 0;
    cursor: pointer;
    pointer-events: auto;
}

.config-btn:hover {
    background-position: calc(-1 * var(--frame-width)) 0;
}

.config-btn:active {
    background-position: calc(-2 * var(--frame-width)) 0;
}

.config-btn.config-checkbox {
    background-position: 0 0;
}

.config-btn.config-checkbox:hover,
.config-btn.config-checkbox:active {
    background-position: 0 0;
    filter: none;
    transform: none;
}

.config-btn.config-skip,
.config-btn.config-window {
    transition: transform 0.12s ease, filter 0.12s ease;
}

.config-btn.config-skip:hover,
.config-btn.config-window:hover {
    background-position: 0 0;
    transform: translateY(-1px);
}

.config-btn.config-skip.is-selected:hover,
.config-btn.config-window.is-selected:hover {
    filter: none;
}

.config-btn.config-skip:not(.is-selected):hover,
.config-btn.config-window:not(.is-selected):hover {
    filter: brightness(1.08);
}

.config-btn.config-skip:active,
.config-btn.config-window:active {
    background-position: 0 0;
    transform: translateY(0);
}

.config-slider {
    --thumb-image: none;
    position: absolute;
    background: transparent;
    border: 0;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    pointer-events: auto;
    cursor: pointer;
}

.config-slider::-webkit-slider-runnable-track {
    height: 24px;
    background: transparent;
}

.config-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 23px;
    height: 23px;
    background-image: var(--thumb-image);
    background-repeat: no-repeat;
    background-size: 69px 23px;
    background-position: 0 0;
    border: 0;
    cursor: pointer;
}

.config-slider:hover::-webkit-slider-thumb {
    background-position: -23px 0;
}

.config-slider:active::-webkit-slider-thumb {
    background-position: -46px 0;
}

.config-slider::-moz-range-track {
    height: 24px;
    background: transparent;
    border: 0;
}

.config-slider::-moz-range-thumb {
    width: 23px;
    height: 23px;
    border: 0;
    background-color: transparent;
    background-image: var(--thumb-image);
    background-repeat: no-repeat;
    background-size: 69px 23px;
    background-position: 0 0;
    cursor: pointer;
}