/* ==========================================================
   base.css — 色・変数・全体レイアウト・共通部品
   デザイン全体の変更(色/ガラス効果/フォント)は主にここ
   ========================================================== */
:root {
    --bg-primary: #000000;
    --bg-card: linear-gradient(135deg, rgba(40, 40, 48, 0.55) 0%, rgba(12, 12, 16, 0.85) 100%);
    --text-main: #f4f4f6;
    --text-sub: #9ca3af;
    --danger: #f87171;
    --success: #4ade80;
    --warning: #facc15;

    --border-subtle: rgba(255, 255, 255, 0.12);
    --border-glass: rgba(255, 255, 255, 0.22);
    --border-highlight: rgba(255, 255, 255, 0.45);

    --glass-blur: blur(28px) saturate(200%);
    --card-shadow: 0 12px 28px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.06), 0 0 18px rgba(255, 255, 255, 0.06);

    /* 発光の強さ: 半径(文字サイズの倍率)と濃さ。ここだけ変えれば、全体の強さが変わる */
    --gr: 0.5; --ga: 0.8;
    --glow-text: 0 0 calc(var(--gr) * 1em) rgba(255, 255, 255, var(--ga));
    --glow-white: 0 0 8px rgba(255, 255, 255, 0.85), 0 0 16px rgba(255, 255, 255, 0.3);
    --sel-bg: #141414; --sel-ring: rgba(255, 255, 255, 0.6);
    --radius: 18px; --pad: 10px; --gap: 8px;
    --sheet-top: 21.5%;
    --warn-h: 0px;   /* 警告の帯(.warn-strip)を出している間は 28px(cloud-backup.js が切り替える) */
    --band-bg: rgba(255, 255, 255, 0.04); --band-bd: rgba(255, 255, 255, 0.28);   /* ホイールの選択帯。明るさは、これより上げない */

    /* アプリの高さ。通常は画面いっぱい。ホーム画面アプリで高さが足りない端末では index.html のスクリプトが px で上書きする */
    --app-h: 100vh;
    --app-h: 100dvh;
    --head-h: calc(env(safe-area-inset-top) + 48px);
    --tab-h: 0px;   /* 上部に下線タブを置く画面は 40px にする(FXは使わない) */
    --top-h: calc(var(--head-h) + var(--tab-h));
    /* 下の余白: ホームインジケータ分の安全領域は一部だけ使い、ナビを低くして画面を広く使う(上側=ダイナミックアイランドは --head-h のまま触らない) */
    --safe-b: max(0px, calc(env(safe-area-inset-bottom) - 14px));
    --nav-h: calc(31px + var(--safe-b));
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
input, select, textarea {
    -webkit-user-select: text;
    user-select: text;
}
/* コピーを許可する要素(エラーログの表示など) */
.selectable {
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
}
img { -webkit-user-drag: none; }

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-primary);
    color: var(--text-main);
}

/* 背景: 純黒＋上部に弱い白い光を1つだけ(光の玉は置かない) */
#bg {
    position: fixed; inset: 0; pointer-events: none; z-index: 0;
    background: radial-gradient(130% 45% at 50% 0%, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 72%);
}

/* ---------- カード(標準部品 .card)。余白は、画面ごとのクラスで上書きしてよい ---------- */
.card {
    border: 1px solid rgba(255, 255, 255, 0.3); border-radius: var(--radius); padding: var(--pad); margin: 0 0 var(--gap);
    -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur); box-shadow: var(--card-shadow);
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.11) 0%, rgba(255, 255, 255, 0) 58%), var(--bg-card);
}

