*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: radial-gradient(circle at top left, #1d3557, #0b1320 55%, #000000 100%);
    color: #f1f5f9;
}

.app-container {
    min-height: 100vh;
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 16px 40px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.app-header {
    text-align: center;
    margin-bottom: 4px;
}

.app-header h1 {
    margin: 0;
    font-size: 1.8rem;
    letter-spacing: 0.03em;
}

.subtitle {
    margin: 4px 0 0;
    color: #cbd5f5;
    font-size: 0.9rem;
}

.subtitle.small {
    font-size: 0.8rem;
}

.card {
    background: rgba(15, 23, 42, 0.9);
    border-radius: 16px;
    padding: 16px 18px 18px;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(148, 163, 184, 0.35);
    backdrop-filter: blur(12px);
}

.chat-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 360px;
}

h2 {
    margin: 0 0 8px;
    font-size: 1.1rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
    font-size: 0.9rem;
}

.field span {
    color: #e5e7eb;
}

select,
textarea {
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.6);
    padding: 8px 10px;
    font-size: 0.9rem;
    background: rgba(15, 23, 42, 0.9);
    color: #e5e7eb;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

select:focus,
textarea:focus {
    border-color: #38bdf8;
    box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.7);
    background-color: rgba(15, 23, 42, 1);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
}

button {
    border-radius: 999px;
    border: none;
    padding: 8px 14px;
    font-size: 0.9rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background-color 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease,
    opacity 0.15s ease;
    font-weight: 500;
}

button.primary {
    background: linear-gradient(135deg, #38bdf8, #0ea5e9);
    color: #0f172a;
    box-shadow: 0 6px 18px rgba(56, 189, 248, 0.45);
}

button.primary:hover {
    background: linear-gradient(135deg, #0ea5e9, #06b6d4);
    transform: translateY(-1px);
    box-shadow: 0 10px 25px rgba(56, 189, 248, 0.55);
}

button.secondary {
    background: rgba(15, 23, 42, 0.9);
    color: #e5e7eb;
    border: 1px solid rgba(148, 163, 184, 0.8);
}

button.secondary:hover {
    background: rgba(30, 64, 175, 0.8);
    border-color: rgba(129, 140, 248, 0.95);
}

button.ghost {
    background: transparent;
    color: #e5e7eb;
    border: 1px solid rgba(148, 163, 184, 0.4);
    padding-inline: 10px;
    font-size: 0.8rem;
}

button.ghost:hover {
    background: rgba(30, 64, 175, 0.7);
    border-color: rgba(129, 140, 248, 0.9);
}

button:active {
    transform: translateY(0);
    box-shadow: none;
}

button:disabled {
    opacity: 0.5;
    cursor: default;
    box-shadow: none;
}

.hint {
    margin-top: 6px;
    font-size: 0.78rem;
    color: #9ca3af;
}

.accordion {
    margin-top: 8px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(15, 23, 42, 0.75);
    padding: 6px 10px;
}

.accordion summary {
    cursor: pointer;
    font-size: 0.85rem;
    color: #cbd5f5;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.accordion summary::before {
    content: "▶";
    font-size: 0.7rem;
    transition: transform 0.15s ease;
}

.accordion[open] summary::before {
    transform: rotate(90deg);
}

.accordion span,
.accordion p {
    display: block;
    margin: 8px 2px 4px;
    color: #9ca3af;
    font-size: 0.78rem;
}

.chat-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 8px;
}

.header-menu {
    display: block;
    position: relative;
    width: 100%;
}

.header-menu summary {
    list-style: none;
}

.header-menu summary::-webkit-details-marker {
    display: none;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.header-menu summary {
    display: inline-flex;
}

.icon-button {
    padding: 6px 10px;
}

.icon-button svg {
    width: 16px;
    height: 16px;
}

.icon-button .label {
    white-space: nowrap;
}

.chat-log {
    flex: 1;
    padding: 10px;
    border-radius: 12px;
    background: radial-gradient(circle at top, rgba(30, 64, 175, 0.4), rgba(15, 23, 42, 0.95));
    border: 1px solid rgba(148, 163, 184, 0.5);
    overflow-y: auto;
    max-height: 480px;
}

.message-row {
    display: flex;
    margin-bottom: 8px;
}

.message-row.user {
    justify-content: flex-end;
}

.message-bubble {
    max-width: 80%;
    padding: 8px 10px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-row.user .message-bubble {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: #052e16;
    border-bottom-right-radius: 4px;
}

.message-row.assistant .message-bubble {
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(148, 163, 184, 0.8);
    border-bottom-left-radius: 4px;
}

.message-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: #9ca3af;
    margin-bottom: 3px;
}

.chat-input-area {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.chat-input-area textarea {
    flex: 1;
    min-height: 56px;
    max-height: 120px;
}

.app-footer {
    margin-top: 4px;
    text-align: center;
    font-size: 0.75rem;
    color: #9ca3af;
}

.hidden {
    display: none;
}

@media (max-width: 640px) {
    .app-container {
        padding-inline: 10px;
    }

    .app-header h1 {
        font-size: 1.45rem;
    }

    .subtitle {
        font-size: 0.85rem;
    }

    .card {
        padding: 14px 14px 16px;
    }

    .button-row {
        flex-direction: column;
        align-items: stretch;
    }

    .chat-input-area {
        flex-direction: column;
    }

    .chat-input-area textarea {
        min-height: 80px;
    }

    #send-btn,
    #random-personality-btn,
    #start-chat-btn {
        width: 100%;
    }

    .icon-button .label {
        display: none;
    }

    .header-menu-summary .label {
        display: inline;
    }

    .header-menu summary {
        display: inline-flex;
    }

    #toggle-setup-btn,
    #toggle-subtitle-btn,
    #change-settings-btn {
        width: auto;
        padding-inline: 8px;
    }

    .header-menu .header-actions {
        position: absolute;
        right: 0;
        top: 46px;
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
        padding: 10px;
        background: rgba(15, 23, 42, 0.95);
        border: 1px solid rgba(148, 163, 184, 0.4);
        border-radius: 12px;
        box-shadow: 0 12px 25px rgba(15, 23, 42, 0.5);
        display: none;
        z-index: 5;
    }

    .header-menu[open] .header-actions {
        display: flex;
    }

    .header-menu[open] .icon-button .label {
        display: inline;
    }

    .chat-log {
        max-height: 380px;
    }
}


