/* 頁面結構：全域尺寸、排版與基礎色彩。 */
body {
    margin: 0;
    background: #d9c8ae;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    color: white;
    font-family: sans-serif;
    overflow: hidden;
}

#start-screen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background-color: #e4d5bb;
    background-image:
        radial-gradient(ellipse at 50% 42%, rgba(255, 249, 232, 0.78), transparent 42%),
        repeating-linear-gradient(90deg, rgba(92, 65, 42, 0.07) 0 1px, transparent 1px 74px),
        repeating-linear-gradient(0deg, rgba(92, 65, 42, 0.06) 0 1px, transparent 1px 74px),
        linear-gradient(135deg, #eadfc9 0%, #d7c2a1 100%);
    color: #493222;
}

#start-screen::before {
    position: absolute;
    inset: 7%;
    border: 1px solid rgba(84, 56, 34, 0.2);
    border-radius: 28px 8px 28px 8px;
    box-shadow: inset 0 0 0 8px rgba(255, 249, 232, 0.14);
    content: '';
    pointer-events: none;
}

.start-content {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 24px;
    text-align: center;
}

.start-kicker {
    margin: 0 0 12px;
    color: #557566;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 3px;
}

#start-screen h1 {
    margin: 0;
    color: #473022;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: clamp(3.5rem, 10vw, 7rem);
    line-height: 0.95;
    letter-spacing: 0;
    text-shadow: 0 4px 0 rgba(255, 249, 232, 0.7);
}

.start-subtitle {
    margin: 20px 0 30px;
    color: #795f48;
    font-size: clamp(15px, 2vw, 19px);
    letter-spacing: 0;
}

#start-btn {
    padding: 14px 38px;
    border: 2px solid #87543e;
    border-radius: 999px;
    background: #9a6247;
    color: white;
    font-size: 17px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 0 #704332, 0 14px 24px rgba(93, 57, 36, 0.2);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

#start-btn:hover {
    background: #ad7356;
    transform: translateY(-3px);
    box-shadow: 0 11px 0 #704332, 0 17px 28px rgba(93, 57, 36, 0.24);
}

#start-btn:active {
    transform: translateY(4px);
    box-shadow: 0 4px 0 #704332, 0 8px 16px rgba(93, 57, 36, 0.18);
}

.start-decoration {
    position: absolute;
    width: clamp(220px, 30vw, 390px);
    height: clamp(120px, 16vw, 210px);
    border: 1px solid rgba(84, 56, 34, 0.24);
    border-radius: 44% 12% 44% 12%;
    opacity: 0.82;
    filter: none;
    transform: rotate(-18deg);
}

.start-decoration-left {
    top: 6%;
    left: -8%;
    background:
        repeating-linear-gradient(90deg, rgba(255, 249, 232, 0.18) 0 2px, transparent 2px 22px),
        #9fb5a2;
    box-shadow: 48px 92px 0 -20px rgba(85, 117, 102, 0.28), inset 0 0 0 8px rgba(255, 249, 232, 0.12);
}

.start-decoration-right {
    right: -8%;
    bottom: 7%;
    background:
        repeating-linear-gradient(0deg, rgba(255, 249, 232, 0.16) 0 2px, transparent 2px 22px),
        #c99568;
    border-radius: 12% 44% 12% 44%;
    box-shadow: -56px -76px 0 -26px rgba(154, 98, 71, 0.24), inset 0 0 0 8px rgba(255, 249, 232, 0.12);
    transform: rotate(18deg);
}

/* 起始畫面右下角的支援與語言控制列。 */
.start-controls {
    position: absolute;
    right: 28px;
    bottom: 24px;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 8px;
}

.coffee-link,
.language-picker {
    padding: 8px 10px;
    border: 1px solid rgba(84, 56, 34, 0.24);
    border-radius: 8px;
    background: rgba(255, 249, 232, 0.72);
    color: #60432e;
    font-size: 12px;
    font-weight: 800;
    text-decoration: none;
    box-shadow: 0 4px 14px rgba(82, 54, 32, 0.1);
}

.coffee-link {
    transition: background-color 160ms ease, transform 160ms ease;
}

.coffee-link:hover,
.coffee-link:focus-visible {
    background: #f7ecd7;
    transform: translateY(-1px);
}

.language-picker {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 800;
}

.language-picker select {
    padding: 4px 6px;
    border: 1px solid rgba(84, 56, 34, 0.25);
    border-radius: 5px;
    background: #f7ecd7;
    color: #493222;
    font: inherit;
}

/* 響應式：小螢幕起始畫面的文字與間距。 */
@media (max-width: 520px) {
    .start-kicker {
        letter-spacing: 2px;
    }

    .start-subtitle {
        max-width: 230px;
        line-height: 1.6;
    }
}

