/* 
    PTE Coach - Premium Design System & Interaction Layer
    v2.2 UI/UX Expansion
*/

:root {
    /* Color Tokens */
    --primary: var(--theme-accent, #06b6d4);
    --primary-hover: var(--theme-accent, #22d3ee);
    --secondary: #8b5cf6;
    --bg-dark: #0f172a;
    --card-bg: #020617;
    --surface: #1e293b;
    --text-main: #f1f5f9;
    --text-sub: #94a3b8;

    /* Status Colors */
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;

    /* Transitions */
    --transition-smooth: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
    --transition-bounce: all 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Neural Stream Progress Indicator */
.progress-active {
    box-shadow: 0 0 15px var(--primary), 0 0 30px var(--primary);
    filter: brightness(1.2);
}

/* 1. Global Refinements — Normal Document Flow (Flow Toggle Architecture) */
html {
    width: 100%;
    /* overflow-x: clip — 가로 스크롤 제거, body overflow-y 간섭 없음 */
    overflow-x: clip;
}

body {
    /* overflow-x: hidden 제거 — Android WebView에서 overflow-y:auto 강제 생성 → 하단 스크롤 freeze 유발.
       !important: Tailwind CDN CSSOM 동적 삽입 오버라이드 */
    overflow-x: visible !important;
    overflow-y: visible !important;
    width: 100%;
    max-width: 100vw;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 2. Micro-interactions */
.btn-premium {
    transition: var(--transition-bounce);
    position: relative;
    overflow: hidden;
}

.btn-premium:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 10px 20px -5px rgba(var(--primary-rgb), 0.3);
}

.btn-premium:active {
    transform: translateY(0) scale(0.98);
}

.icon-interact {
    transition: var(--transition-bounce);
}

.icon-interact:hover {
    transform: rotate(15deg) scale(1.2);
}

/* 3. Neural Sync States */
.mic-recording-btn {
    background-color: #f43f5e !important;
    /* rose-500 for active alert */
    color: white !important;
    box-shadow: 0 0 40px rgba(244, 63, 94, 0.4) !important;
    transform: scale(0.95);
    border-color: rgba(255, 255, 255, 0.2) !important;
}

#mic-pulse-ring.active-pulse {
    opacity: 0.6;
    animation: ping 1.5s cubic-bezier(0, 0, 0.2, 1) infinite;
}

@keyframes ping {

    75%,
    100% {
        transform: scale(2);
        opacity: 0;
    }
}

/* Base Utility Animations */
@keyframes ring-fill {
    from {
        stroke-dashoffset: 100;
    }
}

.animate-ring {
    animation: ring-fill 1.5s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

@keyframes slide-in-right {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.stagger-item {
    opacity: 0;
    animation: slide-in-right 0.5s ease forwards;
}

@keyframes pop-bounce {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    70% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.animate-pop {
    animation: mascot-glow-gold 3s ease-in-out infinite;
}

/* UI States (Loading, Empty, Error) */
.ux-state-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem;
    transition: all 0.5s ease;
}

.ux-state-icon-wrapper {
    width: 5rem;
    height: 5rem;
    border-radius: 2rem;
    background-color: #0f172a;
    /* slate-900 */
    border: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    position: relative;
    overflow: hidden;
}

.ux-state-loading .loading-spiral {
    width: 3rem;
    height: 3rem;
    border: 4px solid rgba(34, 211, 238, 0.2);
    border-top-color: var(--primary);
    border-radius: 9999px;
    animation: spin-slow 1s linear infinite;
}

.ux-state-empty {
    color: #64748b;
    /* slate-500 */
    opacity: 0.6;
}

.ux-state-error {
    color: #f43f5e;
    /* rose-500 */
}

.ux-state-error .ux-state-icon-wrapper {
    border-color: rgba(244, 63, 94, 0.3);
    background-color: rgba(244, 63, 94, 0.05);
    color: #fb7185;
    /* rose-400 */
}

@keyframes spin-slow {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Scrollbar Premium */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* 4. Feedback Panel - Tabbed Structure */
.kodari-insight-card {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 1rem;
    overflow: hidden;
    transition: var(--transition-smooth);
}

.kodari-tab {
    position: relative;
    padding: 0.75rem 1rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-sub);
    transition: var(--transition-smooth);
    cursor: pointer;
}

.kodari-tab.active {
    color: var(--primary);
}

.kodari-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20%;
    right: 20%;
    height: 2px;
    background: var(--primary);
    box-shadow: 0 0 10px var(--primary);
    border-radius: 2px;
}

/* 5. UX States */
.state-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    text-align: center;
}

.loading-spiral {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(6, 182, 212, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* 6. Pronunciation Heatmap */
.heatmap-word {
    transition: var(--transition-bounce);
}

.heatmap-word:hover {
    transform: scale(1.1) translateY(-2px);
    z-index: 10;
}


/* 8. Interaction & Layering (SPA v4.0) */

:root {
    --z-base: 1;
    --z-card: 10;
    --z-sticky: 100;
    --z-practice-full: 200;
    --z-overlay: 300;
    --z-toast: 400;
    --z-modal: 500;
}

/* Glass & Backdrop Hierarchy */
.glass-panel,
.card-premium {
    position: relative;
    z-index: var(--z-card);
    isolation: isolate;
}

#app-container,
#dashboard-view {
    position: relative;
    z-index: var(--z-base);
}

/*
  Flow Toggle Architecture v6.0
  ─────────────────────────────────────────────────────────
  Dashboard 활성: header 표시 / dashboard-view 표시 / practice-view 숨김
  Practice 활성:  header 숨김 / dashboard-view 숨김 / practice-view 표시

  #practice-view는 <main> 안에 있으나, full-bleed 기법으로
  parent(main)의 max-w-7xl + padding 제약을 완전히 탈출.
  absolute/fixed/z-index 없음 → WebView freeze 원인 제거.
*/

/* practice-view: main의 max-width 제약 탈출 (full-bleed) */
#practice-view {
    display: block;
    min-height: 100dvh;
    min-height: 100vh; /* fallback */
    position: static;

    /* Full-bleed: parent padding/max-width 무력화 */
    width: 100vw;
    margin-left: calc(50% - 50vw);

    background-color: var(--color-darkBg, #0a0f1e);
}

#practice-view.hidden {
    display: none !important;
}

/* practice-view 내부 스크롤 컨테이너 */
.practice-scroll-container {
    width: 100%;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

/* Overlays / Decorations: Visual only, non-blocking */
.blur-layer,
.fade-overlay,
.decorative-ring,
.decorative-glow,
.backdrop-blur,
.bg-overlay {
    pointer-events: none;
}

/* AI Status Bar: Non-blocking by default */
#ai-status-bar {
    pointer-events: none;
    z-index: var(--z-sticky);
}

#ai-status-bar>* {
    pointer-events: auto;
}

/* Loading Glass Layers: Block interactions when active */
.loading-overlay {
    pointer-events: auto;
    z-index: var(--z-modal);
}

/* Interactive Elements */
[data-action],
button,
select,
input,
textarea,
.btn-premium,
.clickable {
    cursor: pointer;
    pointer-events: auto !important;
    position: relative;
    z-index: 60;
    -webkit-tap-highlight-color: transparent;
}

/* Modal Behavior */
.modal-backdrop {
    pointer-events: auto;
    z-index: var(--z-overlay);
}

/* Disabled state */
[disabled],
.disabled {
    pointer-events: none !important;
    opacity: 0.5;
    cursor: not-allowed;
}

/* 9. Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {

    *,
    ::before,
    ::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* 10. Model Frame Visibility Control (Jung-Gong-Beop) */
.frame-hidden {
    display: none !important;
}

.frame-visible {
    display: block !important;
    animation: slide-up-premium 0.5s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

@keyframes slide-up-premium {
    from {
        opacity: 0;
        transform: translateY(20px);
        filter: blur(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
        filter: blur(0);
    }
}

/* =====================================================
   [P2-D] Mobile Touch Optimization (v7.4.10)
   - 300ms tap delay elimination
   - 48px minimum touch targets (WCAG 2.5.5)
   - iOS momentum scrolling for modals
   - Safe-area inset support for notched phones
   ===================================================== */

/* 1. Eliminate 300ms tap delay on ALL interactive elements */
button,
[data-action],
a,
select,
input,
textarea,
label,
.btn-premium,
.clickable {
    touch-action: manipulation;
}

/* 2. 48px minimum touch targets (touchscreen devices only) */
@media (hover: none) and (pointer: coarse) {

    button,
    [data-action] {
        min-height: 48px;
    }

    /* Icon-only buttons also get min-width */
    button.btn-icon,
    [data-action].btn-icon {
        min-width: 48px;
    }

    /* Practice view: mic + analyze buttons — bigger tap zones */
    #btn-master-mic,
    #analyze-btn {
        min-height: 56px;
        min-width: 56px;
    }

    /* Analysis modal footer 3-buttons */
    #strategic-report-modal button {
        min-height: 64px;
        /* already 72px via min-h, but enforce fallback */
    }

    /* Nav / back buttons */
    #btn-back-home,
    [data-action="btn-back-home"],
    [data-action="back-to-dashboard"] {
        min-height: 48px;
        min-width: 48px;
    }
}

/* 3. iOS momentum scrolling + overscroll containment for modals */
#strategic-report-modal [class*="overflow-y"],
#calibration-modal [class*="overflow-y"],
#strategic-report-content {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

/* Also target custom-scrollbar globally */
.custom-scrollbar {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

/* 4. Safe-area inset for notched/gesture-nav phones (iOS & Android) */
#strategic-report-modal>div {
    /* Push modal footer above navigation bar */
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Bottom-anchored bars */
#ai-status-bar {
    padding-bottom: max(0px, env(safe-area-inset-bottom));
}

/* =====================================================
   [Phase 1] Module Card Gradient Redesign
   참고: feature_graphic_banner_v2.png 스타일
   각 카드의 --theme-accent-rgb 인라인 변수 기반으로
   자동으로 카드별 고유 색상 적용됨
   ===================================================== */

/* 1-A: 그라디언트 배경 */
.card-premium {
    background: linear-gradient(
        135deg,
        rgba(var(--theme-accent-rgb, 6, 182, 212), 0.22) 0%,
        rgba(var(--theme-accent-rgb, 6, 182, 212), 0.07) 55%,
        rgba(2, 6, 23, 0.97) 100%
    ) !important;
    border: 1px solid rgba(var(--theme-accent-rgb, 6, 182, 212), 0.30) !important;
    border-radius: 1.25rem;
    transition: transform 0.35s cubic-bezier(0.23, 1, 0.32, 1),
                box-shadow 0.35s cubic-bezier(0.23, 1, 0.32, 1),
                border-color 0.35s ease;
    overflow: hidden;
}

/* 1-B: 상단 컬러 강조 라인 */
.card-premium::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(
        90deg,
        rgba(var(--theme-accent-rgb, 6, 182, 212), 0.9) 0%,
        rgba(var(--theme-accent-rgb, 6, 182, 212), 0.2) 70%,
        transparent 100%
    );
    border-radius: 1.25rem 1.25rem 0 0;
    pointer-events: none;
}

