/* ==========================================================
   Retro CLI 테마
   app.js 가 사용하는 id / class 는 그대로 두고 스타일만 정의합니다.
   ========================================================== */

:root {
    /* 배경 프레임 */
    --frame-from: #8e54e9;
    --frame-to: #4776e6;

    /* 터미널 */
    --term-bg: #000;
    --term-surface: #0a0a0a;
    --term-chrome: #141414;
    --term-line: #222;
    --term-border: #3a3a3a;

    /* 텍스트 */
    --text: #e4e4e4;
    --text-bright: #fff;
    --text-dim: #8c8c8c;
    --text-faint: #5f5f5f;

    /* ANSI 256색 계열 강조색 */
    --pink: #ff87ff;
    --lavender: #afafff;
    --green: #5fd75f;
    --red: #ff5f5f;

    /* 채팅 영역 위쪽(헤더~탭)과 입력창 아래 여백의 대략적인 높이 */
    --chat-offset: 430px;

    --font-mono: "JetBrains Mono", "Nanum Gothic Coding", "D2Coding", ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    /* 로고는 박스 드로잉/블록 글리프가 있는 시스템 고정폭 폰트로 렌더링 */
    --font-art: "Cascadia Mono", Consolas, ui-monospace, "SF Mono", Menlo, Monaco, "DejaVu Sans Mono", "Liberation Mono", monospace;
}

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

html {
    color-scheme: dark;
}

body {
    font-family: var(--font-mono);
    font-size: 15px;
    line-height: 1.65;
    font-variant-ligatures: none;
    color: var(--text);
    background: linear-gradient(120deg, var(--frame-from) 0%, var(--frame-to) 100%);
    min-height: 100vh;
    padding: clamp(16px, 3vw, 32px);
    -webkit-font-smoothing: antialiased;
}

::selection {
    color: #000;
    background: var(--pink);
}

/* 터미널 창 */
.container {
    max-width: 1120px;
    margin: 0 auto;
    background: var(--term-bg);
    border-radius: 14px;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.08),
        0 30px 80px -12px rgba(28, 12, 80, 0.6);
    overflow: hidden;
}

.term-titlebar {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    padding: 0 16px;
    background: var(--term-chrome);
    border-bottom: 1px solid var(--term-line);
}

