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

:root {
    --bg: #ffffff;
    --text: #1d1d1f;
    --text-2: #86868b;
    --border: #e5e5e7;
    --user-bg: #f5f5f7;
    --accent: #1d1d1f;
    --radius: 12px;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 680px;
    margin: 0 auto;
}

header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    flex-shrink: 0;
}

.logo {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}

.session {
    font-size: 12px;
    color: var(--text-2);
}

.header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.username-display {
    font-size: 13px;
    color: var(--text-2);
}

.logout-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-2);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.logout-btn:hover {
    border-color: var(--text-2);
    color: var(--text);
    opacity: 1;
}

main {
    flex: 1;
    overflow-y: auto;
    padding: 0 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.message {
    max-width: 100%;
}

.message .role {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 4px;
    letter-spacing: 0.02em;
}

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

.message .content {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
}

.message.user .content {
    background: var(--user-bg);
    padding: 12px 16px;
    border-radius: var(--radius);
}

.message.error .content {
    color: #d00;
}

.message.system {
    text-align: center;
    color: var(--text-2);
    font-size: 13px;
    padding: 40px 0 20px;
}

/* Markdown */

.message .content p { margin: 0 0 8px; }
.message .content p:last-child { margin: 0; }

.message .content code {
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 13px;
    background: var(--user-bg);
    padding: 2px 6px;
    border-radius: 4px;
}

.message .content pre {
    background: #1d1d1f;
    color: #f5f5f7;
    padding: 14px 16px;
    border-radius: 8px;
    margin: 8px 0;
    overflow-x: auto;
}

.message .content pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: 13px;
}

.message .content ul, .message .content ol {
    padding-left: 20px;
    margin: 8px 0;
}

.message .content li { margin: 4px 0; }

.message .content h1, .message .content h2, .message .content h3 {
    font-size: 15px;
    font-weight: 600;
    margin: 16px 0 4px;
}

.message .content blockquote {
    border-left: 2px solid var(--border);
    padding-left: 12px;
    color: var(--text-2);
    margin: 8px 0;
}

.message .content table {
    border-collapse: collapse;
    width: 100%;
    font-size: 14px;
    margin: 8px 0;
}

.message .content th, .message .content td {
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}

.message .content th {
    font-weight: 600;
    font-size: 12px;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.message .content strong { font-weight: 600; }

.message .content a {
    color: var(--text);
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* Tool use indicators */

.message.tool-use {
    padding: 0;
    margin: -16px 0;
}

.message.tool-use .content {
    font-size: 13px;
    color: var(--text-2);
    padding: 4px 0;
    line-height: 1.4;
}

.message.tool-use .tool-name {
    font-weight: 500;
}

.message.tool-use .tool-detail {
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 12px;
    opacity: 0.7;
}

/* Typing */

.typing {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing span {
    width: 6px;
    height: 6px;
    background: var(--text-2);
    border-radius: 50%;
    animation: pulse 1.2s ease infinite;
}

.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes pulse {
    0%, 60%, 100% { opacity: 0.2; transform: scale(1); }
    30% { opacity: 1; transform: scale(1.1); }
}

/* Footer */

footer {
    padding: 0 20px 20px;
    flex-shrink: 0;
}

.input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px 4px 4px 16px;
    transition: border-color 0.15s;
}

.input-row:focus-within {
    border-color: var(--text-2);
}

textarea {
    flex: 1;
    border: none;
    background: none;
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    padding: 8px 0;
    resize: none;
    outline: none;
    min-height: 24px;
    max-height: 200px;
}

textarea::placeholder {
    color: var(--text-2);
}

button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: center;
    transition: opacity 0.15s;
}

button:hover { opacity: 0.7; }
button:disabled { opacity: 0.2; cursor: default; }

/* Scrollbar */

main::-webkit-scrollbar { width: 0; }

/* Auth Screen */

.auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    padding: 20px;
}

.auth-card {
    width: 100%;
    max-width: 320px;
    text-align: center;
}

.auth-title {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 32px;
    color: var(--text);
}

.auth-card input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
    outline: none;
    margin-bottom: 10px;
    transition: border-color 0.15s;
}

.auth-card input:focus {
    border-color: var(--text-2);
}

.auth-card input::placeholder {
    color: var(--text-2);
}

.auth-btn {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-family: inherit;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    height: auto;
    margin-top: 4px;
    transition: opacity 0.15s;
}

.auth-btn:hover {
    opacity: 0.8;
}

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

.auth-btn-secondary:hover {
    border-color: var(--text-2);
    opacity: 1;
}

.auth-error {
    color: #d00;
    font-size: 13px;
    margin-top: 12px;
    min-height: 20px;
}

.auth-switch {
    margin-top: 16px;
    font-size: 13px;
    color: var(--text-2);
}

.auth-switch a {
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
}

.auth-switch a:hover {
    text-decoration: underline;
}

.pending-message {
    padding: 24px 0;
}

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

.pending-sub {
    font-size: 13px;
    color: var(--text-2);
    margin-top: 4px;
}

@media (max-width: 600px) {
    #app { max-width: 100%; }
    main { padding: 0 16px 16px; }
    footer { padding: 0 16px 16px; }
}
