:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-main: #f8fafc;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.5);
}

body {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.6;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* 背景の装飾 */
.background-elements {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    overflow: hidden;
}

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

.blob-1 {
    top: -10%;
    left: -10%;
    width: 50vw;
    height: 50vw;
    background: #e0e7ff;
}

.blob-2 {
    bottom: -20%;
    right: -10%;
    width: 60vw;
    height: 60vw;
    background: #dbeafe;
    animation-delay: -5s;
}

.blob-3 {
    top: 40%;
    left: 60%;
    width: 40vw;
    height: 40vw;
    background: #f1f5f9;
    animation-delay: -10s;
}

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

    100% {
        transform: translate(5%, 5%) scale(1.1);
    }
}

.container {
    width: 100%;
    max-width: 1200px;
    padding: 2rem;
    box-sizing: border-box;
}

.header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #1e40af, #3b82f6);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

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

/* 住宅ローン返済比率カラークラス（背景塗りつぶし・白文字） */
.ratio-green {
    background-color: #22c55e !important;
    /* 緑 */
    color: #ffffff !important;
    font-weight: bold;
}

.ratio-yellow {
    background-color: #eab308 !important;
    /* 黄色・注意 */
    color: #ffffff !important;
    font-weight: bold;
}

.ratio-pink {
    background-color: #f472b6 !important;
    /* 淡いピンク (Tailwind pink-400相当) */
    color: #ffffff !important;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
    /* 背景が薄くなったのでシャドウも控えめに */
    font-weight: 700;
}

.ratio-red {
    background-color: #dc2626 !important;
    /* 強めの赤 */
    color: #ffffff !important;
    font-weight: bold;
}

/* ローン差額表示用クラス */
.diff-blue {
    background-color: #3b82f6;
    /* プラスは青・白文字 */
    color: #ffffff;
}

.diff-red {
    background-color: #ef4444;
    /* マイナスは赤・白文字 */
    color: #ffffff;
}

/* グラスモーフィズムパネル */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 1.5rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    padding: 2.5rem;
    margin-bottom: 2rem;
}

/* フォーム関連 */
.form-card {
    max-width: 800px;
    margin: 0 auto 2rem auto;
}

.input-group {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.children-group {
    margin-top: 1.5rem;
}

.input-field {
    flex: 1;
    min-width: 200px;
    display: flex;
    flex-direction: column;
}

.input-field label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.input-field input {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    background: rgba(255, 255, 255, 0.8);
    font-size: 1rem;
    transition: all 0.2s ease;
    font-family: inherit;
}

.input-field input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    background: #ffffff;
}

.form-divider {
    border: 0;
    height: 1px;
    background: var(--border-color);
    margin: 2rem 0;
}

/* 行列入力テーブル */
.table-group {
    margin-bottom: 1.5rem;
}

.table-group h4 {
    margin-top: 0;
    margin-bottom: 1rem;
    color: var(--text-main);
    font-size: 1.1rem;
    font-weight: 600;
}

.matrix-table-wrapper {
    overflow-x: auto;
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.8);
}

.matrix-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px;
    /* 横スクロールを促す */
}

.matrix-table th,
.matrix-table td {
    padding: 0.75rem;
    text-align: center;
    border: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.matrix-table th {
    background-color: rgba(241, 245, 249, 0.8);
    font-weight: 600;
    white-space: nowrap;
}

.matrix-table td {
    background-color: transparent;
}

.small-input {
    width: 4.5rem;
    padding: 0.4rem;
    border: 1px solid var(--border-color);
    border-radius: 0.4rem;
    text-align: center;
    font-size: 0.95rem;
    background: #ffffff;
    transition: all 0.2s;
}

.small-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}


.action-row {
    display: flex;
    justify-content: center;
    margin-top: 1rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: #ffffff;
    border: none;
    padding: 1rem 2.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(37, 99, 235, 0.3);
}

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

