/* ==========================================================================
   Poem Critique PWA - Mobile-First Styles
   ========================================================================== */

:root {
    /* Colors */
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #f59e0b;

    --bg: #f8fafc;
    --bg-dark: #1e293b;
    --card: #ffffff;
    --card-dark: #334155;

    --text: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;

    --border: #e2e8f0;
    --border-dark: #475569;

    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;

    /* Spacing */
    --gap: 24px;
    --card-padding: 32px 28px;
    --input-padding: 18px 16px;

    /* Transitions */
    --transition: 0.2s ease;

    /* Safe area */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100dvh;
    overflow-x: hidden;
}

/* ==========================================================================
   Screens
   ========================================================================== */

.screen {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    gap: var(--gap);
    padding: var(--safe-top) 16px var(--safe-bottom);
}

.screen.hidden {
    display: none;
}

/* Loading Screen */
.loading-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--bg-dark) 0%, #0f172a 100%);
    color: white;
}

.loading-content {
    text-align: center;
}

.loading-icon {
    font-size: clamp(4rem, 15vw, 6rem);
    margin-bottom: 16px;
    animation: float 2s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.loading-title {
    font-family: 'Noto Serif KR', serif;
    font-size: clamp(2rem, 8vw, 3rem);
    font-weight: 700;
    margin-bottom: 8px;
}

.loading-subtitle {
    color: var(--text-light);
    margin-bottom: 24px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 1s linear infinite;
}

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

/* Main Screen */
.main-screen {
    background: var(--bg);
    padding-bottom: max(24px, var(--safe-bottom));
}

/* ==========================================================================
   Header
   ========================================================================== */

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: max(16px, var(--safe-top)) 0 16px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-icon {
    font-size: 1.8rem;
}

.app-title {
    font-family: 'Noto Serif KR', serif;
    font-size: 1.5rem;
    font-weight: 700;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.docs-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--card);
    border-radius: 12px;
    text-decoration: none;
    transition: var(--transition);
}

.docs-link:hover {
    background: var(--border);
}

.docs-icon {
    font-size: 1.3rem;
}

.user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
}

.user-btn:hover {
    border-color: var(--primary);
}

.user-icon {
    font-size: 1.2rem;
}

.username {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
}

/* ==========================================================================
   Content & Cards
   ========================================================================== */

.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

.card {
    background: var(--card);
    border-radius: 20px;
    padding: var(--card-padding);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.card-title {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text);
}

/* ==========================================================================
   Form Elements
   ========================================================================== */

.form-group {
    margin-bottom: 24px;
}

.poem-textarea {
    width: 100%;
    min-height: 200px;
    padding: var(--input-padding);
    font-family: 'Noto Serif KR', serif;
    font-size: 1rem;
    line-height: 1.8;
    color: var(--text);
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 16px;
    resize: vertical;
    transition: var(--transition);
}

.poem-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.poem-textarea::placeholder {
    color: var(--text-light);
}

.char-count {
    text-align: right;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ==========================================================================
   Options Section
   ========================================================================== */

.options-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 24px;
}

.option-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.option-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
}

/* Tone Selector */
.tone-selector {
    display: flex;
    gap: 10px;
}

.tone-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 12px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 14px;
    cursor: pointer;
    transition: var(--transition);
}

.tone-btn:hover {
    border-color: var(--primary-light);
}

.tone-btn.active {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--primary);
}

.tone-icon {
    font-size: 1.4rem;
}

.tone-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
}

/* Toggle Switch */
.toggle-option {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.toggle-option input {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 50px;
    height: 28px;
    background: var(--border);
    border-radius: 14px;
    transition: var(--transition);
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    background: white;
    border-radius: 50%;
    transition: var(--transition);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.toggle-option input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle-option input:checked + .toggle-slider::after {
    transform: translateX(22px);
}

.toggle-text {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text);
}

.option-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-left: 62px;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.critique-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 18px 24px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: 16px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.critique-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.3);
}

.critique-btn:active {
    transform: translateY(0);
}

.critique-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.critique-btn.loading .btn-text {
    display: none;
}

.critique-btn.loading::after {
    content: '분석 중...';
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: var(--transition);
}

.icon-btn:hover {
    background: var(--border);
}

/* ==========================================================================
   Result Card
   ========================================================================== */

.result-card {
    animation: slideUp 0.4s ease;
}

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

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.result-header .card-title {
    margin-bottom: 0;
}

.critique-content {
    font-family: 'Noto Sans KR', sans-serif;
    line-height: 1.8;
}

.critique-section {
    margin-bottom: 28px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.critique-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.critique-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.critique-section p {
    color: var(--text);
    margin-bottom: 10px;
}

.critique-section ul {
    list-style: none;
    padding-left: 0;
}

.critique-section li {
    padding: 10px 0 10px 28px;
    position: relative;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}

.critique-section li:last-child {
    border-bottom: none;
}

.critique-section li::before {
    content: '•';
    position: absolute;
    left: 8px;
    color: var(--primary);
    font-weight: bold;
}

.strengths-list li::before {
    content: '✓';
    color: var(--success);
}

.improvements-list li::before {
    content: '→';
    color: var(--warning);
}

.recommendation-item {
    padding: 12px;
    background: var(--bg);
    border-radius: 12px;
    margin-bottom: 10px;
}

.recommendation-item:last-child {
    margin-bottom: 0;
}

.rec-poet {
    font-weight: 600;
    color: var(--primary-dark);
}

.rec-work {
    font-style: italic;
}

.rec-rationale {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ==========================================================================
   Toast
   ========================================================================== */

.toast-container {
    position: fixed;
    top: 80px; /* MUST be top, not bottom */
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    padding: 14px 20px;
    background: var(--bg-dark);
    color: white;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
    animation: toastIn 0.3s ease;
    pointer-events: auto;
    max-width: 320px;
    text-align: center;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--error);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   Modal
   ========================================================================== */

.modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--card);
    border-radius: 20px;
    padding: 32px 28px;
    max-width: 400px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    background: var(--bg);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--border);
}

#modal-body h3 {
    font-size: 1.2rem;
    margin-bottom: 16px;
    text-align: center;
}

.auth-btn {
    display: block;
    width: 100%;
    padding: 14px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 12px;
    transition: var(--transition);
}

.auth-btn:hover {
    background: var(--primary-dark);
}

.auth-btn.secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.auth-btn.secondary:hover {
    background: var(--border);
}

.user-info {
    text-align: center;
}

.user-info .avatar {
    font-size: 3rem;
    margin-bottom: 12px;
}

.user-info .name {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.user-info .stats {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 20px;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.footer {
    text-align: center;
    padding: 16px 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.footer a {
    color: var(--primary);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 480px) {
    .screen {
        padding: var(--safe-top) 12px var(--safe-bottom);
        gap: 20px;
    }

    .card {
        padding: 24px 20px;
        border-radius: 16px;
    }

    .tone-btn {
        padding: 12px 8px;
    }

    .tone-icon {
        font-size: 1.2rem;
    }

    .tone-name {
        font-size: 0.8rem;
    }

    .option-hint {
        margin-left: 0;
        margin-top: 8px;
    }
}

@media (max-height: 667px) {
    .poem-textarea {
        min-height: 150px;
    }

    .card {
        padding: 24px 20px;
    }
}

@media (max-height: 568px) {
    .poem-textarea {
        min-height: 120px;
    }

    .loading-icon {
        font-size: 3rem;
    }

    .loading-title {
        font-size: 1.8rem;
    }
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}
