/* ========================================
   ROOT & VARIABLES
   ======================================== */

:root {
    /* Color Palette */
    --primary-color: #FFB6D9;
    --primary-dark: #FF9CC8;
    --secondary-color: #FFE5F0;
    --accent-color: #FF6BB1;
    --success-color: #66BB6A;
    --warning-color: #FFA726;
    --error-color: #EF5350;
    --text-dark: #333333;
    --text-light: #666666;
    --bg-light: #FFFFFF;
    --bg-lighter: #FAFAFA;
    
    /* Typography */
    --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    --font-size-h1: 24px;
    --font-size-h2: 20px;
    --font-size-body: 16px;
    --font-size-small: 14px;
    
    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    
    /* Border & Shadow */
    --border-radius: 20px;
    --border-radius-sm: 12px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.2);
    
    /* Transitions */
    --transition-fast: 200ms ease;
    --transition-normal: 300ms ease;
    --transition-slow: 500ms ease;
    
    /* Game Container Aspect Ratio */
    --game-aspect-ratio: 9 / 16;
    --game-max-width: 100vw;
    --game-max-height: 100vh;
}

/* ========================================
   BASE STYLES
   ======================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    font-family: var(--font-main);
    background-color: var(--bg-lighter);
    color: var(--text-dark);
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-app-region: no-drag;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* ========================================
   GAME CONTAINER (9:16 RESPONSIVE)
   ======================================== */

.game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    aspect-ratio: var(--game-aspect-ratio);
    max-width: 100%;
    max-height: 100%;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateZ(0); /* 硬件加速 */
    
    /* 根据屏幕尺寸进行缩放 */
    @supports (aspect-ratio: 1) {
        aspect-ratio: var(--game-aspect-ratio);
    }
}

/* 响应式缩放逻辑 */
@media (min-aspect-ratio: 9/16) {
    .game-container {
        height: auto;
        width: calc(var(--game-max-height) * 9 / 16);
        max-width: 100vw;
    }
}

@media (max-aspect-ratio: 9/16) {
    .game-container {
        width: 100vw;
        height: calc(100vw * 16 / 9);
        max-height: 100vh;
    }
}

/* 刘海屏适配 */
@supports (padding: max(0px)) {
    .game-container {
        padding-left: max(env(safe-area-inset-left), 0);
        padding-right: max(env(safe-area-inset-right), 0);
        padding-top: max(env(safe-area-inset-top), 0);
        padding-bottom: max(env(safe-area-inset-bottom), 0);
    }
}

/* ========================================
   HEADER
   ======================================== */

.game-header {
    padding: var(--spacing-md) var(--spacing-md) var(--spacing-sm);
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.5);
    flex-shrink: 0;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.game-header h1 {
    font-size: var(--font-size-h1);
    font-weight: 700;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ========================================
   DEBUG BUTTON AND HEADER BUTTONS
   ======================================== */

.header-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

.diagnostic-link {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.6);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    text-decoration: none;
    color: white;
}

.diagnostic-link:active {
    background: rgba(255, 255, 255, 0.6);
    transform: scale(0.95);
}

.debug-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.6);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.debug-btn:active {
    background: rgba(255, 255, 255, 0.6);
    transform: scale(0.95);
}

/* ========================================
   GAME MAIN
   ======================================== */

.game-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: var(--spacing-lg) var(--spacing-md);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    gap: var(--spacing-md);
}

/* 隐藏滚动条但保持滚动功能 */
.game-main::-webkit-scrollbar {
    display: none;
}
.game-main {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* ========================================
   SCORE BOARD
   ======================================== */

.score-board {
    display: flex;
    gap: var(--spacing-md);
    justify-content: space-around;
    margin-bottom: var(--spacing-sm);
}

.score-item {
    background: rgba(255, 255, 255, 0.5);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xs);
    min-width: 100px;
    backdrop-filter: blur(10px);
}

.score-label {
    font-size: var(--font-size-small);
    color: rgba(255, 255, 255, 0.8);
    font-weight: 500;
}

.score-value {
    font-size: 20px;
    font-weight: 700;
    color: white;
}

/* ========================================
   GAME AREA
   ======================================== */

.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

/* ========================================
   CHARACTER DISPLAY
   ======================================== */

.character-display {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-height: 50%;
    margin-bottom: var(--spacing-md);
}

.character-image-wrapper {
    position: relative;
    width: 200px;
    height: 200px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(10px);
}

.character-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: var(--spacing-md);
}

/* ========================================
   CHARACTER NAME
   ======================================== */

.character-name-display {
    text-align: center;
    margin-bottom: var(--spacing-lg);
}

.character-name {
    font-size: var(--font-size-h2);
    font-weight: 700;
    color: white;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    min-height: 30px;
    word-break: break-word;
    line-height: 1.4;
}

