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

:root {
    --primary: #000;
    --primary-hover: #333;
    --bg: #fafafa;
    --card-bg: #fff;
    --text: #111;
    --text-muted: #666;
    --text-light: #999;
    --border: #eee;
    --border-dark: #ddd;
    --accent: #0066ff;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    min-height: 100vh;
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    -webkit-touch-callout: none;
}

.container {
    max-width: 640px;
    margin: 0 auto;
    padding: 60px 20px 40px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 헤더 */
.header {
    position: relative;
    text-align: center;
    margin-bottom: 20px;
}

.title-row {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-corner {
    position: absolute;
    left: 0;
}

.logo-corner:hover .logo {
    transform: scale(1.08);
}

.logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    transition: transform 0.2s ease;
}

.header h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 8px;
}

.header p {
    color: var(--text-muted);
    font-size: 15px;
}

.greeting {
    display: inline-block;
    margin-top: 12px;
    padding: 6px 14px;
    background: var(--text);
    color: #fff;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    min-height: 1.5em;
}

/* 카드 */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* 폼 */
form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1;
}

/* 입력 영역 (contenteditable) */
.meeting-input {
    width: 100%;
    padding: 16px;
    border: 1px solid var(--border-dark);
    border-radius: 8px;
    font-size: 14px;
    min-height: 200px;
    flex: 1;
    overflow-y: auto;
    transition: border-color 0.2s;
    font-family: inherit;
    line-height: 1.6;
    background: #fff;
    -webkit-user-select: text;
    user-select: text;
}

.meeting-input:focus {
    outline: none;
    border-color: var(--primary);
}

.meeting-input:empty::before {
    content: attr(data-placeholder);
    color: var(--text-light);
    pointer-events: none;
}

.meeting-input img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin: 8px 0;
}

button {
    padding: 14px 24px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

button:hover {
    background: var(--primary-hover);
}

button:active {
    transform: scale(0.98);
    opacity: 0.9;
}

button:disabled {
    background: var(--text);
    opacity: 0.7;
    cursor: not-allowed;
    animation: thinking 1.5s ease-in-out infinite;
}

@keyframes thinking {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 0.5; }
}

.hidden {
    display: none !important;
}

/* 로딩 */
#loading-section {
    margin-top: 24px;
}

.loading-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px 24px;
    text-align: center;
}

.loading-animation {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 24px;
}

.loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-light);
    animation: pulse 1.4s ease-in-out infinite;
}

.loading-dot:nth-child(1) { animation-delay: 0s; }
.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* 프로그레스 */
.progress-container {
    margin-bottom: 24px;
}

.progress-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.progress-text {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

/* 메시지 */
.message-area {
    min-height: 60px;
}

.status-badge {
    display: inline-block;
    padding: 4px 10px;
    background: var(--bg);
    border-radius: 4px;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.rotating-message {
    font-size: 15px;
    color: var(--text);
    transition: opacity 0.3s;
}

.rotating-message.fade-out {
    opacity: 0;
}

/* 팁 */
.tip-area {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.tip-text {
    font-size: 13px;
    color: var(--text-light);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

/* 결과 페이지 */
.result-container {
    max-width: 560px;
    margin: 0 auto;
    padding: 60px 20px 40px;
}

.comic-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.comic {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
}

.comic h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 16px;
    text-align: center;
}

.panels {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.panel {
    text-align: center;
}

.panel img {
    width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: opacity 0.2s;
    -webkit-touch-callout: default;
    -webkit-user-select: none;
    user-select: none;
}

.panel img:hover {
    opacity: 0.9;
}

.panel img:active {
    opacity: 0.8;
}

.panel p {
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

/* 다운로드 */
.download-section {
    margin-top: 20px;
    text-align: center;
}

.download-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border-dark);
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    -webkit-tap-highlight-color: transparent;
}

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

.download-btn:active {
    transform: scale(0.98);
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 32px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    transition: color 0.2s;
    padding: 8px 4px;
    -webkit-tap-highlight-color: transparent;
}

.back-link:hover {
    color: var(--text);
}

.back-link:active {
    opacity: 0.7;
}

/* 에러 */
.error-message {
    background: #fff5f5;
    border: 1px solid #ffebeb;
    border-radius: 8px;
    padding: 16px;
    color: #c00;
    font-size: 14px;
    margin-top: 16px;
}

/* 작업 내역 */
#history-section {
    margin-top: 32px;
}

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

.history-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.1s;
    text-decoration: none;
    color: inherit;
}

.history-item:hover {
    border-color: var(--border-dark);
}

.history-item:active {
    transform: scale(0.99);
}

.history-thumbnail {
    width: 60px;
    height: 60px;
    border-radius: 6px;
    object-fit: cover;
    background: var(--bg);
    flex-shrink: 0;
}

.history-thumbnail.placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--text-light);
}