.term-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.term-dot-close { background: #ff5f57; }
.term-dot-min { background: #febc2e; }
.term-dot-max { background: #28c840; }

.term-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    color: var(--text-dim);
    white-space: nowrap;
}

/* 헤더: 프롬프트 + ASCII 로고 */
header {
    padding: 22px 32px 0;
}

.term-cwd {
    color: var(--text-dim);
}

.term-command {
    font-weight: 700;
    color: var(--text-bright);
}

.ascii-logo {
    margin: 20px 0 16px 18px;
    font-family: var(--font-art);
    font-size: clamp(7px, 2.3vw, 15px);
    line-height: 1.05;
    /* 글리프를 살짝 겹쳐 블록 사이 이음새 제거 */
    letter-spacing: -0.4px;
    color: var(--pink);
    text-shadow: 0 0 10px rgba(255, 135, 255, 0.28);
    overflow: hidden;
}

header h1 {
    margin-left: 18px;
    font-size: 1em;
    font-weight: 400;
    color: var(--text-bright);
}

.tagline {
    margin-top: 14px;
    color: var(--text-bright);
}

/* 기능 선택 (탭) */
.mode-select {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 14px;
    margin: 18px 32px 0;
    padding-bottom: 14px;
    border-bottom: 1px dashed var(--term-border);
}

.mode-question {
    font-weight: 700;
    color: var(--text-bright);
}

.term-check {
    color: var(--green);
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.tab-button {
    padding: 2px 10px 2px 4px;
    font: inherit;
    color: var(--text-dim);
    background: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: color 0.15s, background-color 0.15s;
}

.tab-button::before {
    content: "❯";
    display: inline-block;
    width: 2ch;
    text-align: center;
    color: var(--pink);
    visibility: hidden;
}

.tab-button:hover {
    color: var(--text-bright);
    background: #161616;
}

.tab-button.active {
    font-weight: 700;
    color: var(--lavender);
}

.tab-button.active::before {
    visibility: visible;
}

.tab-button:focus-visible {
    outline: 1px dashed var(--pink);
    outline-offset: 2px;
}

.tab-content {
    display: none;
    padding: 18px 32px 24px;
    min-height: 500px;
}

.tab-content.active {
    display: block;
}

/* 공통 입력 요소 */
input::placeholder,
textarea::placeholder {
    color: var(--text-faint);
    opacity: 1;
}

/* 터미널 버튼: [ 전송 ] */
.term-btn {
    padding: 6px 10px;
    font: inherit;
    font-weight: 700;
    color: var(--pink);
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.12s, background-color 0.12s;
}

.term-btn::before {
    content: "[ ";
}

.term-btn::after {
    content: " ]";
}

.term-btn:hover {
    color: #000;
    background: var(--pink);
}

.term-btn:active {
    transform: translateY(1px);
}

.term-btn:focus-visible {
    outline: 1px dashed var(--pink);
    outline-offset: 2px;
}

.term-btn-muted {
    color: var(--text-dim);
}

.term-btn-muted:hover {
    color: #000;
    background: var(--text-dim);
}

/* 채팅 스타일 */
/* 헤더 아래 남은 화면 높이에 맞춰 첫 화면에서 입력창이 보이도록 함 */
.chat-container {
    display: flex;
    flex-direction: column;
    height: clamp(320px, calc(100vh - var(--chat-offset)), 600px);
}

@supports (height: 100svh) {
    .chat-container {
        height: clamp(320px, calc(100svh - var(--chat-offset)), 600px);
    }
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding-right: 8px;
    margin-bottom: 16px;
}

.chat-messages:empty::before {
    content: "# 아직 대화가 없습니다. 아래 프롬프트에 메시지를 입력하고 Enter 를 누르세요.";
    color: var(--text-faint);
}

.message {
    margin-bottom: 18px;
    overflow-wrap: anywhere;
}

.message-content {
    line-height: 1.7;
    white-space: pre-wrap;
}

/* 사용자 입력: "👤 사용자 ❯ 메시지" */
.message.user {
    display: flex;
    align-items: baseline;
    gap: 1ch;
}

.message.user .message-header {
    flex: none;
    font-weight: 700;
    color: var(--lavender);
}

.message.user .message-header::after {
    content: " ❯";
    color: var(--pink);
}

.message.user .message-content {
    min-width: 0;
    font-weight: 700;
    color: var(--text-bright);
}

/* AI 응답: "✔ 🤖 AI" + 들여쓴 본문 */
.message.assistant .message-header {
    font-weight: 700;
    color: var(--text-bright);
}

.message.assistant .message-header::before {
    content: "✔ ";
    color: var(--green);
}

.message.assistant .message-content,
.message.assistant .usage-info {
    padding-left: 2ch;
}

.usage-info {
    margin-top: 6px;
    font-size: 0.85em;
    color: var(--text-dim);
}

.chat-input-container {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 6px 6px 16px;
    background: var(--term-surface);
    border: 1px solid var(--term-border);
    border-radius: 8px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-input-container::before {
    content: "❯";
    font-weight: 700;
    color: var(--pink);
}

.chat-input-container:focus-within {
    border-color: var(--pink);
    box-shadow: 0 0 0 3px rgba(255, 135, 255, 0.12);
}

.chat-input-container input {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    font: inherit;
    color: var(--text-bright);
    background: transparent;
    border: none;
    outline: none;
    caret-color: var(--pink);
}

/* 멀티모달 스타일 */
.multimodal-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.input-section {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field-label {
    font-weight: 700;
    color: var(--text-bright);
}

.term-q {
    color: var(--green);
}

.term-hint {
    font-weight: 400;
    color: var(--text-dim);
}

.input-section textarea,
.web-container input[type="url"] {
    width: 100%;
    padding: 10px 14px;
    font: inherit;
    color: var(--text-bright);
    background: var(--term-surface);
    border: 1px solid var(--term-border);
    border-radius: 6px;
    outline: none;
    caret-color: var(--pink);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.input-section textarea {
    resize: vertical;
}

.input-section textarea:focus,
.web-container input[type="url"]:focus {
    border-color: var(--pink);
    box-shadow: 0 0 0 3px rgba(255, 135, 255, 0.12);
}

.file-upload-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.file-label {
    padding: 14px;
    color: var(--lavender);
    text-align: center;
    border: 1px dashed var(--term-border);
    border-radius: 6px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}

.file-label:hover {
    color: var(--pink);
    background: rgba(255, 135, 255, 0.05);
    border-color: var(--pink);
}

.file-upload-section input[type="file"] {
    display: none;
}

.image-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.image-preview:empty {
    display: none;
}

.image-preview-item {
    position: relative;
    width: 96px;
    height: 96px;
    border: 1px solid var(--term-border);
    border-radius: 4px;
    overflow: hidden;
}

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

.image-preview-item .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    font: inherit;
    font-size: 14px;
    line-height: 1;
    color: var(--text-bright);
    background: rgba(0, 0, 0, 0.75);
    border: 1px solid var(--term-border);
    border-radius: 3px;
    cursor: pointer;
}

.image-preview-item .remove-btn:hover {
    color: #000;
    background: var(--red);
    border-color: var(--red);
}

.button-group {
    display: flex;
    gap: 8px;
}

/* 출력 패널 */
.output-pane {
    display: flex;
    flex-direction: column;
    min-height: 220px;
    border: 1px solid var(--term-border);
    border-radius: 6px;
    overflow: hidden;
}

.output-title {
    padding: 6px 14px;
    font-size: 0.8em;
    color: var(--text-dim);
    background: var(--term-chrome);
    border-bottom: 1px solid var(--term-line);
}

.multimodal-response,
.web-response {
    flex: 1;
    padding: 16px;
}

.multimodal-response {
    max-height: 500px;
    overflow-y: auto;
}

.multimodal-response:empty::before,
.web-response:empty::before {
    content: "# 응답이 여기에 출력됩니다.";
    color: var(--text-faint);
}

/* 웹 요약 스타일 */
.web-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.web-container .term-btn {
    align-self: flex-start;
}

/* 로딩 / 오류 */
.loading {
    color: var(--text-dim);
}

.loading::before {
    content: "⠋";
    display: inline-block;
    width: 2ch;
    color: var(--pink);
    animation: term-spinner 0.8s steps(1, end) infinite;
}

.loading::after {
    content: "";
    display: inline-block;
    width: 0.55em;
    height: 1.1em;
    margin-left: 0.4ch;
    vertical-align: text-bottom;
    background: var(--text-dim);
    animation: term-blink 1s steps(1, end) infinite;
}

.error {
    padding: 10px 14px;
    color: var(--red);
    background: rgba(255, 95, 95, 0.08);
    border-left: 2px solid var(--red);
    overflow-wrap: anywhere;
}

@keyframes term-spinner {
    0% { content: "⠋"; }
    10% { content: "⠙"; }
    20% { content: "⠹"; }
    30% { content: "⠸"; }
    40% { content: "⠼"; }
    50% { content: "⠴"; }
    60% { content: "⠦"; }
    70% { content: "⠧"; }
    80% { content: "⠇"; }
    90% { content: "⠏"; }
}

@keyframes term-blink {
    50% { opacity: 0; }
}

/* 상태 표시줄 */
footer {
    display: flex;
    align-items: stretch;
    min-height: 30px;
    font-size: 12px;
    color: var(--text-dim);
    background: var(--term-chrome);
    border-top: 1px solid var(--term-line);
}

.status-badge {
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: #000;
    background: var(--pink);
}

footer p {
    display: flex;
    align-items: center;
    padding: 4px 14px;
}

/* 스크롤바 */
.chat-messages,
.multimodal-response {
    scrollbar-width: thin;
    scrollbar-color: var(--term-border) transparent;
}

/* 반응형 디자인 */
@media (max-width: 768px) {
    body {
        padding: 12px;
        font-size: 14px;
    }

    header {
        padding: 22px 16px 0;
    }

    .mode-select {
        margin: 18px 16px 0;
    }

    .tab-content {
        padding: 16px 16px 20px;
    }

    .term-btn {
        padding: 6px;
    }

    .multimodal-container {
        grid-template-columns: 1fr;
    }

    .term-title {
        display: none;
    }
}

/* 세로가 낮은 화면: 헤더 간격을 줄여 채팅 영역 확보 */
@media (max-height: 820px) {
    :root {
        --chat-offset: 376px;
    }

    body {
        padding-top: 16px;
        padding-bottom: 16px;
    }

    header {
        padding-top: 16px;
    }

    .ascii-logo {
        margin-top: 14px;
        margin-bottom: 10px;
    }

    .tagline {
        margin-top: 8px;
    }

    .mode-select {
        margin-top: 12px;
        padding-bottom: 10px;
    }

    .tab-content {
        padding-top: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}
