:root {
    --bg: #0f0f14;
    --surface: #1a1a24;
    --surface-hover: #252532;
    --primary: #10b981;
    --primary-hover: #059669;
    --accent: #8b5cf6;
    --danger: #ef4444;
    --warning: #f59e0b;
    --text: #f4f4f5;
    --text-muted: #a1a1aa;
    --border: #27272a;
    --code-bg: #18181b;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

.hidden {
    display: none !important;
}

/* Navigation */
nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
}

.logo span {
    color: var(--primary);
}

.nav-links {
    display: flex;
    gap: 1.5rem;
}

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.95rem;
    transition: color 0.2s;
}

.nav-links a:hover, .nav-links a.active {
    color: var(--primary);
}

/* Main Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* Hero Section */
.hero {
    text-align: center;
    padding: 4rem 0 3rem;
}

.hero h1 {
    font-size: 3rem;
    margin-bottom: 0.75rem;
    font-weight: 700;
}

.hero h1 span {
    color: var(--primary);
}

.hero .tagline {
    font-size: 1.25rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.hero .features {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.hero .features span {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.hero .features .check {
    color: var(--primary);
}

/* Generate Input Section */
.generate-section {
    max-width: 800px;
    margin: 0 auto 2rem;
}

.input-group {
    position: relative;
}

.main-input {
    width: 100%;
    padding: 1.25rem 1.5rem;
    padding-right: 150px;
    font-size: 1.1rem;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}

.main-input:focus {
    border-color: var(--primary);
}

.main-input::placeholder {
    color: var(--text-muted);
}

.generate-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.generate-btn:hover {
    background: var(--primary-hover);
}

.generate-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.example-text {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.example-text code {
    background: var(--surface);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

/* Divider */
.divider {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 2rem 0;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

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

.divider span {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 3rem;
}

.action-btn {
    padding: 0.875rem 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn:hover {
    background: var(--surface-hover);
    border-color: var(--primary);
}

/* Featured Templates */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.section-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.section-header a {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.95rem;
}

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1.5rem;
    margin-bottom: 4rem;
}

.template-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    transition: all 0.2s;
}

.template-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.template-card h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.template-card p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
    line-height: 1.5;
}

.template-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.tag {
    padding: 0.25rem 0.75rem;
    background: var(--code-bg);
    border-radius: 999px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.template-actions {
    display: flex;
    gap: 0.75rem;
}

.template-actions button {
    flex: 1;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-view {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-view:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-use {
    background: var(--primary);
    border: none;
    color: white;
}

.btn-use:hover {
    background: var(--primary-hover);
}

/* Views/Panels */
.view {
    display: none;
}

.view.active {
    display: block;
}

/* Result View */
.result-container {
    max-width: 1100px;
    margin: 2rem auto 4rem;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.result-header h2 {
    font-size: 1.25rem;
}

.back-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.result-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 1.5rem;
}

@media (max-width: 900px) {
    .result-grid {
        grid-template-columns: 1fr;
    }
}

.code-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--code-bg);
    border-bottom: 1px solid var(--border);
}

.code-header span {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.copy-btn {
    padding: 0.4rem 0.75rem;
    background: var(--surface-hover);
    border: none;
    border-radius: 4px;
    color: var(--text);
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.2s;
}

.copy-btn:hover {
    background: var(--primary);
}

.code-content {
    padding: 1rem;
    overflow-x: auto;
    max-height: 600px;
    overflow-y: auto;
}

.code-content pre {
    margin: 0;
    background: transparent !important;
}

.code-content code {
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
}

.sidebar-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.sidebar-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
}

.sidebar-card h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    font-size: 0.9rem;
}

.status-ok {
    color: var(--primary);
}

.status-error {
    color: var(--danger);
}

.status-warning {
    color: var(--warning);
}

.action-list button {
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
}

.action-list button:hover {
    border-color: var(--primary);
}

.action-list button:last-child {
    margin-bottom: 0;
}

/* Edit Request */
.edit-request {
    margin-top: 1.5rem;
}

.edit-input-group {
    display: flex;
    gap: 0.5rem;
}

.edit-input {
    flex: 1;
    padding: 0.75rem 1rem;
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
}

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

.edit-btn {
    padding: 0.75rem 1.25rem;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
}

.edit-btn:hover {
    opacity: 0.9;
}

/* Fix/Judge View */
.fix-container {
    max-width: 900px;
    margin: 2rem auto 4rem;
}

.fix-container h2 {
    margin-bottom: 1.5rem;
}

.script-input {
    width: 100%;
    min-height: 300px;
    padding: 1rem;
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.9rem;
    resize: vertical;
    margin-bottom: 1rem;
}

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

.fix-btn {
    padding: 0.875rem 2rem;
    background: var(--primary);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.fix-btn:hover {
    background: var(--primary-hover);
}

.fix-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Issues List */
.issues-list {
    margin-top: 1.5rem;
}

.issue {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.issue.error {
    border-left: 3px solid var(--danger);
}

.issue.warning {
    border-left: 3px solid var(--warning);
}

.issue-line {
    color: var(--text-muted);
    font-weight: 500;
}

.issue-rule {
    color: var(--accent);
}

/* Review View */
.review-output {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-top: 1.5rem;
}

.review-output h3 {
    color: var(--text);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
}

.review-output h3:first-child {
    margin-top: 0;
}

.review-output ul {
    margin-left: 1.5rem;
    color: var(--text-muted);
}

.review-output li {
    margin-bottom: 0.5rem;
}

.review-output p {
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

/* Templates Gallery */
.gallery-header {
    padding: 2rem 0;
}

.gallery-header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.gallery-header p {
    color: var(--text-muted);
}

.filter-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.filter-tab {
    padding: 0.5rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-tab:hover, .filter-tab.active {
    border-color: var(--primary);
    color: var(--primary);
}

/* Template Detail View */
.template-detail {
    max-width: 1100px;
    margin: 2rem auto 4rem;
}

.template-detail-header {
    margin-bottom: 1.5rem;
}

.template-detail-header h1 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}

.template-detail-header p {
    color: var(--text-muted);
}

.template-detail-grid {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 1.5rem;
}

@media (max-width: 900px) {
    .template-detail-grid {
        grid-template-columns: 1fr;
    }
}

.template-about h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.template-about p, .template-about li {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.template-about ul {
    margin-left: 1.25rem;
    margin-bottom: 1.25rem;
}

.template-about section {
    margin-bottom: 1.5rem;
}

/* Loading */
.loading {
    display: none;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 0;
    color: var(--text-muted);
}

.loading.active {
    display: flex;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Footer */
footer {
    text-align: center;
    padding: 2rem;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.9rem;
}

footer a {
    color: var(--primary);
    text-decoration: none;
}

/* Intent input for review */
.intent-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

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

/* Badge for success */
.success-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(16, 185, 129, 0.15);
    color: var(--primary);
    border-radius: 6px;
    font-size: 0.9rem;
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
    z-index: 1000;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success {
    border-color: var(--primary);
}

/* Auth UI */
.auth-area {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.usage-badge {
    padding: 0.25rem 0.75rem;
    background: var(--surface-hover);
    border-radius: 12px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.usage-badge.pro {
    background: linear-gradient(135deg, var(--accent), var(--primary));
    color: white;
}

.auth-btn {
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.auth-btn:hover {
    background: var(--surface-hover);
    border-color: var(--primary);
}

.auth-btn.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.auth-btn.primary:hover {
    background: var(--primary-hover);
}

.user-email {
    color: var(--text-muted);
    font-size: 0.85rem;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Auth Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.2s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    position: relative;
}

.modal-content h2 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

.modal-content .close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.modal-content .close-btn:hover {
    color: var(--text);
}

.modal-content input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 1rem;
    margin-bottom: 1rem;
}

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

.modal-content button[type="submit"] {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary);
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.modal-content button[type="submit"]:hover {
    background: var(--primary-hover);
}

.auth-toggle {
    margin-top: 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.auth-toggle a {
    color: var(--primary);
    text-decoration: none;
}

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

.auth-error {
    color: var(--danger);
    font-size: 0.9rem;
    margin-top: 0.5rem;
    text-align: center;
}

.auth-error.hidden {
    display: none;
}