.history-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

.history-preview {
    font-size: 14px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-light);
}

.history-status {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.history-status.completed {
    background: #e8f5e9;
    color: #2e7d32;
}

.history-status.processing {
    background: #fff3e0;
    color: #ef6c00;
}

.history-status.pending {
    background: #e3f2fd;
    color: #1565c0;
}

/* 푸터 */
.footer {
    margin-top: 60px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    text-align: center;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    transition: color 0.2s;
    padding: 8px 4px;
    -webkit-tap-highlight-color: transparent;
}

.footer-links a:hover {
    color: var(--text);
}

.footer-links a:active {
    opacity: 0.7;
}

.footer-contact {
    font-size: 12px;
    color: var(--text-light);
}

.footer-contact a {
    color: var(--text-light);
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

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

.footer-contact a:active {
    opacity: 0.7;
}

/* 이미지 뷰어 모달 */
.viewer-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    -webkit-user-select: none;
    user-select: none;
}

.viewer-overlay.active {
    opacity: 1;
    visibility: visible;
}

.viewer-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

.viewer-img {
    max-width: min(90vw, 600px);
    max-height: 70vh;
    object-fit: contain;
    border-radius: 8px;
    user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    pointer-events: none;
}

.viewer-caption {
    margin-top: 16px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    text-align: center;
    max-width: 480px;
}

.viewer-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.viewer-close:hover {
    color: #fff;
}

.viewer-close:active {
    transform: scale(0.9);
}

.viewer-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.viewer-nav:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.viewer-nav:active {
    transform: translateY(-50%) scale(0.95);
}

.viewer-nav svg {
    width: 20px;
    height: 20px;
}

.viewer-prev { left: 16px; }
.viewer-next { right: 16px; }

.viewer-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.4);
    font-size: 12px;
}

/* 이미지 선택 모달 */
.image-select-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.image-select-modal.active {
    display: flex;
}

.image-select-content {
    background: var(--card-bg);
    border-radius: 16px;
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.image-select-header {
    padding: 20px 20px 16px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.image-select-header h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

.image-select-header p {
    font-size: 14px;
    color: var(--text-muted);
}

.image-select-actions-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.select-all-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
}

.select-all-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
}

.selected-count {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

.image-select-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

.image-select-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s, transform 0.2s;
}

.image-select-item:hover {
    transform: scale(1.02);
}

.image-select-item.selected {
    border-color: var(--primary);
}

.image-select-item.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.image-select-item.disabled:hover {
    transform: none;
}

