:root {
    --bg-dark: #090d16;
    --bg-darker: #05070c;
    --bg-card: rgba(15, 23, 42, 0.45);
    --border-color: rgba(255, 255, 255, 0.08);
    --primary: #8b5cf6;
    --primary-glow: rgba(139, 92, 246, 0.4);
    --primary-hover: #a78bfa;
    --secondary: #ec4899;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-blur: blur(16px);
}

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

body {
    font-family: 'Inter', 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    position: relative;
}

/* 背景グロー装飾 */
.bg-glow {
    position: absolute;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(139, 92, 246, 0.12) 0%, rgba(236, 72, 153, 0.05) 50%, transparent 100%);
    top: -100px;
    right: -100px;
    z-index: -1;
    pointer-events: none;
    filter: blur(80px);
}

/* 全体コンテナ */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
}

/* ヘッダー */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 32px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

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

.divider {
    color: var(--border-color);
}

.logo-icon {
    font-size: 2rem;
}

.title-group h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.title-group p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ボタン共通 */
.btn {
    font-family: inherit;
    font-weight: 600;
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.25);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(139, 92, 246, 0.4);
}

.btn-secondary {
    background: var(--glass-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    backdrop-filter: var(--glass-blur);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: 6px;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 1rem;
    border-radius: 10px;
}

.btn-block {
    width: 100%;
}

/* メインレイアウト */
.app-main {
    display: grid;
    grid-template-columns: 440px 1fr;
    gap: 32px;
    flex: 1;
}

/* コントロールパネル */
.control-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    backdrop-filter: var(--glass-blur);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    height: fit-content;
}

.control-group {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 20px;
}

.control-group:last-of-type {
    border-bottom: none;
    padding-bottom: 0;
}

.control-group h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-main);
}

.desc-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    line-height: 1.4;
}

code {
    background: rgba(255,255,255,0.08);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: monospace;
    color: var(--secondary);
}

/* テンプレートエディタテキストエリア */
#template-editor-textarea {
    width: 100%;
    height: 120px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.85rem;
    line-height: 1.4;
    resize: vertical;
    outline: none;
}

#template-editor-textarea:focus {
    border-color: var(--primary);
}

/* セレクトフィールド */
.select-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.select-field label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.select-field select {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    padding: 10px;
    border-radius: 8px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
}

.select-field select:disabled, 
.input-group input:disabled, 
.input-group button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.badge-pro {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #000;
    font-size: 0.7rem;
    padding: 1px 5px;
    border-radius: 4px;
    font-weight: 700;
    margin-left: 4px;
    text-transform: uppercase;
}

/* 動的変数フォーム */
.variable-forms {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 250px;
    overflow-y: auto;
    padding-right: 4px;
}

.placeholder-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    padding: 20px 0;
}

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

.form-field label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.form-field input, .form-field textarea {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
}

.form-field input:focus, .form-field textarea:focus {
    border-color: var(--primary);
}

/* プレビューパネル */
.preview-panel {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.preview-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    backdrop-filter: var(--glass-blur);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-height: 400px;
}

.preview-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.15);
}

.preview-title {
    font-weight: 600;
    font-size: 0.95rem;
}

.preview-controls {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-body-textarea {
    flex: 1;
    display: flex;
    padding: 16px;
    background: #060913;
}

#final-prompt-textarea {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    color: var(--neon-blue);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
    resize: none;
    outline: none;
}

/* アクション */
.action-section {
    display: flex;
}

/* フッター */
.app-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.footer-fund-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.footer-fund-info a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.footer-fund-info a:hover {
    text-decoration: underline;
}

/* 入力グループ */
.input-group {
    display: flex;
    gap: 8px;
}

.input-group input {
    flex: 1;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
}

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

/* モーダル */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 7, 12, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: #0f172a;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    width: 520px;
    max-width: 90%;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}

.modal-body {
    padding: 24px;
}

.modal-fund-box {
    background: rgba(251, 191, 36, 0.05);
    border: 1px solid rgba(251, 191, 36, 0.15);
    border-radius: 10px;
    padding: 16px;
    margin: 16px 0 24px 0;
}

.modal-fund-box h4 {
    color: #fbbf24;
    margin-bottom: 8px;
    font-size: 0.95rem;
    font-weight: 600;
}

.modal-fund-box p {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.modal-action-links {
    display: flex;
    justify-content: center;
}

.unlock-form label {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 10px;
}

.error-msg {
    color: #ef4444;
    font-size: 0.8rem;
    margin-top: 8px;
    font-weight: 500;
}

/* トースト */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid var(--primary);
    box-shadow: 0 10px 25px rgba(139, 92, 246, 0.2);
    color: var(--text-main);
    padding: 12px 24px;
    border-radius: 8px;
    z-index: 2000;
    font-size: 0.85rem;
    font-weight: 500;
    transition: opacity 0.3s, transform 0.3s;
    transform: translateY(0);
}

.hidden {
    display: none !important;
}

/* レスポンシブ */
@media (max-width: 900px) {
    .app-main {
        grid-template-columns: 1fr;
    }
}
