: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: 380px 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);
}

/* 各コントロールのボタンレイアウト */
.grid-buttons, .tool-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.grid-buttons {
    grid-template-columns: repeat(3, 1fr);
}

.grid-buttons button.active, .tool-buttons button.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary-hover);
}

.checkbox-field {
    margin-top: 10px;
}

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

.checkbox-label input[type="checkbox"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

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

/* カラーパレット */
.palette-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
}

.color-tile {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: transform 0.1s, border-color 0.1s;
}

.color-tile:hover {
    transform: scale(1.1);
}

.color-tile.active {
    border: 2px solid #fff;
    box-shadow: 0 0 8px var(--primary-glow);
}

.color-picker-field {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.color-picker-field input[type="color"] {
    -webkit-appearance: none;
    border: none;
    width: 40px;
    height: 30px;
    border-radius: 6px;
    cursor: pointer;
    background: none;
}

.color-picker-field input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-picker-field input[type="color"]::-webkit-color-swatch {
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

/* アニメーションフレーム */
.frame-list-wrapper {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 4px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    min-height: 60px;
}

.frame-thumb {
    width: 44px;
    height: 44px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
    background-color: #1a202c;
    /* チェッカー背景 */
    background-image: 
        linear-gradient(45deg, #2d3748 25%, transparent 25%), 
        linear-gradient(-45deg, #2d3748 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #2d3748 75%), 
        linear-gradient(-45deg, transparent 75%, #2d3748 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
}

.frame-thumb canvas {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

.frame-thumb.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary);
}

.frame-thumb span {
    position: absolute;
    bottom: 0;
    right: 2px;
    font-size: 0.6rem;
    font-weight: bold;
    color: #fff;
    background: rgba(0, 0, 0, 0.6);
    padding: 0 3px;
    border-radius: 2px;
}

.slider-field {
    margin-bottom: 12px;
}

.slider-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.slider-label .val {
    font-weight: 600;
    color: var(--text-main);
}

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

/* プレビューパネル & キャンバスカード */
.preview-panel {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.canvas-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: 420px;
}

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

.canvas-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px;
    position: relative;
    background-color: #1a202c;
    /* 大きめのチェッカー背景 */
    background-image: 
        linear-gradient(45deg, #2d3748 25%, transparent 25%), 
        linear-gradient(-45deg, #2d3748 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #2d3748 75%), 
        linear-gradient(-45deg, transparent 75%, #2d3748 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.canvas-wrapper canvas {
    position: absolute;
    width: 400px;
    height: 400px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    cursor: crosshair;
}

#grid-canvas {
    pointer-events: none; /* マウスイベントを下のpaint-canvasに透過させる */
}

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

.action-section .btn {
    flex: 1;
}

/* フッター */
.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;
    }
    .canvas-wrapper canvas {
        width: 320px;
        height: 320px;
    }
    .canvas-card {
        min-height: 340px;
    }
}