/* 主要 UI 區域：遊戲背景、三欄版面與場景裝飾。 */
/* 左側角色、中央遊戲、右側預留功能區 */
#game-layout {
    position: relative;
    isolation: isolate;
    display: flex;
    /* 內部使用固定設計尺寸，實際顯示由 main.js 等比縮放整個框架。 */
    width: 1280px;
    height: 720px;
    aspect-ratio: 16 / 9;
    position: absolute;
    top: 50%;
    left: 50%;
    margin: 0;
    transform: translate(-50%, -50%) scale(var(--game-scale, 1));
    transform-origin: center center;
    overflow: hidden;
    background-color: #d2bea0;
    background-image:
        radial-gradient(ellipse at 50% 18%, rgba(255, 248, 226, 0.82), transparent 34%),
        radial-gradient(ellipse at 8% 78%, rgba(119, 145, 125, 0.2), transparent 24%),
        radial-gradient(ellipse at 92% 62%, rgba(185, 126, 62, 0.16), transparent 25%),
        repeating-linear-gradient(90deg, rgba(92, 59, 35, 0.08) 0 2px, transparent 2px 86px),
        repeating-linear-gradient(0deg, rgba(111, 76, 47, 0.1) 0 2px, transparent 2px 116px),
        linear-gradient(180deg, #eadcc3 0%, #c5ad8d 100%);
    background-position: center, center, center, center, center, center;
    background-size: cover, cover, cover, cover, auto, cover;
    background-repeat: no-repeat;
}

#game-layout::before {
    position: absolute;
    inset: 0;
    z-index: 0;
    background:
        linear-gradient(90deg, transparent 0 24%, rgba(73, 45, 26, 0.14) 24% 24.4%, transparent 24.4% 75.5%, rgba(73, 45, 26, 0.14) 75.5% 75.9%, transparent 75.9%),
        repeating-linear-gradient(0deg, transparent 0 116px, rgba(91, 57, 34, 0.16) 116px 121px, rgba(255, 248, 226, 0.3) 121px 125px, transparent 125px 238px),
        repeating-linear-gradient(90deg, rgba(111, 76, 47, 0.06) 0 2px, transparent 2px 104px),
        linear-gradient(180deg, rgba(255, 248, 226, 0.2), transparent 22%, transparent 78%, rgba(84, 52, 31, 0.14));
    content: '';
    pointer-events: none;
}

#game-layout::after {
    position: absolute;
    top: 7%;
    left: 4%;
    width: 18%;
    height: 24%;
    border: 5px solid rgba(83, 51, 29, 0.5);
    border-bottom-width: 12px;
    background:
        linear-gradient(140deg, rgba(255, 248, 226, 0.55), transparent 52%),
        repeating-linear-gradient(0deg, #9c7046 0 13px, #d7b783 13px 17px, #725033 17px 28px);
    box-shadow: 0 0 0 3px rgba(148, 101, 54, 0.18), 0 18px 30px rgba(64, 38, 20, 0.2);
    content: '';
    z-index: 0;
    opacity: 0.92;
    pointer-events: none;
}

.scene-accent {
    position: absolute !important;
    left: 0;
    z-index: 0 !important;
    width: 100%;
    height: 10px;
    border-top: 2px solid rgba(109, 75, 46, 0.5);
    border-bottom: 2px solid rgba(109, 75, 46, 0.28);
    background: repeating-linear-gradient(90deg, #b18451 0 88px, #718e7a 88px 104px, #d7b783 104px 148px, #9a6b3e 148px 184px);
    box-shadow: 0 0 18px rgba(109, 75, 46, 0.12);
    opacity: 0.9;
    pointer-events: none;
}

.scene-accent-top {
    top: 0;
}

.scene-accent-bottom {
    bottom: 0;
}

/* 主要 UI 區域：遊戲內選單與操作按鈕。 */
.game-menu {
    position: absolute;
    top: 18px;
    right: 22px;
    z-index: 5;
    color: white;
}

.game-menu summary {
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 5px;
    background: rgba(25, 25, 25, 0.72);
    cursor: pointer;
    font-size: 13px;
    list-style: none;
}

.game-menu summary::-webkit-details-marker {
    display: none;
}

.game-menu-options {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 170px;
    padding: 8px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 6px;
    background: #252525;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
}

#return-to-title {
    width: 100%;
    padding: 8px 10px;
    border: 0;
    background: transparent;
    color: white;
    cursor: pointer;
    text-align: left;
}

#continue-game {
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: 4px;
    background: #2c9b70;
    color: white;
    cursor: pointer;
    font-weight: 800;
    text-align: left;
}

#continue-game:hover {
    background: #35a97b;
}

#return-to-title:hover {
    background: rgba(255, 255, 255, 0.12);
}

#settle-round {
    width: 100%;
    margin-top: 8px;
    padding: 9px 10px;
    border: 1px solid rgba(232, 185, 92, 0.55);
    border-radius: 4px;
    background: rgba(217, 151, 43, 0.16);
    color: #ffe5a3;
    cursor: pointer;
    text-align: left;
}

#settle-round:hover {
    background: rgba(217, 151, 43, 0.28);
}