/* ---------- ヘッダー ---------- */
header {
    position: fixed; top: 0; left: 0; width: 100%; z-index: 1000;
    /* ステータスバー領域(上の安全領域)は純黒の不透明、その下のヘッダー(48px)は rgba(0,0,0,.85) */
    background: linear-gradient(to bottom, #000000 env(safe-area-inset-top), rgba(0, 0, 0, 0.85) env(safe-area-inset-top));
    -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
    padding-top: env(safe-area-inset-top); height: var(--head-h);
    padding-left: 16px; padding-right: 16px; font-size: 0.9rem; font-weight: 700;
    border-bottom: 1px solid var(--border-subtle); display: flex; justify-content: space-between; align-items: center;
}

.header-rate-box { font-size: 0.8rem; color: #ffffff; font-weight: 700; display: flex; align-items: center; gap: 6px; text-shadow: var(--glow-white); cursor: pointer; }
.header-rate-val { color: #ffffff; font-weight: bold; text-shadow: var(--glow-white); letter-spacing: 0.02em; }
.header-rate-change {
    font-size: 0.68rem; font-weight: 600; padding: 1px 5px; border-radius: 4px; text-shadow: none;
}
.header-rate-change.plus { color: #4ade80; background: rgba(74, 222, 128, 0.15); border: 1px solid rgba(74, 222, 128, 0.35); }
.header-rate-change.minus { color: #f87171; background: rgba(248, 113, 113, 0.15); border: 1px solid rgba(248, 113, 113, 0.35); }
.header-timestamp { font-size: 0.58rem; color: var(--text-sub); font-weight: normal; margin-left: 2px; }

/* ---------- コンテナ・タブ表示 ---------- */
.container {
    /* ナビ(bottom:0)と同じ画面下端を基準にする。--app-h との差でナビの裏に潜り込まないようにする */
    position: fixed; top: calc(var(--top-h) + var(--warn-h)); bottom: var(--nav-h);
    left: 0; right: 0; z-index: 10; max-width: 600px; margin: 0 auto; width: 100%; overflow: hidden;
}

.tab-content { display: none; width: 100%; height: 100%; overflow-y: auto; padding: 12px 16px; }
.tab-content.active { display: block; }
#tab-browser.tab-content.active { display: flex !important; flex-direction: column; padding: 6px 10px; overflow: hidden !important; }
#tab-home.tab-content.active { display: flex !important; flex-direction: column; justify-content: flex-start; height: 100%; padding: 10px 14px 8px; overflow-x: hidden !important; overflow-y: auto !important; }
#tab-entry.tab-content.active { display: flex !important; flex-direction: column; height: 100%; padding: 8px 16px; overflow-x: hidden !important; overflow-y: auto !important; }
#tab-data.tab-content.active { display: flex !important; flex-direction: column; height: 100%; padding: 12px 16px; overflow: hidden !important; }

.section-title { font-size: 0.75rem; font-weight: 700; color: var(--text-sub); margin-bottom: 6px; letter-spacing: 0.05em; display: flex; justify-content: space-between; align-items: center; }

/* ---------- タップ演出(押せる要素に tap クラスを付ける。.is-pressed は ui.js の setupGlobalTapFeedback が付け外しする) ---------- */
.tap { transition: transform 0.15s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.15s ease; cursor: pointer; touch-action: manipulation; }
.tap:active, .tap.is-pressed { transform: scale(0.93) !important; opacity: 0.75 !important; }

/* ---------- ボタン(標準部品: .btn / .btn.pri / .btn.dng / .btn.sm) ---------- */
.btn { height: 44px; padding: 0 18px; border-radius: 14px; border: 1px solid var(--border-glass); background: rgba(255, 255, 255, 0.07); color: var(--text-main); font-size: 0.9rem; }
.btn.pri {
    background: var(--sel-bg); color: #ffffff; border-color: var(--sel-ring); font-weight: 700;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.25), inset 0 0 8px rgba(255, 255, 255, 0.08); text-shadow: var(--glow-text);
}
.btn.dng {
    background: var(--sel-bg); color: var(--danger); border-color: rgba(248, 113, 113, 0.6); font-weight: 700;
    box-shadow: 0 0 10px rgba(248, 113, 113, 0.25), inset 0 0 8px rgba(248, 113, 113, 0.08);
    text-shadow: 0 0 calc(var(--gr) * 1em) rgba(248, 113, 113, var(--ga));
}
.btn.sm { height: 34px; padding: 0 12px; font-size: 0.8rem; border-radius: 10px; }
.btn:disabled { opacity: 0.4; }

/* ---------- フォーム部品 ---------- */
.form-group { margin-bottom: 10px; }
label { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--text-sub); margin-bottom: 4px; }
/* 入力欄(標準部品 .in)。入力欄そのものには backdrop-filter を付けない(付けると、iOSで入力中のカーソルの位置がずれる) */
.in {
    width: 100%; height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--border-glass);
    background: rgba(10, 10, 15, 0.7); color: var(--text-main); font-size: 0.95rem;
    /* 入力中の点滅する線(カーソル)を白にする。iOSの標準の青を使わない */
    caret-color: #ffffff; outline: none; -webkit-user-select: text; user-select: text;
    transition: border-color 0.2s, box-shadow 0.2s;
}
textarea.in { height: auto; padding: 10px 12px; }
input.in[type=text], input.in[type=number], input.in[type=url], input.in[type=password], input.in[type=search], textarea.in {
    -webkit-appearance: none; appearance: none;
}
.in::selection { background: rgba(255, 255, 255, 0.28); color: #ffffff; }
.in:focus { border-color: rgba(255, 255, 255, 0.55); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08); }

/* ---------- テーブル・損益色(複数画面で共通) ---------- */
.table-wrapper { width: 100%; overflow-x: auto; touch-action: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.72rem; }
th, td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--border-subtle); white-space: nowrap; }
th { color: var(--text-sub); font-weight: 500; background: rgba(255,255,255,0.06); -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px); }
tbody tr:nth-child(even) { background-color: rgba(255, 255, 255, 0.04); }
tbody tr:nth-child(odd) { background-color: rgba(0, 0, 0, 0.25); }
tbody tr.trade-row-item { cursor: pointer; transition: background 0.1s; }
tbody tr.trade-row-item:active { background-color: rgba(255, 255, 255, 0.18); }