.btn-secondary {
    background-color: #ffffff;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 1rem 2.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.btn-secondary:hover {
    background-color: #f8fafc;
    border-color: var(--text-muted);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

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

/* 結果セクション */
.results-card {
    transition: opacity 0.4s ease, transform 0.4s ease;
    width: 100%;
    margin: 0 auto;
}

.results-card.hidden {
    display: none;
    opacity: 0;
    transform: translateY(20px);
}

.results-card.visible {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.table-container {
    overflow-x: auto;
    border-radius: 1rem;
    border: 1px solid var(--border-color);
    background: #ffffff;
    /* スクロールバーのスタイリング */
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.table-container::-webkit-scrollbar {
    height: 10px;
}

.table-container::-webkit-scrollbar-track {
    background: rgba(241, 245, 249, 0.5);
    border-radius: 0 0 1rem 1rem;
}

.table-container::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background-color: #94a3b8;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    white-space: nowrap;
}

th,
td {
    padding: 0.5rem 0.25rem;
    text-align: center;
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
}

th:last-child,
td:last-child {
    border-right: none;
}

th {
    background-color: #f1f5f9;
    font-weight: 600;
    color: var(--text-main);
    position: sticky;
    top: 0;
    z-index: 10;
    line-height: 1.2;
}

/* 家族列（左端）の固定設定 */
th:first-child,
td:first-child {
    position: sticky;
    left: 0;
    background-color: #f8fafc;
    z-index: 20;
    font-weight: 600;
    min-width: 100px;
    border-right: 2px solid #cbd5e1;
    /* 固定列の境界を強調 */
}

th:first-child {
    z-index: 30;
    /* 左上の角は最前面に */
}

.years-later {
    font-size: 0.6rem;
    color: #94a3b8;
    font-weight: normal;
    display: inline-block;
    margin-top: 2px;
}

/* セルの背景色ルール */
.loan-period-highlight {
    background-color: #e9d5ff !important; /* 薄い紫色 */
}

.age-65-highlight {
    background-color: #ef4444 !important;
    /* 赤塗り */
    color: #ffffff !important;
    /* 白文字 */
    font-weight: bold;
}

/* 子供の年齢に応じた背景色 */
.child-bg-blue {
    background-color: #dbeafe !important;
    /* 7〜12歳 (青) */
}

.child-bg-pink {
    background-color: #fce7f3 !important;
    /* 13〜15歳 (ピンク) */
}

.child-bg-green {
    background-color: #dcfce7 !important;
    /* 16〜18歳 (黄緑) */
}

.child-bg-yellow {
    background-color: #fef9c3 !important;
    /* 19〜22歳 (黄色) */
}

/* 年収表示用・ローン表示用の行スタイル */
.income-row td {
    background-color: #f8fafc;
    border-top: 2px solid #e2e8f0;
}

.income-row.gross-income td {
    color: #0ea5e9;
    /* 水色 (スカイブルー) */
}

.income-row.net-income td {
    color: #22c55e;
    /* 緑 */
}

/* 合計行の強調 */
.income-row.total-row td {
    font-weight: 800;
}

.income-row.gross-income.total-row td {
    color: #0284c7;
    /* より濃い水色 */
}

.income-row.net-income.total-row td {
    color: #15803d;
    /* より濃い緑 */
}

/* 手取りセクションを緑の枠で囲む */
/* 最初の手取り行の上境界 */
.income-row.net-income:first-of-type td {
    border-top: 3px solid #22c55e !important;
}

/* 最後の手取り行の下境界 */
.income-row.net-income:last-of-type td {
    border-bottom: 3px solid #22c55e !important;
}

/* 各手取り行の左右境界 (最初と最後のセル) */
.income-row.net-income td:first-child {
    border-left: 3px solid #22c55e !important;
}

.income-row.net-income td:last-child {
    border-right: 3px solid #22c55e !important;
}

.income-row td:first-child {
    background-color: #f1f5f9;
}

.legend-panel {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: #f8fafc;
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
}

.legend-panel h4 {
    margin-top: 0;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
}

.legend-item {
    display: flex;
    align-items: center;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.color-box {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 0.25rem;
    margin-right: 0.5rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .glass-panel {
        padding: 1.5rem;
    }

    th,
    td {
        padding: 0.75rem 0.5rem;
        font-size: 0.9rem;
    }

    th:first-child,
    td:first-child {
        min-width: 90px;
    }
}