/* 主要 UI 區域：關卡選擇畫面、標題與卡片清單。 */
#level-select-screen {
    position: fixed;
    inset: 0;
    z-index: 9998;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-sizing: border-box;
    background-image:
        radial-gradient(ellipse at 50% 26%, rgba(255, 248, 226, 0.72), transparent 38%),
        radial-gradient(ellipse at 8% 80%, rgba(119, 145, 125, 0.22), transparent 24%),
        radial-gradient(ellipse at 92% 72%, rgba(194, 136, 71, 0.18), transparent 25%),
        repeating-linear-gradient(90deg, rgba(91, 57, 34, 0.08) 0 2px, transparent 2px 92px),
        repeating-linear-gradient(0deg, rgba(91, 57, 34, 0.08) 0 2px, transparent 2px 118px),
        linear-gradient(145deg, #eadcc3 0%, #b99b73 100%);
    background-position: center, center, center, center, center, center;
    background-size: cover, cover, cover, cover, auto, cover;
    background-attachment: fixed;
}

#level-select-canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--level-screen-gap, 26px);
    width: 1280px;
    height: 720px;
    overflow: hidden;
    padding: var(--level-screen-padding, 42px 24px);
    box-sizing: border-box;
    transform: translate(-50%, -50%) scale(var(--level-select-scale, 1));
    transform-origin: center center;
}

#level-gemop {
    position: absolute;
    top: var(--level-gemop-top, 22px);
    left: var(--level-gemop-left, 26px);
    z-index: 2;
    padding: 9px 14px;
    border: 1px solid rgba(101, 68, 46, 0.3);
    border-radius: 999px;
    background: rgba(255, 248, 232, 0.76);
    color: #60432e;
    font-size: 14px;
    font-weight: 800;
    box-shadow: 0 4px 14px rgba(82, 54, 32, 0.12);
}

#level-select-screen::before,
#level-select-screen::after {
    position: absolute;
    z-index: 0;
    content: '';
    pointer-events: none;
}

#level-select-screen::before {
    inset: 0;
    background:
        linear-gradient(90deg, rgba(111, 76, 47, 0.12) 0 12%, transparent 12% 88%, rgba(111, 76, 47, 0.12) 88% 100%),
        repeating-linear-gradient(0deg, transparent 0 118px, rgba(91, 57, 34, 0.12) 118px 122px, rgba(255, 248, 226, 0.38) 122px 126px, transparent 126px 240px),
        repeating-linear-gradient(90deg, transparent 0 78px, rgba(111, 76, 47, 0.09) 78px 80px, transparent 80px 156px);
    opacity: 0.62;
}

#level-select-screen::after {
    display: none;
}

#level-select-screen > *,
#game-layout > * {
    position: relative;
    z-index: 1;
}

#level-select-screen > #level-select-canvas {
    position: absolute;
    z-index: 1;
}

#level-select-canvas > #level-gemop {
    position: absolute;
    top: 22px;
    left: 26px;
    z-index: 2;
}

#game-layout > .game-menu {
    position: absolute;
    z-index: 5;
}