.text-right { text-align: right; }
.profit-plus { color: var(--success); text-shadow: 0 0 5px rgba(74, 222, 128, 0.4); }
.profit-minus { color: var(--danger); text-shadow: 0 0 5px rgba(248, 113, 113, 0.4); }

/* ---------- モーダル ---------- */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: var(--app-h);
    background: rgba(0,0,0,0.85); backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 2000; display: none; justify-content: center; align-items: center; padding: 16px;
}
.modal-overlay.active { display: flex; }
.modal-content {
    background: rgba(25, 25, 35, 0.92); border: 1px solid var(--border-highlight);
    border-top: 1px solid rgba(255,255,255,0.5);
    border-radius: 20px; width: 100%; max-width: 450px; max-height: 85vh; overflow-y: auto;
    padding: 18px; box-shadow: 0 25px 50px rgba(0,0,0,0.95);
    /* 中に入力欄があるため、ぼかしは付けない(iOSで入力中のカーソルの位置がずれるのを防ぐ) */
}

/* ---------- ナビゲーションバー ---------- */
nav {
    position: fixed; bottom: 0; left: 0; width: 100%;
    height: var(--nav-h);
    background: rgba(0, 0, 0, 0.9);
    -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-subtle); display: flex; justify-content: space-around;
    padding-bottom: var(--safe-b); z-index: 1000;
}
.nav-item {
    flex: 1; display: flex; align-items: center; justify-content: center; text-align: center;
    font-size: 0.68rem; color: var(--text-sub); cursor: pointer;
}
.nav-item.active {
    color: #ffffff;
    font-weight: bold;
    text-shadow: var(--glow-text);
}