/* ========================================
   VOICE CONTROL
   ======================================== */

.voice-control {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    width: 100%;
    margin-bottom: var(--spacing-lg);
}

.record-btn {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: linear-gradient(135deg, white, #FFE5F0);
    border: 4px solid rgba(255, 255, 255, 0.5);
    font-size: 40px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-lg);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.record-btn:active {
    transform: scale(0.95);
}

.record-btn.listening {
    background: linear-gradient(135deg, var(--accent-color), var(--primary-dark));
    animation: pulse 1s infinite;
}

.record-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.record-text {
    font-size: var(--font-size-small);
    font-weight: 600;
    color: var(--text-dark);
}

.record-btn.listening .record-text {
    color: white;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 107, 177, 0.7);
    }
    70% {
        box-shadow: 0 0 0 20px rgba(255, 107, 177, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 107, 177, 0);
    }
}

/* ========================================
   RECORDING INDICATOR
   ======================================== */

.recording-indicator {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    color: white;
    font-size: var(--font-size-small);
}

.recording-indicator.hidden {
    display: none;
}

.recording-dots {
    display: flex;
    gap: var(--spacing-xs);
}

.recording-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: white;
    animation: dot-pulse 1.4s infinite;
}

.recording-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.recording-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dot-pulse {
    0%, 60%, 100% {
        opacity: 0.3;
    }
    30% {
        opacity: 1;
    }
}

/* ========================================
   VOLUME VISUALIZER
   ======================================== */

.volume-visualizer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
    color: white;
    font-size: var(--font-size-small);
}

.volume-visualizer.hidden {
    display: none;
}

.volume-bars {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 60px;
}

.volume-bars .bar {
    width: 6px;
    background: linear-gradient(180deg, #FFB6D9 0%, #FF69B4 100%);
    border-radius: 3px;
    animation: volumePulse 0.2s ease-out;
    transform-origin: bottom;
}

@keyframes volumePulse {
    0% {
        height: 20%;
        opacity: 0.8;
    }
    100% {
        height: 100%;
        opacity: 1;
    }
}

/* ========================================
   USER INPUT DISPLAY
   ======================================== */

.user-input-display {
    background: rgba(255, 255, 255, 0.3);
    border-radius: var(--border-radius-sm);
    padding: var(--spacing-md);
    width: 100%;
    max-width: 300px;
    text-align: center;
    backdrop-filter: blur(10px);
}

.user-input-display.hidden {
    display: none;
}

.user-input-display .label {
    font-size: var(--font-size-small);
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: var(--spacing-xs);
}

.user-input-text {
    font-size: var(--font-size-body);
    color: white;
    font-weight: 600;
    word-break: break-all;
}

/* ========================================
   RESULT AREA
   ======================================== */

.result-area {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity var(--transition-normal);
    z-index: 100;
}

.result-area.hidden {
    pointer-events: none;
    opacity: 0;
}

.result-content {
    background: white;
    border-radius: var(--border-radius);
    padding: var(--spacing-lg);
    max-width: 280px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-lg);
    animation: slideUp var(--transition-normal) ease;
}

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

/* ========================================
   SIMILARITY CIRCLE
   ======================================== */

.similarity-circle {
    position: relative;
    width: 120px;
    height: 120px;
}

.similarity-circle svg {
    width: 100%;
    height: 100%;
}

.circle-bg {
    fill: none;
    stroke: var(--bg-lighter);
    stroke-width: 8;
}

.circle-progress {
    fill: none;
    stroke: url(#gradient);
    stroke-width: 8;
    stroke-dasharray: 283;
    stroke-dashoffset: 283;
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
    transition: stroke-dashoffset var(--transition-slow) ease;
}

.similarity-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xs);
}

.percent {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent-color);
}

.similarity-text .label {
    font-size: var(--font-size-small);
    color: var(--text-light);
}

/* ========================================
   RESULT MESSAGE
   ======================================== */

.result-message {
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message-text {
    font-size: var(--font-size-body);
    color: var(--text-dark);
    font-weight: 600;
    line-height: 1.5;
}

.message-text.success {
    color: var(--success-color);
}

.message-text.warning {
    color: var(--warning-color);
}

/* ========================================
   BUTTONS
   ======================================== */

.next-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    border: none;
    padding: var(--spacing-sm) var(--spacing-xl);
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-body);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-md);
    min-width: 120px;
}

.next-btn:active {
    transform: scale(0.95);
    box-shadow: var(--shadow-sm);
}

.primary-btn, .secondary-btn {
    padding: var(--spacing-sm) var(--spacing-lg);
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-body);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
    min-width: 120px;
}

