@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@300;400;500;700;900&family=Noto+Serif+TC:wght@400;600;700;900&display=swap');

:root {
    --app-height: 100vh;
    --sheet-height: 40vh;
    --sheet-max-height: 400px;
}

html,
body {
    /* 🔧 防止橡皮筋反彈與雙擊放大 (LINE in-app browser 常見問題) */
    overscroll-behavior: none;
    touch-action: manipulation;
}

html {
    font-size: clamp(15px, 14px + 0.25vw, 17px);
}

body {
    margin: 0;
    overflow: hidden;
    background: #FAF9F6;
    font-family: 'Noto Sans TC', 'Outfit', sans-serif;
    -webkit-tap-highlight-color: transparent;
    width: 100vw;
    height: var(--app-height);
    position: fixed;
    top: 0;
    left: 0;
    color: #44403c; /* stone-700 */
    letter-spacing: 0.1em;
}

.tracking-widest-brand {
    letter-spacing: 0.3em;
}

h1, h2, h3, .brand-font {
    letter-spacing: 0.3em;
    font-weight: 300;
}

.font-serif-tc {
    font-family: 'Noto Serif TC', serif;
}

#canvas-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: calc(var(--app-height) - min(var(--sheet-height), var(--sheet-max-height)));
    z-index: 1;
    /* 🔧 只有 Canvas 禁用原生觸控,不影響其他元素 */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    overscroll-behavior: none;
}

body.immersive #canvas-container {
    height: var(--app-height);
}

::-webkit-scrollbar {
    display: none;
}

.hide-scroll {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.bottom-sheet {
    transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    padding-bottom: env(safe-area-inset-bottom, 20px);
    height: var(--sheet-height);
    max-height: var(--sheet-max-height);
    overscroll-behavior: contain;
    /* 🔧 sheet 內允許垂直滑動 */
    touch-action: pan-y;
}

.ui-fade {
    transition: opacity 0.3s ease;
}

#theater-overlay {
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.6) 0%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.8) 100%);
    z-index: 5;
    position: absolute;
    inset: 0;
}

body.immersive .bottom-sheet {
    transform: translateY(100%);
}

body.immersive .ui-fade {
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
}

body.immersive #theater-overlay {
    opacity: 1;
    pointer-events: none !important;
}

body.immersive #status-badge-wrapper {
    opacity: 0 !important;
    pointer-events: none !important;
}

.item-card {
    transition: all 0.2s ease;
    border: 1px solid #e7e5e4; /* stone-200 */
    background: #ffffff;
}

.item-card:active {
    transform: scale(0.95);
    background: #f8fafc;
    border-color: #e2e8f0;
}

.tool-btn {
    transition: all 0.2s ease;
}

.tool-btn:active {
    transform: scale(0.95);
    background: #f1f5f9;
}

.top-tab.active {
    color: #44403c; /* stone-700 */
    font-weight: 400;
    border-bottom: 2px solid #a8a29e; /* stone-400 */
}

.sidebar-btn.active {
    color: #44403c;
    font-weight: 400;
    background: #ffffff;
    position: relative;
}

.sidebar-btn.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 20%;
    height: 60%;
    width: 3px;
    background: #0f172a;
    border-radius: 0 4px 4px 0;
}

#ritual-overlay {
    overflow-y: auto;
    overflow-x: hidden;
    /* 🔧 ritual overlay 允許完整觸控,select 才能開 */
    touch-action: auto;
    user-select: auto;
    background-color: #FAF9F6;
    height: var(--app-height);
    overscroll-behavior: contain;
}

#ritual-step-container {
    display: grid;
    align-items: center;
    justify-items: center;
    width: 100%;
    min-height: var(--app-height);
    padding: 2rem 1rem 10rem 1rem;
}

.ritual-step {
    grid-area: 1 / 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: opacity 0.5s ease, transform 0.5s ease;
    opacity: 0;
    pointer-events: none;
}

.ritual-step.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
    z-index: 10;
}

.ritual-step.next {
    transform: translateY(20px);
}

.ritual-step.prev {
    transform: translateY(-20px);
}

.perspective-1000 {
    perspective: 1200px;
    -webkit-perspective: 1200px;
}

.transform-style-3d {
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
}

.backface-hidden {
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.card-wrapper {
    transition: transform 0.7s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.5s ease;
    cursor: pointer;
    position: absolute;
    transform-origin: bottom center;
}

@media (hover: hover) {
    .card-wrapper:not(.selected-card):hover {
        z-index: 20 !important;
        transform: var(--base-trans) translateY(-10px) scale(1.05) !important;
    }
}

.card-wrapper:active .card-inner {
    transform: scale(0.95);
}

.card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.8s cubic-bezier(0.4, 0.2, 0.2, 1);
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
}

