:root {
  --theme: #3D8BFF;
  --bg: #17181c;
  --panel: #22242a;
  --panel2: #2b2e36;
  --line: #3a3d47;
  --grid: #5d6270; /* カレンダーの区切り線（--line より明るくして見やすく） */
  --text: #f2f3f5;
  --sub: #a7abb6;
  --sat: #7db4ff;
  --sun: #ff8f8a;
  --sat-bg: rgba(61, 139, 255, 0.10);
  --sun-bg: rgba(229, 83, 75, 0.10);
  --danger: #e5534b;
  --fz: 1; /* カレンダーの文字の大きさの倍率（設定の「表示」） */
  --shade-rgb: 23, 24, 28; /* 背景の柄にかける膜の色 */
  --danger-text: #ff9d97;
  --danger-line: #6e3532;
  --rain: #5AC8FA;
  --pick: #ffffff; /* 選んでいる色の丸・スタンプの縁 */
}
/* 明るい表示（設定の「表示」で切り替え） */
body.light {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel2: #eceef2;
  --line: #d3d7de;
  --grid: #b4b9c4;
  --text: #1c1e23;
  --sub: #5a5f6c;
  --sat: #1f5fc4;
  --sun: #cf3229;
  --sat-bg: rgba(61, 139, 255, 0.10);
  --sun-bg: rgba(229, 83, 75, 0.10);
  --shade-rgb: 244, 245, 247;
  --danger-text: #c62f28;
  --danger-line: #e8a9a5;
  --rain: #1878cc;
  --pick: #1c1e23;
}
body.light input[type="date"], body.light input[type="time"] { color-scheme: light; }
body.light .ev-chip { box-shadow: 0 0 0 1px rgba(0, 0, 0, .14), 0 1px 2px rgba(0, 0, 0, .18); }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  font-size: 15px; -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
.note { color: var(--sub); font-size: 12.5px; line-height: 1.5; }
.error { color: var(--danger-text); font-size: 13px; min-height: 1em; margin: 4px 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--sub); }
input, select {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px; font-size: 15px; width: 100%;
}
input[type="date"], input[type="time"] { color-scheme: dark; }
.btn {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 14px; font-size: 14px; cursor: pointer;
}
.btn.primary { background: var(--theme); border-color: var(--theme); color: #fff; font-weight: 600; }
.btn.danger { color: var(--danger-text); border-color: var(--danger-line); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.big { padding: 13px; font-size: 16px; width: 100%; }
.btn:disabled { opacity: 0.55; }
.icon-btn {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 50%; width: 38px; height: 38px; font-size: 18px; cursor: pointer; flex: none;
}
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 92px; z-index: 200;
  background: #33363f; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.4); max-width: 90vw; text-align: center;
}

/* 認証 */
.view { min-height: 100dvh; }
.auth-box { max-width: 420px; margin: 0 auto; padding: 32px 18px; }
.app-title { text-align: center; font-size: 24px; }
.tabs { display: flex; gap: 8px; margin: 16px 0; }
.tab { flex: 1; padding: 10px; border-radius: 10px; background: var(--panel); color: var(--sub); border: 1px solid var(--line); font-size: 15px; cursor: pointer; }
.tab.active { background: var(--theme); color: #fff; border-color: var(--theme); }

/* メイン */
#view-main { padding-bottom: calc(76px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 8px;
  background: var(--bg); border-top: 4px solid var(--theme); border-bottom: 1px solid var(--line);
  padding: 8px 10px;
}
.cal-switcher { width: auto; max-width: 55vw; font-weight: 700; font-size: 16px; }
.top-actions { margin-left: auto; display: flex; gap: 8px; }
.search-bar { display: flex; gap: 8px; padding: 8px 10px; }
.search-results { padding: 0 10px 8px; display: flex; flex-direction: column; gap: 6px; }
.search-item { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; text-align: left; color: var(--text); cursor: pointer; font-size: 14px; }
.search-item .d { color: var(--sub); font-size: 12px; margin-right: 8px; }

.today-panel { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px 2px; align-items: center; }
.today-panel .tp-label { font-size: 12px; color: var(--sub); font-weight: 700; }
.mini-chip { border-radius: 999px; padding: 3px 9px; font-size: calc(12px * var(--fz)); color: #17181c; font-weight: 600; cursor: pointer; border: none; }

.monthbar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; }
.month-label { font-size: 17px; font-weight: 700; }
.view-toggle { margin-left: auto; display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.toggle-btn { background: var(--panel); color: var(--sub); border: none; padding: 6px 14px; font-size: 13px; cursor: pointer; }
.toggle-btn.active { background: var(--theme); color: #fff; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-row { padding: 2px 10px 8px; }
.chip {
  border-radius: 999px; padding: 5px 11px; font-size: 13px; cursor: pointer;
  background: var(--panel); color: var(--text); border: 2px solid var(--line);
}
.chip.active { border-color: var(--theme); background: var(--panel2); font-weight: 700; }
.chip .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: baseline; }

/* タイムライン */
.timeline-wrap { padding: 0 6px; }
.tl { display: grid; border-top: 1px solid var(--line); }
.tl-head, .tl-row { display: grid; grid-template-columns: 44px repeat(var(--cols, 6), 1fr); }
.tl-head { position: sticky; top: 59px; z-index: 20; background: var(--bg); }
.tl-head .tl-mem {
  text-align: center; font-size: 12px; font-weight: 700; padding: 5px 1px 3px;
  border-bottom: 2px solid var(--mc, var(--line)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tl-row { border-bottom: 1px solid var(--line); min-height: 46px; }
.tl-row.sat { background: var(--sat-bg); }
.tl-row.sun { background: var(--sun-bg); }
.tl-row.today { outline: 2px solid var(--theme); outline-offset: -2px; }
.tl-date { padding: 4px 2px; text-align: center; font-size: calc(11px * var(--fz)); color: var(--sub); line-height: 1.35; }
.tl-date .dnum { font-size: calc(15px * var(--fz)); font-weight: 700; color: var(--text); display: inline-flex; align-items: center; justify-content: center; min-width: calc(22px * var(--fz)); height: calc(22px * var(--fz)); }
.tl-row.today .tl-date .dnum { background: var(--theme); color: #fff; border-radius: 50%; }
.tl-date.sat .dnum, .tl-date.sat .dow { color: var(--sat); }
.tl-date.sun .dnum, .tl-date.sun .dow { color: var(--sun); }
.tl-date .hol { color: var(--sun); font-size: calc(9.5px * var(--fz)); display: block; }
.tl-date .wx { display: block; font-size: 9.5px; color: var(--sub); line-height: 1.3; margin-top: 1px; }
.tl-cell { padding: 2px; display: flex; flex-direction: column; gap: 2px; cursor: pointer; min-width: 0; border-left: 1px solid var(--grid); }
.tl-head .tl-mem { border-left: 1px solid var(--grid); }
.ev-chip {
  border-radius: 7px; padding: 2px 4px; font-size: calc(10.5px * var(--fz)); line-height: 1.3; color: #17181c;
  box-shadow: 0 1px 2px rgba(0,0,0,.35); cursor: pointer; word-break: break-all; text-align: left; border: none; width: 100%;
}
.ev-new {
  display: inline-block; background: #e5302a; color: #fff; font-size: 0.85em; font-weight: 700; line-height: 1;
  padding: 2px 3px; border-radius: 4px; margin-right: 2px; vertical-align: 1px; box-shadow: 0 0 0 1px #fff;
}
.ev-chip .t { display: block; font-weight: 700; font-size: calc(9.5px * var(--fz)); opacity: .85; }

/* 月表示 */
.month-wrap { padding: 0 6px 10px; }
.m-head, .m-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.m-head div { text-align: center; font-size: 12px; color: var(--sub); padding: 4px 0; }
.m-head .sat { color: var(--sat); } .m-head .sun { color: var(--sun); }
.m-cell { border: 1px solid var(--grid); min-height: 74px; padding: 2px; cursor: pointer; overflow: hidden; }
.m-cell.dim { opacity: .35; }
.m-cell.sat { background: var(--sat-bg); } .m-cell.sun { background: var(--sun-bg); }
.m-cell .dnum { font-size: calc(12px * var(--fz)); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; min-width: calc(20px * var(--fz)); height: calc(20px * var(--fz)); }
.m-cell.today .dnum { background: var(--theme); color: #fff; border-radius: 50%; }
.m-cell .hol { font-size: calc(9px * var(--fz)); color: var(--sun); display: block; }
.m-cell .ev-chip { font-size: calc(9.5px * var(--fz)); padding: 1px 3px; margin-top: 2px; }

/* 着せ替え */
.bg-layer, .bg-shade { position: fixed; inset: 0; display: none; pointer-events: none; }
.bg-layer { z-index: -2; background-position: center; }
.bg-shade { z-index: -1; background: rgba(var(--shade-rgb), var(--shade, .65)); }
body.has-bg .bg-layer, body.has-bg .bg-shade { display: block; }
body.has-bg .topbar, body.has-bg .tl-head { background: rgba(var(--shade-rgb), .86); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.bg-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.bg-tile {
  position: relative; aspect-ratio: 3 / 4; border-radius: 10px; overflow: hidden; cursor: pointer; padding: 0;
  border: 3px solid var(--line); background-color: var(--panel2); background-position: center;
}
.bg-tile.active { border-color: var(--theme); }
.bg-tile .bg-name {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 2px; font-size: 12.5px; font-weight: 700;
  background: rgba(0, 0, 0, .6); color: #fff; text-align: center;
}
.bg-tile .bg-check { position: absolute; top: 4px; right: 6px; font-size: 18px; }
.bg-tile.none { display: flex; align-items: center; justify-content: center; color: var(--sub); font-size: 13px; }
label.btn[for="bg-file"] { text-align: center; }

/* 設定のタブ */
.set-tabs { display: flex; gap: 2px; padding: 6px 8px 0; border-bottom: 1px solid var(--grid); }
.set-tab {
  flex: 1; min-width: 0; padding: 10px 0; font-size: 13px; font-weight: 700; white-space: nowrap;
  background: none; color: var(--sub); border: none; border-bottom: 3px solid transparent; cursor: pointer;
}
.set-tab.active { color: var(--text); border-bottom-color: var(--theme); }
/* タブを切り替えても枠の高さが変わらないよう固定する */
#modal-settings .modal-card { height: 92dvh; }
#modal-settings .modal-body { flex: 1; min-height: 0; }
@media (min-width: 700px) { #modal-settings .modal-card { height: min(86dvh, 820px); } }
.set-pane { display: none; flex-direction: column; gap: 10px; }
.set-pane.active { display: flex; }
.set-pane > h4:first-child { margin-top: 2px; }

/* 天気予報 */
#weather-list { gap: 0; }
.wx-row { display: grid; grid-template-columns: 92px 48px 1fr 52px; align-items: center; gap: 8px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.wx-row.today { background: var(--panel2); border-radius: 10px; }
.wx-date { font-size: 14px; line-height: 1.35; }
.wx-date b { display: block; font-size: 16px; color: var(--theme); }
.wx-date.sat span { color: var(--sat); }
.wx-date.sun span { color: var(--sun); }
.wx-icon { font-size: 34px; text-align: center; }
.wx-text { font-size: 16px; font-weight: 700; }
.wx-temp { font-size: 15px; color: var(--sub); }
.wx-temp .hi { color: var(--danger-text); font-weight: 700; font-size: 18px; }
.wx-temp .lo { color: var(--sat); font-weight: 700; font-size: 18px; }
.wx-pop { text-align: center; font-size: 15px; line-height: 1.3; color: var(--sub); }
.wx-pop.rainy { color: var(--rain); font-weight: 700; }
#weather-list > .note { margin-top: 10px; }

/* 連続入力 */
.stamp-open {
  position: fixed; left: 16px; bottom: calc(78px + env(safe-area-inset-bottom)); z-index: 40;
  height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--grid);
  background: var(--panel2); color: var(--text); font-size: 15px; font-weight: 700;
  box-shadow: 0 4px 14px rgba(0,0,0,.45); cursor: pointer;
}
.stamp-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  background: var(--panel); border-top: 2px solid var(--theme);
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 16px rgba(0,0,0,.45);
}
.stamp-head { display: flex; align-items: center; gap: 8px; }
.stamp-chips { margin-top: 8px; }
.stamp-members { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; padding-bottom: 2px; }
.stamp-members .chip { flex: none; font-size: 14px; padding: 6px 11px; }
.stamp-hint { flex: 1; font-size: 14px; line-height: 1.5; color: var(--text); }
.stamp-hint .stamp-chip { display: inline-block; padding: 3px 12px; cursor: default; transform: none; }
.stamp-hint .note { font-size: 12px; }
.stamp-chips { display: flex; flex-wrap: wrap; gap: 8px; max-height: 30vh; overflow-y: auto; }
.stamp-chip {
  border-radius: 999px; padding: 8px 14px; font-size: 15px; font-weight: 700; cursor: pointer;
  border: 3px solid transparent; box-shadow: 0 1px 2px rgba(0,0,0,.35);
}
.stamp-chip.active { border-color: var(--pick); transform: scale(1.06); }
.stamp-chips .note a { color: var(--theme); }
body.stamping #view-main { padding-bottom: calc(40vh + env(safe-area-inset-bottom)); }
body.stamping .fab, body.stamping .stamp-open { display: none; }
body.stamping .tl-row, body.stamping .m-cell { cursor: copy; }
body.stamping .toast { bottom: auto; top: 72px; }
.tl-row.stamp-flash, .m-cell.stamp-flash { animation: stampflash .5s ease-out; }
@keyframes stampflash { from { background: rgba(61, 139, 255, .45); } to { background: transparent; } }

/* FAB */
.fab {
  position: fixed; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 40;
  width: 56px; height: 56px; border-radius: 50%; border: none; background: var(--theme); color: #fff;
  font-size: 28px; box-shadow: 0 4px 14px rgba(0,0,0,.45); cursor: pointer;
}
.tabbar-spacer { height: 0; }

/* モーダル */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.modal-card {
  background: var(--panel); width: 100%; max-width: 560px; max-height: 92dvh; border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column;
}
.modal-card.wide { max-width: 640px; }
@media (min-width: 700px) { .modal { align-items: center; } .modal-card { border-radius: 16px; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 4px; }
.modal-head h3 { margin: 0; }
.modal-body { overflow-y: auto; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.modal-body h4 { margin: 14px 0 2px; font-size: 14px; color: var(--sub); border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.modal-foot {
  display: flex; gap: 10px; justify-content: flex-end; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--panel);
}
.modal-foot.wrap { flex-wrap: wrap; justify-content: flex-start; }
.field-label { font-size: 13px; color: var(--sub); margin-top: 4px; }
.color-row { display: flex; flex-wrap: wrap; gap: 7px; }
.color-dot { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.color-dot.active { border-color: var(--pick); transform: scale(1.12); }
.time-row { display: flex; gap: 10px; }
.time-row label { flex: 1; }
.inline-row { display: flex; gap: 8px; } .inline-row input { flex: 1; }
.batch-nav { display: flex; align-items: center; gap: 10px; justify-content: center; }
.batch-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.batch-grid button { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 0; font-size: 13px; cursor: pointer; }
.batch-grid button.sel { background: var(--theme); color: #fff; border-color: var(--theme); font-weight: 700; }
.batch-grid button.dim { opacity: .3; }
.detail-colorbar { height: 8px; border-radius: 4px; }
.detail-list { margin: 0; }
.detail-list > div { display: flex; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.detail-list dt { width: 64px; color: var(--sub); font-size: 13px; flex: none; }
.detail-list dd { margin: 0; }
.box { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.user-line { display: flex; align-items: center; gap: 10px; }
.member-edit { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.member-edit .row1 { display: flex; gap: 8px; align-items: center; }
.member-edit input[type="text"] { flex: 1; }
details summary { cursor: pointer; color: var(--sub); font-size: 13px; padding: 6px 0; }
.invite-url { word-break: break-all; font-size: 12px; background: var(--panel2); padding: 8px; border-radius: 8px; }
.danger-zone { border-top: 1px solid var(--danger-line); margin-top: 10px; }