.scene-bookshelf {
    position: fixed !important;
    top: 24%;
    z-index: 0 !important;
    width: clamp(126px, 14vw, 190px);
    height: 52%;
    border: 7px solid #28130a;
    border-top-width: 12px;
    border-bottom-width: 14px;
    background:
        repeating-linear-gradient(0deg, transparent 0 70px, rgba(239, 174, 88, 0.22) 70px 76px),
        repeating-linear-gradient(90deg, #876343 0 15px, #b98d5e 15px 30px, #68472f 30px 45px, #d2b27c 45px 54px, #5a3b28 54px 70px);
    box-shadow: 0 0 0 3px rgba(229, 158, 74, 0.2), 0 24px 30px rgba(9, 4, 2, 0.4);
}

.scene-bookshelf-left {
    left: clamp(18px, 8vw, 140px);
}

.scene-bookshelf-right {
    right: clamp(18px, 8vw, 140px);
}

.scene-wall-light {
    position: absolute !important;
    top: 8%;
    left: 50%;
    z-index: 0 !important;
    width: 150px;
    height: 26px;
    border: 5px solid #31170b;
    border-radius: 50%;
    background: #f6c66e;
    box-shadow: 0 0 20px 8px rgba(246, 198, 110, 0.3), 0 0 70px 20px rgba(246, 173, 72, 0.12);
    transform: translateX(-50%);
    pointer-events: none;
}

.level-select-heading {
    position: relative;
    text-align: center;
}

.level-select-heading::before,
.level-select-heading::after {
    position: absolute;
    top: 150px;
    width: 160px;
    height: 390px;
    border: 5px solid rgba(27, 12, 7, 0.7);
    border-top-width: 9px;
    border-bottom-width: 11px;
    background:
        linear-gradient(90deg, rgba(16, 8, 4, 0.4) 0 10%, transparent 10% 90%, rgba(16, 8, 4, 0.4) 90%),
        repeating-linear-gradient(0deg, rgba(225, 159, 77, 0.14) 0 4px, transparent 4px 68px),
        repeating-linear-gradient(90deg, #285249 0 17px, #9b5b2f 17px 31px, #6e3d24 31px 45px, #bc7c39 45px 53px, #332018 53px 69px);
    box-shadow: 0 0 0 3px rgba(214, 141, 61, 0.15), 0 22px 32px rgba(9, 4, 2, 0.32);
    content: '';
    opacity: 0.92;
    pointer-events: none;
}

.level-select-heading::before {
    right: calc(50% + 330px);
}

.level-select-heading::after {
    left: calc(50% + 330px);
}

.level-select-kicker {
    margin: 0 0 10px;
    color: #557566;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 3px;
    text-shadow: 0 1px 0 rgba(255, 248, 232, 0.65);
}

.level-select-heading h1 {
    margin: 0;
    color: #493222;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 54px;
    letter-spacing: 0;
}

.level-select-heading p:last-child {
    margin: 10px 0 0;
    color: #795f48;
    font-size: 14px;
}

#level-list-container {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: stretch;
    gap: var(--level-list-gap, 24px);
    width: var(--level-list-width, 920px);
    min-height: 0;
    height: 560px;
    padding: 0;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: hidden;
}

.level-card {
    display: flex;
    flex-direction: column;
    width: var(--level-card-width, 360px);
    min-height: var(--level-card-min-height, 560px);
    overflow: hidden;
    border: 1px solid rgba(255, 210, 140, 0.3);
    border-radius: 8px;
    background: #302017;
    box-shadow: 0 24px 50px rgba(0, 0, 0, 0.46), 0 0 0 5px rgba(42, 21, 12, 0.28);
}

.level-select-button {
    flex: 0 1 360px;
    padding: 0;
    border: 0;
    background: transparent;
    color: white;
    cursor: pointer;
    text-align: left;
    transition: transform 0.2s ease, filter 0.2s ease;
}

.level-select-button:hover,
.level-select-button:focus-visible {
    transform: translateY(-8px);
    filter: brightness(1.08);
    outline: none;
}

.level-card-visual {
    position: relative;
    height: var(--level-card-visual-height, 310px);
    overflow: hidden;
    background:
        linear-gradient(150deg, rgba(57, 26, 14, 0.1), rgba(57, 26, 14, 0.5)),
        repeating-linear-gradient(90deg, #9b5b31 0 10px, #824522 10px 14px, #a8683b 14px 28px);
}

.level-card-visual::after {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(18, 32, 31, 0.05), rgba(18, 32, 31, 0.5));
    content: '';
}

.level-card-glow {
    position: absolute;
    top: 48px;
    left: 50%;
    width: 220px;
    height: 220px;
    border-radius: 50%;
    background: rgba(255, 244, 188, 0.45);
    filter: blur(24px);
    transform: translateX(-50%);
}

.level-card-body,
.level-card-face {
    position: absolute;
    z-index: 2;
    top: var(--level-character-top, 120%);
    left: 50%;
    width: var(--level-character-width, 130%);
    max-width: none;
    height: auto;
    pointer-events: none;
    transform: translate(-50%, -50%);
}

.level-card-face {
    z-index: 1;
}

.level-card-number,
.level-card-status {
    position: absolute;
    z-index: 3;
    top: 18px;
    color: rgba(255, 255, 255, 0.82);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 2px;
}

.level-card-number {
    left: 20px;
    font-size: 18px;
}

.level-card-status {
    right: 20px;
    color: #fff2be;
}

.level-card-content {
    display: flex;
    flex: 1;
    flex-direction: column;
    padding: 22px 24px 20px;
    background:
        linear-gradient(rgba(56, 31, 19, 0.9), rgba(40, 23, 15, 0.98)),
        repeating-linear-gradient(0deg, rgba(255, 195, 119, 0.06) 0 1px, transparent 1px 7px);
}

.level-card-label {
    margin: 0 0 8px;
    color: #e8b95c;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 2px;
}

.level-card-content h2 {
    margin: 0;
    color: #fff5d6;
    font-size: 26px;
}

.level-card-description {
    min-height: 42px;
    margin: 10px 0 18px;
    color: rgba(255, 255, 255, 0.62);
    font-size: 13px;
    line-height: 1.6;
}

.level-card-stats {
    display: flex;
    gap: 20px;
    padding: 12px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.58);
    font-size: 12px;
}

.level-card-stats strong {
    color: #fff5d6;
    font-size: 16px;
}

.level-card-cta {
    display: flex;
    justify-content: space-between;
    margin-top: auto;
    padding-top: 18px;
    color: #ffe5a3;
    font-size: 14px;
    font-weight: 800;
}

.level-card-cta b {
    font-size: 20px;
    line-height: 12px;
}

/* 選擇畫面使用固定設計畫布，視窗只縮放整體畫布。 */
@media (max-height: 650px) {
    #level-select-screen { overflow: hidden; }
}

/* 選擇畫布不因手機寬度重新排列物件。 */
@media (max-width: 520px) {
    #level-select-screen { overflow: hidden; }
}