/* 1-C: 호버 — 글로우 + 떠오르기 */
.card-premium:hover {
    transform: translateY(-5px);
    box-shadow:
        0 16px 48px -8px rgba(var(--theme-accent-rgb, 6, 182, 212), 0.45),
        0 0 0 1px rgba(var(--theme-accent-rgb, 6, 182, 212), 0.25) inset !important;
    border-color: rgba(var(--theme-accent-rgb, 6, 182, 212), 0.55) !important;
}

/* 1-D: 내부 래디얼 글로우 오버레이 */
.card-premium::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(
        circle at 25% 25%,
        rgba(var(--theme-accent-rgb, 6, 182, 212), 0.12) 0%,
        transparent 65%
    );
    opacity: 0;
    transition: opacity 0.4s ease;
    pointer-events: none;
    border-radius: inherit;
}

.card-premium:hover::after {
    opacity: 1;
}

/* 모듈 타일 내부 레이아웃 */
.module-tile-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    position: relative;
    z-index: 1;
}

/* 아이콘 래퍼 컨테이너 */
.module-tile-icon-wrap {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(var(--theme-accent-rgb, 6, 182, 212), 0.18);
    border: 1px solid rgba(var(--theme-accent-rgb, 6, 182, 212), 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(var(--theme-accent-rgb, 6, 182, 212), 1);
    font-size: 22px;
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    flex-shrink: 0;
}

.card-premium:hover .module-tile-icon-wrap {
    background: rgba(var(--theme-accent-rgb, 6, 182, 212), 0.32);
    transform: scale(1.12) rotate(6deg);
    box-shadow: 0 0 20px rgba(var(--theme-accent-rgb, 6, 182, 212), 0.35);
}

/* 모듈 타일 텍스트 */
.module-tile-title {
    font-size: 0.78rem;
    font-weight: 800;
    color: #f1f5f9;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.3;
    text-align: left;
}

/* 오른쪽 하단 bolt 액션 아이콘 */
.module-tile-action {
    position: absolute;
    bottom: -6px;
    right: -4px;
    font-size: 3.5rem !important;
    color: rgba(var(--theme-accent-rgb, 6, 182, 212), 0.12);
    pointer-events: none;
    transition: color 0.35s ease, transform 0.35s ease;
    z-index: 0;
}

.card-premium:hover .module-tile-action {
    color: rgba(var(--theme-accent-rgb, 6, 182, 212), 0.22);
    transform: scale(1.1) rotate(-5deg);
}