/*
 * base.css — 全ページ共通の既存スタイル（base.html のインライン <style> から移設）
 *
 * 中身はほぼ Bootstrap へのダークモード上書き。新しいスタイルはここに足さず、
 * theme.css のトークンを使って書く。ページ移行が進んだら不要になった上書きから削る。
 *
 * 新デザインの画面（body.ds-page）は、ここの dark-mode 上書きの対象外にしている。
 * :where() は詳細度を増やさないので、旧デザインの画面での効き方は変わらない。
 */

/* bodyタグに移行効果を追加 */
body {
    max-width: 1200px;
    margin: 0 auto;
    background-color: transparent;
    color: inherit;
}

html.theme-ready body {
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* 以下のダークモードスタイルを追加 */
html.dark-mode body,
body.dark-mode:where(:not(.ds-page)) {
    background-color: var(--theme-root-bg);
    color: var(--theme-root-color);
}

/* 入力フィールドのダークモード対応を強化 */
body.dark-mode:where(:not(.ds-page)) input[type="text"]:not(#memoInput),
body.dark-mode:where(:not(.ds-page)) input[type="number"],
body.dark-mode:where(:not(.ds-page)) input[type="password"],
body.dark-mode:where(:not(.ds-page)) input:not([type]) {
    background-color: var(--theme-input-bg);
    color: var(--theme-root-color);
    border-color: var(--theme-border-muted);
}

body.dark-mode:where(:not(.ds-page)) input::placeholder {
    color: #adb5bd;
}

/* 共通プライマリボタンのダークモード対応（ガラス調・リッチ） */
body.dark-mode:where(:not(.ds-page)) .btn-primary {
    background-color: rgba(56, 189, 248, 0.15) !important;
    color: #38bdf8 !important; /* text-white などを抑制するためリッチな青文字で統一 */
    border: 1px solid rgba(56, 189, 248, 0.4) !important;
    box-shadow: none !important;
    transition: all 0.2s ease;
}
body.dark-mode:where(:not(.ds-page)) .btn-primary:not(:disabled):hover {
    background-color: rgba(56, 189, 248, 0.25) !important;
    border-color: rgba(56, 189, 248, 0.6) !important;
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.15) !important;
    color: #bae6fd !important;
}
body.dark-mode:where(:not(.ds-page)) .btn-primary:active {
    transform: translateY(1px);
}

/* 共通アウトラインボタンのダークモード対応 */
body.dark-mode:where(:not(.ds-page)) .btn-outline-primary {
    color: #94a3b8 !important;
    border-color: var(--theme-border-muted) !important;
    background-color: transparent !important;
    box-shadow: none !important;
    transition: all 0.2s ease;
}
body.dark-mode:where(:not(.ds-page)) .btn-outline-primary:hover {
    color: #f1f5f9 !important;
    background-color: var(--theme-surface) !important;
    border-color: var(--theme-border) !important;
}
body.dark-mode:where(:not(.ds-page)) .btn-outline-primary.active,
body.dark-mode:where(:not(.ds-page)) .btn-outline-primary:active {
    color: #38bdf8 !important;
    background-color: rgba(56, 189, 248, 0.15) !important;
    border-color: rgba(56, 189, 248, 0.4) !important;
    box-shadow: none !important;
}

/* 設定判別の各項目のダークモード対応 */
body.dark-mode:where(:not(.ds-page)) table {
    color: var(--theme-root-color);
    background-color: var(--theme-surface);
    border-color: var(--theme-border);
}

body.dark-mode:where(:not(.ds-page)) table th,
body.dark-mode:where(:not(.ds-page)) table td {
    border-color: var(--theme-border);
}

/* 確率などのハイライト（table-danger = 最大値/赤）のダークモード対応 */
body.dark-mode:where(:not(.ds-page)) .table-danger,
body.dark-mode:where(:not(.ds-page)) .table-danger > td,
body.dark-mode:where(:not(.ds-page)) .table-danger > th {
    background-color: rgba(239, 68, 68, 0.12) !important; /* 濁らず透明感のあるクリアな赤 */
    color: #ff8a8a !important; /* スッキリとした明るい赤色テキスト */
}

/* 最低値（table-secondary = 最小値/グレー）の眩しさ防止 */
body.dark-mode:where(:not(.ds-page)) .table-secondary,
body.dark-mode:where(:not(.ds-page)) .table-secondary > td,
body.dark-mode:where(:not(.ds-page)) .table-secondary > th {
    background-color: rgba(255, 255, 255, 0.03) !important; /* ほぼ背景に溶け込む暗さ */
    color: #6c757d !important; /* テキストも暗く落として控えめに */
}

/* Bootstrap標準の.bg-light, .table th, .result-table th のダークモード対応 --- */
body.dark-mode:where(:not(.ds-page)) .bg-light,
body.dark-mode:where(:not(.ds-page)) th.bg-light,
body.dark-mode:where(:not(.ds-page)) .table th,
body.dark-mode:where(:not(.ds-page)) .result-table th {
    background-color: var(--theme-surface-strong) !important;
    color: #ffffff !important;
}

/* .result-table 偶数行の背景もダークに */
body.dark-mode:where(:not(.ds-page)) .result-table tr:nth-child(even) {
    background-color: #343a40 !important;
}

body.dark-mode:where(:not(.ds-page)) .setting1,
body.dark-mode:where(:not(.ds-page)) .setting2,
body.dark-mode:where(:not(.ds-page)) .setting3,
body.dark-mode:where(:not(.ds-page)) .setting4,
body.dark-mode:where(:not(.ds-page)) .setting5,
body.dark-mode:where(:not(.ds-page)) .setting6 {
    color: #f8f9fa;
    border-color: #495057;
}

/* フォーム要素のラベルとテキストフィールドの可読性向上 */
body.dark-mode:where(:not(.ds-page)) .form-label {
    color: #ffffff;
    /* ラベルを明るく */
}

.judgement-helper-text,
.judgement-meta-label {
    color: #6c757d;
}

/* ボタンのコントラスト改善 */
body.dark-mode:where(:not(.ds-page)) .btn-outline-secondary {
    color: #adb5bd;
    border-color: var(--theme-border-muted);
}

body.dark-mode:where(:not(.ds-page)) .btn-outline-secondary:hover {
    background-color: var(--theme-surface-strong);
    color: #ffffff;
}

/* --- 下部ナビ（画面の下端に固定・すりガラス・自作アイコン） --- */
/* 端に付けて下のすき間をなくし、面はすりガラスにして内容の上に1枚重なった奥行きを出す */
.fixed-bottom-nav {
    --nav-bg: var(--ds-color-surface);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--ds-nav-height) + env(safe-area-inset-bottom));
    padding: 0 max(8px, calc(50% - 280px)) env(safe-area-inset-bottom);
    background: var(--ds-color-surface-glass);
    backdrop-filter: blur(24px) saturate(1.8);
    -webkit-backdrop-filter: blur(24px) saturate(1.8);
    border-top: 1px solid var(--ds-color-hairline);
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    z-index: 1500;
    transform: translate3d(0, 0, 0);
    /* iOS PWA fix: GPU acceleration */
}