/* 角色區共用結構：第一關的實際大小與位置請到 level1.css 調整。 */
#character-panel {
    flex: 1 1 40%;
    min-width: 0;
    background: transparent;
    border-right: none;
    padding: 20px;
    position: relative;
    display: flex;
    flex-direction: column;
}

#character-panel h2 {
    font-size: 18px;
    border-bottom: none;
    padding-bottom: 10px;
    margin-top: 0;
}

/* 左側 1/3 角色區容器 */
#character-container {
    flex: 1;
    background: transparent;
    border-radius: 0;
    position: relative; /* 關鍵：讓內部絕對定位的圖層以這裡為基準 */
    overflow: visible;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 對話框共用外觀與動畫；各關卡可在自己的 CSS 覆寫尺寸。 */
.character-dialogue {
    position: absolute;
    top: 5%;
    right: 0%;
    width: min(260px, calc(100% - 16px));
    max-height: 32%;
    box-sizing: border-box;
    z-index: 5;
    padding: 10px 14px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 14px;
    background: rgba(20, 24, 42, 0.88);
    color: #fff;
    box-shadow: 0 5px 16px rgba(0, 0, 0, 0.25);
    text-align: center;
    overflow-y: auto;
    overflow-wrap: anywhere;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 180ms ease, transform 180ms ease;
    pointer-events: none;
}

.character-dialogue:not([hidden]) {
    opacity: 1;
    transform: translateY(0);
}

.character-dialogue p {
    margin: 0;
    font-size: 18px;
    line-height: 1.5;
}

/* 動畫：角色各圖層的呼吸起伏效果。 */
.character-part-motion {
    position: absolute;
    inset: 0;
    z-index: 0;
    animation: character-part-breath var(--breath-duration, 5s) ease-in-out infinite;
    transform-origin: var(--breath-origin, 50% 58%);
    backface-visibility: hidden;
    perspective: 1000px;
    will-change: transform;
}

@keyframes character-part-breath {
    0%,
    100% {
        transform: translate3d(0, 0, 0) scale3d(1, 1, 1);
    }
    45% {
        transform:
            translate3d(0, calc(var(--breath-y, 2px) * -1), 0)
            scale3d(var(--breath-scale-x, 1), var(--breath-scale-y, 1.006), 1);
    }
    60% {
        transform:
            translate3d(0, calc(var(--breath-y, 2px) * -0.7), 0)
            scale3d(
                calc(1 + (var(--breath-scale-x, 1) - 1) * 0.7),
                calc(1 + (var(--breath-scale-y, 1.006) - 1) * 0.7),
                1
            );
    }
}
@media (prefers-reduced-motion: reduce) {
    .character-part-motion {
        animation: none;
    }
}

/* 角色分層圖層通用樣式 */
.char-layer {
    position: absolute; /* 關鍵：讓所有圖層重疊在同一位置 */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); /* 置中對齊 */
    width: 130%;
    max-width: none;
    max-height: none;
    object-fit: contain;
    pointer-events: none; /* 避免圖層擋住滑鼠點擊事件 */
}

/* 主要 UI 區域：中央遊戲畫面與右側任務欄。 */
/* 中央遊戲主畫面 */
#main-game-panel {
    flex: 2 1 50%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: transparent;
}

#future-panel {
    flex: 1 1 25%;
    min-width: 0;
    padding: 24px clamp(12px, 2vw, 28px);
    box-sizing: border-box;
    background: transparent;
    border-left: 1px solid rgba(255, 207, 137, 0.2);
    overflow-y: auto;
}

/* 彈窗與表單：結算、操作確認及其按鈕。 */
.settlement-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.68);
}

.settlement-modal[hidden] {
    display: none;
}

.settlement-dialog {
    width: min(360px, 100%);
    padding: 28px 24px;
    border: 2px solid #e8b95c;
    border-radius: 10px;
    background: #252525;
    color: white;
    text-align: center;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}

.settlement-dialog h2 {
    margin: 0 0 14px;
    color: #ffe5a3;
    font-size: 24px;
}

.settlement-dialog p {
    margin: 0 0 22px;
    font-size: 18px;
}

#settlement-continue {
    padding: 10px 24px;
    border: 1px solid #e8b95c;
    border-radius: 5px;
    background: #d9972b;
    color: #241d0d;
    font-weight: 800;
    cursor: pointer;
}

.confirm-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.confirm-actions button {
    min-width: 90px;
    padding: 10px 16px;
    border: 1px solid #e8b95c;
    border-radius: 5px;
    background: #d9972b;
    color: #241d0d;
    font-weight: 800;
    cursor: pointer;
}

.confirm-actions #action-cancel {
    border-color: rgba(255, 255, 255, 0.25);
    background: transparent;
    color: white;
}

/* 任務區：標題、任務內容與完成按鈕。 */
.task-panel-header {
    margin-bottom: 16px;
}

.task-panel-header h2 {
    margin: 0 0 4px;
    color: #65442e;
    font-size: 22px;
}