.image-select-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-select-item .check-overlay {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid var(--border-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s;
}

.image-select-item.selected .check-overlay {
    background: var(--primary);
    border-color: var(--primary);
}

.image-select-item .check-overlay svg {
    width: 14px;
    height: 14px;
    color: transparent;
}

.image-select-item.selected .check-overlay svg {
    color: #fff;
}

.image-select-actions {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.image-select-actions button {
    flex: 1;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

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

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

.btn-confirm {
    background: var(--primary);
    border: none;
    color: #fff;
}

.btn-confirm:hover:not(:disabled) {
    background: var(--primary-hover);
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* 모달 반응형 */
@media (max-width: 480px) {
    .image-select-content {
        max-height: 90vh;
        border-radius: 12px;
    }

    .image-select-header {
        padding: 16px 16px 12px;
    }

    .image-select-header h3 {
        font-size: 16px;
    }

    .image-select-header p {
        font-size: 13px;
    }

    .image-select-actions-top {
        padding: 10px 16px;
    }

    .image-select-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 12px 16px;
    }

    .image-select-actions {
        padding: 12px 16px;
        gap: 10px;
    }

    .image-select-actions button {
        padding: 10px 14px;
        font-size: 14px;
    }
}

/* 반응형 */
@media (max-width: 768px) {
    .container,
    .result-container {
        padding: 40px 16px 32px;
    }

    .header h1 {
        font-size: 26px;
    }

    .card, .loading-card, .comic {
        padding: 20px;
    }

    .meeting-input {
        min-height: 180px;
        font-size: 16px; /* 모바일에서 확대 방지 */
        padding: 14px;
    }

    button {
        padding: 16px 20px;
        font-size: 16px;
        border-radius: 10px;
        min-height: 48px; /* 터치 타겟 권장 */
    }

    .panels {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .footer-links {
        flex-direction: column;
        gap: 12px;
    }

    .footer-links a {
        font-size: 14px;
    }

    .viewer-nav {
        width: 40px;
        height: 40px;
    }
    
    .viewer-nav svg {
        width: 24px;
        height: 24px;
    }

    .viewer-prev { left: 12px; }
    .viewer-next { right: 12px; }

    .viewer-img {
        max-width: 95vw;
        max-height: 75vh;
    }

    .loading-card {
        padding: 24px 16px;
    }

    .progress-text {
        font-size: 12px;
    }

    .rotating-message {
        font-size: 14px;
    }

    .tip-text {
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .container,
    .result-container {
        padding: 32px 12px 28px;
    }

    .header h1 {
        font-size: 22px;
        margin-bottom: 6px;
    }

    .header p {
        font-size: 13px;
    }

    .greeting {
        font-size: 12px;
        padding: 5px 12px;
        margin-top: 10px;
    }

    .card, .loading-card, .comic {
        padding: 16px;
        border-radius: 10px;
    }

    .meeting-input {
        min-height: 160px;
        font-size: 16px;
        padding: 12px;
        max-height: 400px;
        border-radius: 8px;
    }

    button {
        padding: 14px 16px;
        font-size: 15px;
        min-height: 44px;
        border-radius: 8px;
    }

    form {
        gap: 14px;
    }

    .panels {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .panel img {
        border-radius: 6px;
    }

    .download-btn {
        width: 100%;
        justify-content: center;
        padding: 12px 14px;
        font-size: 13px;
    }

    .footer {
        margin-top: 40px;
        padding-top: 20px;
    }

    .footer-links {
        gap: 8px;
        margin-bottom: 12px;
    }

    .footer-links a {
        font-size: 12px;
    }

    .footer-contact {
        font-size: 11px;
    }

    .comic h2 {
        font-size: 13px;
        margin-bottom: 12px;
    }

    .panel p {
        font-size: 12px;
        margin-top: 6px;
    }

    .back-link {
        font-size: 13px;
        margin-top: 24px;
        gap: 4px;
    }

    .viewer-overlay {
        z-index: 1001;
    }

    .viewer-close {
        top: 12px;
        right: 12px;
        padding: 6px;
        width: 32px;
        height: 32px;
    }

    .viewer-close svg {
        width: 20px;
        height: 20px;
    }

    .viewer-nav {
        width: 36px;
        height: 36px;
    }
    
    .viewer-nav svg {
        width: 20px;
        height: 20px;
    }

    .viewer-prev { left: 8px; }
    .viewer-next { right: 8px; }

    .viewer-img {
        max-width: 98vw;
        max-height: 70vh;
    }

    .viewer-caption {
        margin-top: 12px;
        font-size: 12px;
        max-width: 90vw;
        padding: 0 12px;
    }

    .viewer-counter {
        font-size: 11px;
        bottom: 16px;
    }

    .loading-card {
        padding: 20px 12px;
    }

    .loading-animation {
        margin-bottom: 20px;
        gap: 5px;
    }

    .loading-dot {
        width: 6px;
        height: 6px;
    }

    .progress-container {
        margin-bottom: 20px;
    }

    .progress-bar {
        height: 3px;
    }

    .progress-text {
        font-size: 11px;
        margin-top: 6px;
    }

    .message-area {
        min-height: 50px;
    }

    .status-badge {
        font-size: 11px;
        padding: 3px 8px;
        margin-bottom: 10px;
    }

    .rotating-message {
        font-size: 13px;
    }

    .tip-area {
        margin-top: 16px;
        padding-top: 16px;
    }

    .tip-text {
        font-size: 11px;
        gap: 4px;
    }

    .error-message {
        font-size: 13px;
        padding: 12px;
    }

    .comic-container {
        gap: 16px;
    }
}

/* 매우 작은 화면 (320px 이하) */
@media (max-width: 380px) {
    .container,
    .result-container {
        padding: 28px 10px 24px;
    }

    .header h1 {
        font-size: 20px;
    }

    .header p {
        font-size: 12px;
    }

    .card, .loading-card, .comic {
        padding: 14px;
    }

    button {
        padding: 13px 14px;
        font-size: 14px;
        min-height: 40px;
    }

    .meeting-input {
        min-height: 140px;
        font-size: 15px;
        padding: 10px;
    }

    .viewer-nav {
        width: 32px;
        height: 32px;
    }

    .viewer-close {
        width: 28px;
        height: 28px;
    }
}