.m-nav-item {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-decoration: none;
    color: var(--ds-color-ink-2);
    border: none;
    background: transparent;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    transition: color var(--ds-duration) var(--ds-ease);
}

.m-nav-item:hover {
    color: var(--ds-color-ink-2);
}

.m-nav-icon {
    display: block;
    width: 26px;
    height: 26px;
    overflow: visible;
    transition: transform var(--ds-duration-fast) var(--ds-ease);
}

.m-nav-item:active .m-nav-icon {
    transform: scale(0.9);
}

.m-nav-icon * {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: fill var(--ds-duration) var(--ds-ease), stroke var(--ds-duration) var(--ds-ease);
}

.m-nav-icon .nav-ic-dot {
    fill: currentColor;
    stroke: none;
}

.m-nav-icon .nav-ic-knob {
    fill: var(--nav-bg);
}

.m-nav-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1;
}

.m-nav-item.active,
.m-nav-item.active:hover {
    color: var(--ds-color-ink);
}

.m-nav-item.active .m-nav-label {
    font-weight: 700;
}

/* 今いる画面: アイコンを塗りつぶし、1か所だけアプリの色（金）にする */
.m-nav-item.active .nav-ic-body,
.m-nav-item.active .nav-ic-knob {
    fill: currentColor;
}

.m-nav-item.active .nav-ic-cut {
    stroke: var(--nav-bg);
}

.m-nav-item.active .nav-ic-accent {
    fill: var(--ds-color-accent);
    stroke: var(--ds-color-accent);
}

.m-nav-item.active .nav-ic-dot.nav-ic-accent {
    stroke: none;
}

.m-nav-notification-dot {
    position: absolute;
    top: 10px;
    right: calc(50% - 16px);
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--ds-color-danger);
    border: 2px solid var(--ds-color-surface);
}