.task-panel-header span {
    color: #795f48;
    font-size: 12px;
}

#task-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#level2-recipe-dex {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    margin: 28px auto 8px;
}

.level2-recipe-ring {
    position: relative;
    width: 220px;
    height: 220px;
    border: 1px solid rgba(101, 68, 46, 0.28);
    border-radius: 50%;
    background: rgba(255, 248, 232, 0.22);
}

.level2-recipe-item {
    position: absolute;
    top: 50%;
    left: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 58px;
    color: #a8c9f0;
    padding: 0;
    border: 0;
    background: transparent;
    font-size: 10px;
    text-align: center;
    cursor: pointer;
    transform: translate(-50%, -50%) rotate(var(--recipe-angle)) translateY(-82px) rotate(calc(var(--recipe-angle) * -1));
}

.level2-recipe-arrow {
    position: absolute;
    z-index: 0;
    height: 2px;
    transform-origin: left center;
    background: #b66d43;
    opacity: 0.78;
    pointer-events: none;
}

.level2-recipe-arrow::after {
    position: absolute;
    top: 50%;
    right: -1px;
    width: 8px;
    height: 8px;
    border-top: 2px solid #6678c9;
    border-right: 2px solid #6678c9;
    content: '';
    transform: translateY(-50%) rotate(45deg);
}

.level2-recipe-item:not(.recipe-active) {
    filter: grayscale(1) opacity(0.45);
    cursor: not-allowed;
}

.level2-recipe-item.recipe-unlocked {
    filter: none;
}

.level2-ring-two .level2-recipe-item:not(.recipe-active) {
    filter: grayscale(1) opacity(0.45);
}

.level2-ring-two .level2-recipe-item.recipe-active {
    filter: none;
}

.level2-ring-two .level2-recipe-item.recipe-discovered,
.level2-ring-two .level2-recipe-item.recipe-used {
    filter: none;
}

.level2-recipe-item.recipe-ready .level2-recipe-circle {
    border-color: #ffd34e;
    box-shadow:
        0 0 0 5px rgba(255, 211, 78, 0.28),
        0 0 24px rgba(255, 211, 78, 0.9);
}

.level2-recipe-item.recipe-used .level2-recipe-circle,
#game-layout.level-2 .level2-recipe-item[data-skill-used="true"] .level2-recipe-circle {
    position: relative;
    z-index: 2;
    border-color: #73d66f;
    box-shadow:
        0 0 0 4px rgba(115, 214, 111, 0.4),
        0 0 26px rgba(115, 214, 111, 1);
}

#game-layout.level-2 .level2-recipe-center.recipe-used.recipe-ready .level2-recipe-circle {
    border-color: #73d66f;
    box-shadow:
        0 0 0 4px rgba(115, 214, 111, 0.45),
        0 0 0 9px rgba(255, 211, 78, 0.38),
        0 0 30px rgba(255, 211, 78, 1),
        0 0 42px rgba(115, 214, 111, 0.8);
}

.level2-recipe-center {
    transform: translate(-50%, -50%);
}

.level2-recipe-item:focus-visible {
    outline: 2px solid #594c70;
    outline-offset: 4px;
}

.level2-recipe-ring .level2-recipe-item:nth-of-type(1) { --recipe-angle: 0deg; }
.level2-recipe-ring .level2-recipe-item:nth-of-type(2) { --recipe-angle: 72deg; }
.level2-recipe-ring .level2-recipe-item:nth-of-type(3) { --recipe-angle: 144deg; }
.level2-recipe-ring .level2-recipe-item:nth-of-type(4) { --recipe-angle: 216deg; }
.level2-recipe-ring .level2-recipe-item:nth-of-type(5) { --recipe-angle: 288deg; }

.level2-ring-two .level2-recipe-item:nth-of-type(1) { --recipe-angle: 36deg; }
.level2-ring-two .level2-recipe-item:nth-of-type(2) { --recipe-angle: 108deg; }
.level2-ring-two .level2-recipe-item:nth-of-type(3) { --recipe-angle: 180deg; }
.level2-ring-two .level2-recipe-item:nth-of-type(4) { --recipe-angle: 252deg; }
.level2-ring-two .level2-recipe-item:nth-of-type(5) { --recipe-angle: 324deg; }

.level2-panel .task-panel-header,
.level2-panel #task-list {
    display: none;
}

.level2-recipe-circle {
    width: 42px;
    height: 42px;
    margin-bottom: 4px;
    border: 2px solid rgba(123, 93, 206, 0.42);
    border-radius: 50%;
    background-color: rgba(255, 248, 232, 0.68);
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
    box-shadow: 0 2px 5px rgba(70, 43, 26, 0.2);
}

.level2-recipe-name {
    white-space: nowrap;
}

.task-empty {
    padding: 18px 12px;
    border: 1px dashed rgba(101, 68, 46, 0.38);
    border-radius: 8px;
    background: rgba(255, 248, 232, 0.26);
    color: #6f563f;
    font-size: 13px;
    line-height: 1.5;
    text-align: center;
}

