:root {
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --focus-ring: rgba(59, 130, 246, 0.5);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 72px 20px 40px;
    position: relative;
    overflow-x: hidden;
}

.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.blob {
    position: absolute;
    filter: blur(80px);
    opacity: 0.5;
    border-radius: 50%;
    animation: float 20s infinite ease-in-out alternate;
}

.blob-1 {
    top: -10%;
    left: -10%;
    width: 500px;
    height: 500px;
    background: #3b82f6;
    animation-delay: 0s;
}

.blob-2 {
    bottom: -20%;
    right: -10%;
    width: 600px;
    height: 600px;
    background: #8b5cf6;
    animation-delay: -5s;
}

.blob-3 {
    top: 40%;
    left: 50%;
    width: 400px;
    height: 400px;
    background: #0ea5e9;
    transform: translateX(-50%);
    animation-delay: -10s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(50px, 50px) scale(1.1); }
}

.container {
    width: 100%;
    max-width: 800px;
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 40px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

header {
    text-align: center;
    margin-bottom: 40px;
}

h1 {
    font-size: 2.5rem;
    font-weight: 600;
    margin-bottom: 10px;
    background: linear-gradient(to right, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.top-auth {
    position: fixed;
    top: 18px;
    right: 20px;
    z-index: 20;
    display: grid;
    justify-items: end;
    width: min(380px, calc(100vw - 32px));
}

.top-auth-btn {
    min-width: 76px;
    border: 1px solid rgba(147, 197, 253, 0.42);
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.72);
    color: #dbeafe;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.2;
    padding: 10px 16px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    transition: all 0.2s ease;
}

.top-auth-btn:hover {
    background: rgba(30, 41, 59, 0.88);
    border-color: rgba(191, 219, 254, 0.58);
}

.auth-popover {
    width: 100%;
    max-height: calc(100vh - 76px);
    overflow: auto;
    margin-top: 10px;
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.92);
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.38);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.auth-box,
.account-box {
    display: grid;
    gap: 10px;
    align-items: center;
}

.auth-box {
    grid-template-columns: minmax(0, 1fr);
}

.account-box {
    grid-template-columns: minmax(0, 1fr);
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.auth-action-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.google-login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    min-height: 42px;
    border: 1px solid rgba(203, 213, 225, 0.3);
    border-radius: 10px;
    background: #ffffff;
    color: #1f2937;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.2;
    padding: 10px 14px;
    transition: all 0.2s ease;
}

.google-login-btn:hover {
    background: #f8fafc;
    border-color: rgba(203, 213, 225, 0.62);
}

.google-mark {
    display: inline-grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    color: #4285f4;
    font-family: Arial, sans-serif;
    font-size: 1rem;
    font-weight: 700;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-secondary);
    font-size: 0.78rem;
    line-height: 1.4;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

#accountEmail {
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#accountBalance {
    color: #bbf7d0;
    font-weight: 600;
}

.billing-panel {
    margin-top: 14px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.billing-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 12px;
}

.billing-header strong {
    font-size: 0.98rem;
    font-weight: 600;
}

.billing-header span {
    color: var(--text-secondary);
    font-size: 0.82rem;
}

.billing-package-list {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
}

.billing-package {
    display: grid;
    gap: 8px;
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.48);
}

.billing-package-title {
    color: var(--text-primary);
    font-size: 0.92rem;
    font-weight: 600;
}

.billing-package-meta {
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.5;
}

.billing-package-total {
    color: #bbf7d0;
    font-size: 0.9rem;
    font-weight: 600;
}

.billing-message {
    min-height: 20px;
    margin-top: 10px;
    color: var(--text-secondary);
    font-size: 0.84rem;
    line-height: 1.5;
}

.billing-message.is-error {
    color: #fca5a5;
}

.billing-message.is-success {
    color: #bbf7d0;
}

.billing-orders-wrap {
    margin-top: 8px;
}

.billing-orders-title {
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 0.82rem;
}

.billing-order-list {
    display: grid;
    gap: 8px;
}

.billing-order {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.billing-order-main {
    min-width: 0;
}

.billing-order-id {
    overflow: hidden;
    color: var(--text-primary);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.billing-order-detail {
    margin-top: 2px;
}

.billing-status {
    border-radius: 999px;
    padding: 3px 8px;
    background: rgba(250, 204, 21, 0.12);
    color: #fde68a;
    white-space: nowrap;
}

.billing-status.is-paid {
    background: rgba(34, 197, 94, 0.14);
    color: #bbf7d0;
}

.api-key-container {
    margin-bottom: 24px;
    animation: fadeInUp 0.5s ease forwards;
}

.api-key-container input {
    width: 100%;
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    padding: 12px 16px;
    transition: all 0.3s ease;
}

.api-key-container input:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.2);
}