.primary-btn {
    background: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-md);
}

.primary-btn:active {
    transform: scale(0.95);
}

.secondary-btn {
    background: transparent;
    color: var(--text-dark);
    border: 2px solid var(--text-light);
}

.secondary-btn:active {
    background: var(--bg-lighter);
}

/* ========================================
   DEBUG PANEL
   ======================================== */

.debug-panel {
    position: fixed;
    top: 0;
    right: 0;
    left: auto;
    width: 100%;
    max-width: 350px;
    height: 100dvh;
    background: white;
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform var(--transition-normal);
    /* iOS 特定修复 */
    -webkit-appearance: none;
    appearance: none;
    -webkit-user-select: none;
    user-select: none;
    /* iOS 滚动修复 - 必须 */
    -webkit-touch-callout: none;
}

.debug-panel.hidden {
    pointer-events: none;
}

.debug-panel:not(.hidden) {
    transform: translateX(0);
}

/* iOS safe area */
@supports (padding: max(0px)) {
    .debug-panel {
        max-width: calc(350px - max(env(safe-area-inset-right), 0));
        padding-right: max(env(safe-area-inset-right), 0);
    }
}

.debug-header {
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--bg-lighter);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    gap: var(--spacing-sm);
    z-index: 10;
    position: relative;
}

.debug-header h2 {
    font-size: var(--font-size-h2);
    margin: 0;
    flex: 1;
}

.debug-header-buttons {
    display: flex;
    gap: var(--spacing-xs);
}

.debug-action-btn,
.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-lighter);
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    -webkit-appearance: none;
    appearance: none;
}

.debug-action-btn:active,
.close-btn:active {
    background: var(--secondary-color);
    transform: scale(0.9);
}

/* iOS 滚动容器 */
.debug-content-scroll {
    flex: 1;
    overflow: hidden;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

.debug-content {
    height: 100%;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    padding: var(--spacing-md);
    overflow-x: hidden;
    position: relative;
}

.debug-section {
    margin-bottom: var(--spacing-lg);
    display: block;
}

.debug-section h3 {
    font-size: var(--font-size-body);
    margin: 0 0 var(--spacing-sm) 0;
    color: var(--text-dark);
    font-weight: 600;
}

.debug-info,
.debug-console {
    background: var(--bg-lighter);
    border-radius: var(--border-radius-sm);
    padding: var(--spacing-md);
    font-size: var(--font-size-small);
    line-height: 1.8;
    word-break: break-all;
}

.debug-info p,
.debug-console p {
    margin: 4px 0;
}

.debug-console {
    max-height: 200px;
    overflow-y: auto;
    background: #000;
    color: #0f0;
    font-family: monospace;
    padding: var(--spacing-sm);
    font-size: 11px;
    line-height: 1.4;
}

.debug-history {
    background: var(--bg-lighter);
    border-radius: var(--border-radius-sm);
    padding: var(--spacing-md);
    max-height: 200px;
    overflow-y: auto;
    font-size: 12px;
    line-height: 1.6;
}

.history-item {
    padding: 4px;
    margin-bottom: 4px;
    border-bottom: 1px solid #ddd;
}

/* ========================================
   MODAL
   ======================================== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    opacity: 1;
    transition: opacity var(--transition-normal);
}

.modal.hidden {
    pointer-events: none;
    opacity: 0;
}

.modal-content {
    background: white;
    border-radius: var(--border-radius);
    padding: var(--spacing-lg);
    max-width: 280px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.modal-content h2 {
    font-size: var(--font-size-h2);
    color: var(--text-dark);
}

.modal-content p {
    font-size: var(--font-size-body);
    color: var(--text-light);
}

.modal-content button {
    width: 100%;
}

/* ========================================
   LOADING OVERLAY
   ======================================== */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity var(--transition-normal);
}

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

.loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loader p {
    color: white;
    font-weight: 600;
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.hidden {
    display: none !important;
}

/* ========================================
   MEDIA QUERIES
   ======================================== */

/* 超小屏幕 */
@media (max-height: 600px) {
    .game-main {
        padding: var(--spacing-md) var(--spacing-sm);
        gap: var(--spacing-sm);
    }
    
    .character-image-wrapper {
        width: 120px;
        height: 120px;
    }
    
    .record-btn {
        width: 90px;
        height: 90px;
        font-size: 30px;
    }
}

/* 横屏模式（如果用户旋转手机） */
@media (orientation: landscape) {
    .game-main {
        padding: var(--spacing-sm);
    }
    
    .score-board {
        margin-bottom: var(--spacing-sm);
    }
    
    .character-name {
        font-size: 16px;
        min-height: 20px;
    }
}

/* 打印样式 */
@media print {
    body, .game-container {
        display: none;
    }
}