.task-item {
    padding: 14px;
    border: 1px solid rgba(101, 68, 46, 0.24);
    border-radius: 8px;
    background: rgba(255, 248, 232, 0.4);
}

.task-item-title {
    margin-bottom: 10px;
    color: #60432e;
    font-size: 12px;
    font-weight: 700;
}

.task-fruits {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 14px;
}

.task-fruit {
    display: flex;
    align-items: center;
    justify-content: center;
}

.task-fruit-dot {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border: 1px solid rgba(101, 68, 46, 0.42);
    border-radius: 50%;
    background-color: rgba(255, 248, 232, 0.56);
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
    box-shadow: 0 1px 3px rgba(70, 43, 26, 0.18);
}

.task-complete-button {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #e8b95c;
    border-radius: 5px;
    background: #b66d43;
    color: #241d0d;
    font-weight: 800;
    cursor: pointer;
}

.task-complete-button:disabled {
    border-color: rgba(101, 68, 46, 0.3);
    background: #cdb99a;
    color: #6c5038;
    cursor: not-allowed;
}

h1 { margin-bottom: 3px; font-size: 20px; }

/* 遊戲資訊：分數、下一個角色、進化進度與棋盤。 */
#info-panel { 
    display: flex; 
    gap: 15px; 
    margin-bottom: 6px; 
    font-size: 14px; 
    align-items: center; 
    background: #333;
    padding: 4px 10px;
    border-radius: 6px;
    transform: translateX(-100px);
}

#next-preview {
    display: inline-flex;
    align-items: center;
    gap: 5px;
        transform: translateX(5px);
}

.test-fruit-picker {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.test-fruit-picker[hidden] {
    display: none;
}

#test-fruit-select {
    max-width: 150px;
    padding: 3px 5px;
    border: 1px solid rgba(255, 250, 235, 0.72);
    border-radius: 4px;
    background: rgba(255, 250, 235, 0.92);
    color: #493222;
    font: inherit;
}

.game-stage {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* 進度：以直向填充條呈現角色進化累積值。 */
#evolution-progress {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 34px;
    color: #493222;
    font-size: 10px;
    font-weight: 800;
}

#evolution-progress[hidden] {
    display: none;
}

#evolution-progress-max {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    white-space: nowrap;
    font-size: 9px;
    opacity: 0.58;
}

.evolution-progress-track {
    position: relative;
    width: 16px;
    height: 33vh;
    overflow: hidden;
    border: 2px solid rgba(73, 50, 34, 0.72);
    border-radius: 10px;
    background: rgba(255, 249, 232, 0.58);
    box-shadow: inset 0 1px 4px rgba(73, 50, 34, 0.25), 0 3px 8px rgba(73, 50, 34, 0.16);
}

#evolution-progress-fill {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    height: 0;
    border-radius: 7px;
    background: linear-gradient(0deg, #c46d3b, #e4b84f);
    transition: height 0.25s ease-out;
}

#evolution-progress-value {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    white-space: nowrap;
}

/* 動畫：角色進化時短暫顯示的全畫面閃光。 */
#evolution-flash {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: #fff;
    opacity: 0;
    pointer-events: none;
}

#next-image {
    display: inline-block;
    width: 28px;
    height: 28px;
    border: 1px solid rgba(255, 250, 235, 0.72);
    border-radius: 50%;
    background-repeat: no-repeat;
    background-size: contain;
    background-position: center;
    box-shadow: 0 1px 4px rgba(36, 24, 17, 0.3);
}

canvas {
    width: min(520px, 48vw, calc((100vh - 150px) * 2 / 3));
    height: auto;
    aspect-ratio: 2 / 3;
    max-width: calc(100vw - 80px);
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.22), transparent 25%, transparent 72%, rgba(91, 111, 105, 0.16)),
        linear-gradient(180deg, rgba(222, 232, 224, 0.48), rgba(126, 145, 140, 0.58));
    border: 6px solid rgba(255, 250, 235, 0.74);
    border-radius: 20px;
    box-shadow:
        inset 0 0 0 2px rgba(82, 103, 96, 0.42),
        inset 0 12px 22px rgba(255, 255, 255, 0.18),
        0 0 0 1px rgba(72, 88, 80, 0.5),
        0 16px 32px rgba(72, 47, 29, 0.28);
    backdrop-filter: blur(2px);
    cursor: crosshair;
}

/* 響應式：窄螢幕將三欄版面改為上下排列。 */
@media (max-width: 700px) {
    #game-layout {
        flex-direction: column;
        overflow: auto;
    }

    #character-panel {
        flex: 0 0 180px;
        min-height: 180px;
    }

    #future-panel {
        flex: 0 0 auto;
        width: 100%;
        max-height: 280px;
        padding: 12px 16px;
        border-top: 1px solid rgba(255, 255, 255, 0.12);
        border-left: none;
    }

    #main-game-panel {
        flex: 1;
        min-height: 0;
        padding: 8px 0 16px;
    }

    .game-stage {
        max-width: calc(100vw - 24px);
    }

    canvas {
        width: min(400px, 86vw, calc((100vh - 300px) * 2 / 3));
        max-width: calc(100vw - 24px);
    }
}