/* ページ下部の余白をグローバルに確保 (フッターがある場合のみ) */
body:not(.no-footer) {
    padding-bottom: 110px;
    /* 浮いたフッターに合わせて余白を増やす */
}

/* スマホでの入力欄タップ時の自動ズーム防止 (16px以上に設定) */
@media screen and (max-width: 768px) {

    input,
    select,
    textarea {
        font-size: 16px !important;
    }
}

.maintenance-info {
    font-size: 11px;
    font-weight: bold;
    padding: 10px;
    text-align: center;
}

/* 上に戻るボタン: 内容と見分けがつくよう不透明な面にする。表示は base.html のスクロール処理で is-visible を付け外し */
.scroll-top-btn {
    position: fixed;
    right: 16px;
    bottom: var(--ds-above-nav);
    z-index: 1400;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    outline: none;
    background: var(--ds-color-surface);
    color: var(--ds-color-ink);
    font-size: 1.05rem;
    line-height: 44px;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(16, 24, 40, 0.18), 0 0 0 1px var(--ds-color-hairline);
    opacity: 0;
    transform: translateY(10px) scale(0.9);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.scroll-top-btn.is-visible {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

.fixed-close-button {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top));
    right: 12px;
    z-index: 2500;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--ds-color-hairline);
    border-radius: 50%;
    background-color: var(--ds-color-surface-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--ds-color-ink-2);
    box-shadow: 0 4px 14px rgba(16, 24, 40, 0.12);
    text-decoration: none;
}

.fixed-close-button:hover {
    color: var(--ds-color-ink);
}

/* Bootstrap の btn-close（×画像）を使っているページはダーク系で反転 */
html.dark-mode .fixed-close-button.btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
    background-color: rgba(255, 255, 255, 0.7);
}

body.vision-assist-mode .positive,
body.vision-assist-mode .ev-positive,
body.vision-assist-mode .slot-profit.positive,
body.vision-assist-mode .month-total-badge.positive,
body.vision-assist-mode .calendar-day-balance.positive,
body.vision-assist-mode .payout-over-105 {
    color: var(--theme-assist-positive) !important;
    font-weight: 800 !important;
}

body.vision-assist-mode .negative,
body.vision-assist-mode .ev-negative,
body.vision-assist-mode .slot-profit.negative,
body.vision-assist-mode .month-total-badge.negative,
body.vision-assist-mode .calendar-day-balance.negative,
body.vision-assist-mode .payout-under-100 {
    color: var(--theme-assist-negative) !important;
    font-weight: 800 !important;
}

body.vision-assist-mode .ev-positive,
body.vision-assist-mode .payout-over-105,
body.vision-assist-mode .slot-profit.positive,
body.vision-assist-mode .month-total-badge.positive,
body.vision-assist-mode .calendar-day-balance.positive,
body.vision-assist-mode .positive {
    text-decoration: underline;
    text-decoration-thickness: 0.12em;
    text-underline-offset: 0.18em;
}

body.vision-assist-mode .ev-negative,
body.vision-assist-mode .payout-under-100,
body.vision-assist-mode .slot-profit.negative,
body.vision-assist-mode .month-total-badge.negative,
body.vision-assist-mode .calendar-day-balance.negative,
body.vision-assist-mode .negative {
    text-decoration: underline wavy;
    text-decoration-thickness: 0.12em;
    text-underline-offset: 0.18em;
}

/* 行全体への背景色補助（機種別期待値ページのテーブル行） */
body.vision-assist-mode .row-payout-over-105 {
    background: rgba(15, 118, 110, 0.06) !important;
}

body.vision-assist-mode .row-payout-over-105 td:nth-child(1) {
    border-left-style: solid !important;
    border-left-width: 5px !important;
    border-left-color: var(--theme-assist-positive) !important;
}

body.vision-assist-mode .row-payout-under-100 td:nth-child(1) {
    border-left-style: dashed !important;
    border-left-width: 5px !important;
    border-left-color: var(--theme-assist-negative) !important;
}

/* 主要データレンダリングのテーブル：識別強化対応（アンダーラインのみで対応・三角マーク不使用） */

body.vision-assist-mode .btn:focus-visible,
body.vision-assist-mode .form-control:focus-visible,
body.vision-assist-mode .form-select:focus-visible,
body.vision-assist-mode button:focus-visible,
body.vision-assist-mode a:focus-visible {
    outline: 3px solid var(--theme-link);
    outline-offset: 2px;
}