/* ---------- トースト通知(画面上部。ヘッダーの下。モーダルより手前) ---------- */
#toast-container {
    position: fixed; left: 0; right: 0; top: calc(var(--top-h) + var(--warn-h) + 8px); z-index: 3000;
    display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; padding: 0 16px;
}
.toast {
    max-width: 560px; padding: 10px 14px; border-radius: 12px; font-size: 0.78rem; line-height: 1.5; color: var(--text-main);
    background: rgba(0, 0, 0, 0.94); border: 1px solid var(--border-glass); box-shadow: 0 10px 28px rgba(0, 0, 0, 0.7);
    -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
    animation: toast-in 0.22s ease-out; transition: opacity 0.3s;
}
.toast-ok { border-color: var(--success); }
.toast-warn { border-color: var(--warning); }
.toast-error { border-color: var(--danger); }
.toast-hide { opacity: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- 部品 dialog(確認ダイアログ)。z-index は、モーダル(2000)とシートより上、トースト(3000)より下 ---------- */
.dlg-ov { position: fixed; inset: 0; z-index: 2500; display: flex; align-items: center; justify-content: center; padding: 24px; background: rgba(0, 0, 0, 0.7); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); opacity: 0; transition: opacity 0.2s; }
.dlg-ov.show { opacity: 1; }
.dlg { width: 100%; max-width: 340px; background: #000000; border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 20px; padding: 18px 16px 14px; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.8), 0 0 14px rgba(255, 255, 255, 0.06); transform: scale(0.96); transition: transform 0.2s; }
.dlg-ov.show .dlg { transform: none; }
.dlg h3 { margin: 0 0 8px; font-size: 0.9rem; text-shadow: var(--glow-text); }
.dlg p { margin: 0 0 16px; font-size: 0.8rem; line-height: 1.5; color: var(--text-sub); white-space: pre-line; }
.dlg-btns { display: flex; gap: 10px; }
.dlg-btns .btn { flex: 1; }

/* ---------- 部品 segment(セグメント切り替え。値や設定の選択。選んだ項目は .on) ---------- */
.segc { display: inline-flex; border: 1px solid var(--border-glass); border-radius: 14px; overflow: hidden; background: rgba(255, 255, 255, 0.04); }
.segc.full { display: flex; width: 100%; }
.segc button { flex: 1; font: inherit; font-size: 0.8rem; line-height: normal; min-height: 40px; padding: 0 18px; background: none; border: 0; color: var(--text-sub); white-space: nowrap; }   /* white-space: nowrap は、アプリで足した(項目の幅が均等に割られて、文字が2行に割れるのを防ぐ) */
.segc button + button { border-left: 1px solid var(--border-subtle); }
.segc button:first-child { border-radius: 13px 0 0 13px; }
.segc button:last-child { border-radius: 0 13px 13px 0; }
.segc button:only-child { border-radius: 13px; }
.segc button.on { background: var(--sel-bg); color: #ffffff; font-weight: 700; box-shadow: inset 0 0 0 1px var(--sel-ring), inset 0 0 8px rgba(255, 255, 255, 0.15); text-shadow: var(--glow-text); }
/* 独立の形(売買) */
.segc.split { border: 0; background: none; border-radius: 0; overflow: visible; gap: 8px; }
.segc.split button, .segc.split button:first-child, .segc.split button:last-child, .segc.split button:only-child { border: 1px solid var(--border-glass); border-radius: 12px; background: rgba(255, 255, 255, 0.04); }
.segc.split button + button { border-left: 1px solid var(--border-glass); }
.segc.split button.on { border-color: transparent; background: var(--sel-bg); }
/* 色分け(売買): t-ok=買い(緑)、t-ng=売り(赤) */
.segc button.on.t-ok { color: var(--success); box-shadow: inset 0 0 0 1px var(--success), inset 0 0 8px rgba(74, 222, 128, 0.25); text-shadow: 0 0 calc(var(--gr) * 1em) rgba(74, 222, 128, var(--ga)); }
.segc button.on.t-ng { color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger), inset 0 0 8px rgba(248, 113, 113, 0.25); text-shadow: 0 0 calc(var(--gr) * 1em) rgba(248, 113, 113, var(--ga)); }

/* ---------- 部品 sheet(ボトムシート)。z-index は、モーダル(2000)・確認ダイアログ(2500)より下 ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 1500; background: rgba(0, 0, 0, 0.7); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); display: flex; align-items: flex-end; opacity: 0; transition: opacity 0.3s; }
.sheet-backdrop.show { opacity: 1; }
.sheet { width: 100%; height: calc(100% - var(--sheet-top)); display: flex; flex-direction: column; background: #000000; border: 0; border-top: 2px solid rgba(255, 255, 255, 0.65); border-radius: 24px 24px 0 0; box-shadow: 0 -2px 12px rgba(255, 255, 255, 0.28); transform: translateY(100%); transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1); }
.sheet-backdrop.show .sheet { transform: none; }   /* 開いたあとは transform を残さない(残すと、iOSで入力欄のカーソルの位置がずれる) */
.sheet-grip { flex: none; position: relative; height: 22px; touch-action: none; }
.sheet-grip::after { content: ""; position: absolute; left: 50%; top: 9px; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: rgba(255, 255, 255, 0.35); }
.sheet-head { flex: none; display: flex; align-items: center; gap: var(--gap); padding: 0 14px 10px; touch-action: none; }
.sheet-titles { flex: 1; min-width: 0; }
.sheet-title { font-size: 0.9rem; font-weight: 700; text-shadow: var(--glow-text); }
.sheet-note { min-height: 1.2em; font-size: 0.62rem; color: var(--text-sub); }
.sheet-note.ok { color: var(--success); }
.sheet-body { flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 0 14px calc(16px + env(safe-area-inset-bottom)); }
/* シートの中身(カード・入力欄を含む)には backdrop-filter を付けない */
.sheet .card { -webkit-backdrop-filter: none; backdrop-filter: none; }

/* ---------- 警告の帯(上部バーの直下。タップで閉じる。--warn-h と一緒に使う) ---------- */
.warn-strip { position: fixed; left: 0; right: 0; top: var(--top-h); height: 28px; display: flex; align-items: center; justify-content: center; padding: 0 12px; font-size: 0.68rem; color: var(--warning); background: rgba(0, 0, 0, 0.85); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); border-bottom: 1px solid var(--border-subtle); z-index: 20; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }   /* 末尾の3つは、アプリで足した(狭い画面で、高さ28pxからはみ出さないように) */