/* 底部圖鑑解鎖欄樣式 */
#dex-container {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    width: min(520px, calc(100vw - 24px));
    box-sizing: border-box;
    background: rgba(71, 49, 35, 0.82);
    padding: 8px 12px;
    border-radius: 8px;
    max-width: min(520px, calc(100vw - 24px));
    justify-content: center;
    overflow: hidden;
}

.dex-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 11px;
    color: #777;
    width: auto;
    min-width: 0;
    flex: 1 1 0;
    line-height: 1.2;
    text-align: center;
}

.dex-circle {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-color: #6c6459;
    background-repeat: no-repeat;
    background-size: contain;
    background-position: center;
    border: 2px dashed #666;
    margin-bottom: 3px;
    filter: grayscale(1) opacity(0.46);
}

.dex-item.unlocked .dex-circle {
    filter: none;
}

#game-layout::after,
#character-panel::before,
#future-panel::after {
    display: none;
}

.level-select-heading::before,
.level-select-heading::after {
    display: none;
}

.dex-item.unlocked {
    color: #fff;
}

.dex-item.unlocked .dex-circle {
    border: 2px solid #222;
}

#character-panel::before,
#future-panel::after {
    position: absolute;
    top: 78px;
    width: 12px;
    height: 52%;
    border: 3px solid rgba(22, 10, 5, 0.72);
    background: repeating-linear-gradient(0deg, #a96a37 0 8px, #3b2116 8px 13px, #477064 13px 27px, #6f3d23 27px 42px);
    box-shadow: 0 0 0 3px rgba(224, 157, 78, 0.15);
    content: '';
    opacity: 0.9;
    pointer-events: none;
}

#character-panel::before {
    left: 14px;
}

#future-panel::after {
    right: 14px;
}

/* 橫向手機：維持三欄遊戲編排，畫布以固定 2:3 比例縮放。 */
@media (orientation: landscape) and (max-height: 700px) {
    #game-layout {
        display: grid !important;
        grid-template-columns: 28% 44% 28%;
        grid-template-rows: 100%;
        width: 100vw;
        height: 100vh;
        min-width: 0;
        overflow: hidden;
    }

    #character-panel,
    #main-game-panel,
    #future-panel {
        min-width: 0;
        min-height: 0;
        box-sizing: border-box;
    }

    #character-panel {
        grid-column: 1;
        grid-row: 1;
        padding: 12px 8px;
    }

    #main-game-panel {
        grid-column: 2;
        grid-row: 1;
        justify-content: center;
        padding: 26px 4px 8px;
        overflow: hidden;
    }

    #future-panel {
        grid-column: 3;
        grid-row: 1;
        padding: 34px 8px 8px;
        max-height: none;
        overflow-x: hidden;
        overflow-y: auto;
    }

    #info-panel {
        max-width: 100%;
        margin-bottom: 3px;
        padding: 3px 6px;
        gap: 6px;
        font-size: 10px;
        transform: none;
    }

    #next-preview {
        gap: 3px;
        transform: none;
    }

    #next-image {
        width: 20px;
        height: 20px;
    }

    .game-stage {
        max-width: 100%;
        max-height: calc(100vh - 76px);
        gap: 4px;
    }

    canvas {
        width: auto;
        height: min(600px, calc(100vh - 96px));
        max-width: 100%;
        aspect-ratio: 2 / 3;
        border-width: 3px;
        border-radius: 10px;
    }

    #evolution-progress {
        width: 22px;
        gap: 4px;
        font-size: 8px;
    }

    .evolution-progress-track {
        width: 10px;
        height: min(260px, calc(100vh - 170px));
    }

    #dex-container {
        width: 100%;
        max-width: 100%;
        margin-top: 4px;
        padding: 4px 5px;
        gap: 3px;
        border-radius: 5px;
    }

    .dex-circle {
        width: 16px;
        height: 16px;
        margin-bottom: 1px;
        border-width: 1px;
    }

    .dex-item {
        font-size: 8px;
    }

    .task-panel-header {
        margin-bottom: 8px;
    }

    .task-panel-header h2 {
        margin-bottom: 2px;
        font-size: 15px;
    }

    .task-panel-header span {
        font-size: 9px;
    }

    #task-list {
        gap: 6px;
    }

    .task-item {
        padding: 6px;
        border-radius: 5px;
    }

    .task-fruits {
        gap: 4px;
        margin-bottom: 6px;
    }

    .task-fruit-dot {
        width: 26px;
        height: 26px;
        flex-basis: 26px;
    }

    .task-complete-button {
        padding: 5px 6px;
        font-size: 10px;
    }

    .game-menu {
        top: 6px;
        right: 8px;
    }

    .game-menu summary {
        padding: 5px 7px;
        font-size: 10px;
    }
}