.api-key-container input::placeholder {
    color: rgba(148, 163, 184, 0.3);
}

.input-group {
    margin-bottom: 24px;
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInUp 0.5s ease forwards;
}

.input-group:nth-child(2) { animation-delay: 0.1s; }
.input-group:nth-child(3) { animation-delay: 0.2s; }
.input-group:nth-child(4) { animation-delay: 0.3s; }

@keyframes fadeInUp {
    to { opacity: 1; transform: translateY(0); }
}

label {
    display: block;
    font-weight: 500;
    margin-bottom: 8px;
    font-size: 0.95rem;
}

label span {
    color: var(--text-secondary);
    font-weight: 400;
    font-size: 0.85rem;
}

.input-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.input-label-row label {
    margin-bottom: 0;
}

.inline-action-btn {
    flex: 0 0 auto;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
    color: #bfdbfe;
    padding: 5px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.82rem;
    line-height: 1.4;
    transition: all 0.2s ease;
}

.inline-action-btn:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #dbeafe;
}

.inline-action-btn:disabled {
    cursor: wait;
    opacity: 0.7;
}

.mode-toggle {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.mode-btn {
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    padding: 11px 14px;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.mode-btn.is-active {
    background: rgba(59, 130, 246, 0.18);
    border-color: rgba(147, 197, 253, 0.45);
    color: #dbeafe;
}

.name-field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.name-field-grid > div {
    min-width: 0;
}

.prompt-tag-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 10px;
}

.prompt-tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
}

.prompt-tag-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.prompt-tag,
.prompt-tag-add,
.prompt-tag-remove {
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #dbeafe;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    line-height: 1.3;
    transition: all 0.2s ease;
}

.prompt-tag {
    padding: 6px 11px;
}

.prompt-tag-add {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    padding: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.prompt-tag-remove {
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
    padding: 0;
    color: rgba(203, 213, 225, 0.62);
    font-size: 0.9rem;
    line-height: 1;
}

.prompt-tag:hover,
.prompt-tag-add:hover {
    background: rgba(59, 130, 246, 0.18);
    border-color: rgba(147, 197, 253, 0.45);
    color: #eff6ff;
}

.prompt-tag-remove:hover {
    background: rgba(248, 113, 113, 0.14);
    border-color: rgba(248, 113, 113, 0.38);
    color: #fecaca;
}

.prompt-tag.is-selected {
    background: rgba(148, 163, 184, 0.12);
    border-color: rgba(148, 163, 184, 0.16);
    color: rgba(203, 213, 225, 0.45);
}

textarea,
input[type="text"],
input[type="email"],
input[type="password"] {
    width: 100%;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    padding: 16px;
    transition: all 0.3s ease;
    resize: vertical;
}

textarea:focus,
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--focus-ring);
    background: rgba(15, 23, 42, 0.8);
}

textarea::placeholder,
input::placeholder {
    color: rgba(148, 163, 184, 0.5);
}

textarea#context {
    height: 180px;
}

textarea#intent {
    height: 120px;
}

textarea#prompt {
    min-height: 76px;
    resize: vertical;
}

.generate-btn {
    width: 100%;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 16px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 30px;
    animation: fadeInUp 0.5s ease forwards;
    animation-delay: 0.4s;
    opacity: 0;
}

.generate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px -10px rgba(99, 102, 241, 0.8);
}

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

.generate-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.loader {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

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

.result-group {
    margin-top: 40px;
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    animation: fadeIn 0.5s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

.result-header h2 {
    font-size: 1.2rem;
    font-weight: 500;
}

.result-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.copy-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.result-warning {
    color: #f87171;
    font-weight: 700;
    line-height: 1.6;
    margin-bottom: 10px;
    white-space: pre-wrap;
}

.result-content {
    width: 100%;
    min-height: 500px;
    color: #e2e8f0;
    line-height: 1.6;
    outline: none;
    padding: 16px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    border: 1px solid transparent;
    resize: vertical;
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

@media (max-width: 600px) {
    .container {
        padding: 24px;
    }
    h1 {
        font-size: 2rem;
    }
    .name-field-grid {
        grid-template-columns: 1fr;
    }
    .auth-box,
    .account-box {
        grid-template-columns: 1fr;
    }
    .billing-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }
    .billing-package-list {
        grid-template-columns: 1fr;
    }
    .billing-order {
        grid-template-columns: minmax(0, 1fr);
    }
    .result-header {
        align-items: flex-start;
        flex-direction: column;
    }
}