.is-flipped {
    transform: rotateY(180deg);
    pointer-events: none;
}

.mystic-pattern {
    background-image: linear-gradient(45deg, rgba(201, 142, 107, 0.08) 25%, transparent 25%, transparent 75%, rgba(201, 142, 107, 0.08) 75%, rgba(201, 142, 107, 0.08)), linear-gradient(45deg, rgba(201, 142, 107, 0.08) 25%, transparent 25%, transparent 75%, rgba(201, 142, 107, 0.08) 75%, rgba(201, 142, 107, 0.08));
    background-size: 16px 16px;
    background-position: 0 0, 8px 8px;
}

select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1em;
    background-color: white;
    cursor: pointer;
    /* 🔧 select 必須允許原生觸控才能展開 picker */
    touch-action: auto;
    position: relative;
    z-index: 50;
    text-align: center;
    text-align-last: center;
}

.loader-ring {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 3px solid rgba(201, 142, 107, 0.1);
    border-top-color: #c98e6b;
    animation: spin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}

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

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

.ritual-focus-btn {
    border-width: 2px;
    border-color: transparent;
    padding: 12px 8px;
}

.ritual-focus-btn:not(.selected) {
    border-color: #f3f4f6;
}

.ritual-focus-btn.selected {
    border-color: #a8a29e; /* stone-400 */
    background-color: rgba(168, 162, 158, 0.05);
    box-shadow: 0 4px 15px rgba(120, 113, 108, 0.1);
}

/* =====================================================
   全設備響應式設計 (RWD)
   手機 <600px | 平板 600~1023px | 桌面 ≥1024px
   ===================================================== */

/* 流動字體 — 所有尺寸自動插值，無需 media query */
html {
    font-size: clamp(14px, 1vw + 12px, 17px);
}

/* === 右側浮動資訊欄 === */
/* 桌面：維持原位並顯示完整 */
@media (min-width: 1024px) {
    #ui-layer [class*='right-5'][class*='top-\[80px\]'],
    .ui-right-panel {
        top: 88px;
        right: 1.5rem;
    }
}

/* 平板：縮小字體與間距 */
@media (min-width: 600px) and (max-width: 1023px) {
    #ui-layer [class*='absolute'][class*='right-5'] {
        right: 0.75rem;
        top: 72px;
        gap: 0.5rem;
    }
    #ui-layer [class*='absolute'][class*='right-5'] .text-\[22px\] {
        font-size: 1.1rem;
    }
    #ui-layer [class*='absolute'][class*='right-5'] .text-\[18px\] {
        font-size: 0.95rem;
    }
}


@media (max-width: 599px) {
    /* 手機：右側小資訊欄只縮減位置，不改變內部 flex 方向 */
    #ui-layer [class*='absolute'][class*='right-5'],
    .ui-right-panel {
        right: 0.5rem;
        top: 68px;
        gap: 0.35rem;
    }

    /* 字體縮小確保不搶鏡 */
    #ui-layer [class*='absolute'][class*='right-5'] .text-\[22px\] {
        font-size: 0.95rem;
    }
    #ui-layer [class*='absolute'][class*='right-5'] .text-\[18px\] {
        font-size: 0.85rem;
    }
    #ui-layer [class*='absolute'][class*='right-5'] .text-\[9px\],
    #ui-layer [class*='absolute'][class*='right-5'] .text-\[8\.5px\] {
        font-size: 0.6rem;
    }

    /* 底部 sheet — 手機版確保有足夠高度 */
    .bottom-sheet {
        height: clamp(160px, 38vh, 340px);
        max-height: 360px;
    }

    /* canvas 高度隨 sheet 動態調整 */
    #canvas-container {
        height: calc(var(--app-height) - clamp(160px, 38vh, 340px));
    }

    /* 儀式流程步驟在小螢幕的 padding */
    #ritual-step-container {
        padding: 1.5rem 0.75rem 9rem 0.75rem;
    }

    /* 頂部導航欄縮小 padding */
    #ui-layer > div:first-child {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}


/* 左側工具按鈕：手機縮小 */
@media (max-width: 599px) {
    #ui-layer [class*='absolute'][class*='left-3'] {
        left: 0.3rem;
        top: 68px;
        gap: 0.4rem;
    }
    #ui-layer [class*='absolute'][class*='left-3'] button {
        width: 36px;
    }
}

/* 底部 action bar 按鈕文字大小響應 */
@media (max-width: 380px) {
    #btn-submit-line {
        font-size: 0.8rem;
        letter-spacing: 0.1em;
    }
    #btn-design {
        font-size: 0.75rem;
    }
}