: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.1) 0%, rgba(236, 72, 153, 0.03) 50%, transparent 100%);
    bottom: -100px;
    right: -100px;
    z-index: -1;
    pointer-events: none;
    filter: blur(80px);
}

/* 全体コンテナ */
.app-container {
    max-width: 1440px;
    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 18px;
    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-block {
    width: 100%;
}

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

/* カード */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    backdrop-filter: var(--glass-blur);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 24px;
}

.card:last-child {
    margin-bottom: 0;
}

.card h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* パターン入力 */
.regex-input-row {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    gap: 6px;
}

.regex-slash {
    color: var(--text-muted);
    font-family: 'Fira Code', monospace;
    font-size: 1.1rem;
    user-select: none;
}

#regex-pattern {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.95rem;
    outline: none;
    width: 100%;
}

.flags-group {
    display: flex;
    gap: 8px;
    border-left: 1px solid var(--border-color);
    padding-left: 10px;
}

.flag-label {
    font-family: 'Fira Code', monospace;
    font-size: 0.9rem;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 2px;
}

.flag-label input {
    accent-color: var(--primary);
    cursor: pointer;
}

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

/* テンプレートリスト */
.template-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tpl-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 12px;
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tpl-btn:hover {
    background: rgba(139, 92, 246, 0.08);
    border-color: rgba(139, 92, 246, 0.25);
    transform: translateX(4px);
}

/* レイヤードエディタ */
.editor-wrapper {
    position: relative;
    background: #070a13;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    height: 200px;
    overflow: hidden;
}

.backdrop {
    position: absolute;
    z-index: 1;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: auto;
    pointer-events: none;
}

.highlights, #test-text {
    padding: 16px;
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    border: none;
    margin: 0;
    width: 100%;
    height: 100%;
}

.highlights {
    color: transparent;
    overflow: hidden;
}

#test-text {
    position: relative;
    z-index: 2;
    background: transparent;
    color: #e2e8f0;
    resize: none;
    outline: none;
    overflow: auto;
    /* キャレットだけ表示 */
    caret-color: #f8fafc;
}

/* ハイライト表示のマーク */
.highlights mark {
    background-color: rgba(245, 158, 11, 0.35); /* マッチ: オレンジ */
    border-radius: 2px;
    border-bottom: 2px solid rgba(245, 158, 11, 0.8);
    color: transparent;
}

.highlights mark.group-1 {
    background-color: rgba(16, 185, 129, 0.25); /* グループ1: 緑 */
    border-bottom: 2px solid rgba(16, 185, 129, 0.7);
}

.match-counter {
    background: rgba(139, 92, 246, 0.12);
    color: var(--primary-hover);
    font-size: 0.75rem;
    padding: 3px 8px;
    border-radius: 20px;
    border: 1px solid rgba(139, 92, 246, 0.25);
}

/* 解説 & AI カード共通 */
.explainer-body, .ai-body {
    position: relative;
    min-height: 120px;
}

.pro-locked-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(9, 13, 22, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    border-radius: 8px;
    z-index: 5;
    padding: 20px;
}

.pro-locked-overlay p {
    font-size: 0.95rem;
    font-weight: 600;
}

.lock-desc {
    font-size: 0.8rem !important;
    color: var(--text-muted);
    max-width: 320px;
    margin: 8px 0 16px 0;
    line-height: 1.4;
}

/* 解説文のスタイル */
.explainer-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.explainer-item {
    background: rgba(255, 255, 255, 0.02);
    border-left: 3px solid var(--primary);
    padding: 10px 14px;
    border-radius: 0 6px 6px 0;
    font-size: 0.85rem;
    display: flex;
    gap: 10px;
}

.explainer-item code {
    font-family: 'Fira Code', monospace;
    color: var(--secondary);
    background: rgba(0, 0, 0, 0.2);
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 600;
    height: fit-content;
}

.explainer-item span {
    color: #e2e8f0;
    line-height: 1.4;
}

/* AIセクション */
.ai-content-inner label {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 8px;
}

.input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.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);
}

.ai-result-box {
    background: rgba(139, 92, 246, 0.05);
    border: 1px solid rgba(139, 92, 246, 0.15);
    border-radius: 8px;
    padding: 14px;
}

.ai-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.ai-result-box code {
    display: block;
    font-family: 'Fira Code', monospace;
    font-size: 1.1rem;
    color: #fca5a5;
    background: rgba(0, 0, 0, 0.25);
    padding: 10px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    margin-bottom: 8px;
}

.ai-result-box p {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.action-btn {
    background: rgba(139, 92, 246, 0.1);
    border: 1px solid rgba(139, 92, 246, 0.2);
    color: var(--primary-hover);
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 500;
}

.action-btn:hover {
    background: rgba(139, 92, 246, 0.2);
}

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

/* フッター */
.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;
}

/* モーダル */
.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;
}

.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: 12px;
    color: var(--text-main);
    font-family: inherit;
    outline: none;
}

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

.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;
}

.hidden {
    display: none !important;
}

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