:root {
  color-scheme: light;            /* 端末がダークでも常に白基調 */
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f2f5f9;
  --muted-bg: #fafbfd;
  --line: #e4e9f0;
  --text: #16202f;
  --muted: #6b7789;
  --primary: #38c2f5;        /* 空色 */
  --primary-ink: #05334c;    /* 空色の上に載せる文字色 */
  --link: #0b82b8;           /* 白地に載せる空色系の文字 */
  --danger: #e5484d;
  --today: #e8f7ff;
  --sat: #2f7fd6;
  --sun: #d64545;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(20, 32, 55, .10);
  --ad-h: 0px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 認証 ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 24px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 22px; margin: 0; letter-spacing: .02em; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; background: var(--primary); color: var(--primary-ink); }
.brand-sub { color: var(--muted); font-size: 13px; margin: 8px 0 18px; }
.tabs { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-bottom: 16px; }
.tab { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 9px; border-radius: 9px; font-size: 14px; font-weight: 600; cursor: pointer; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.stack { display: grid; gap: 12px; }
label { display: grid; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
textarea { resize: vertical; }
.lang-pick { margin-top: 14px; }
.lang-pick select { padding: 8px 10px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

.btn { border: 0; border-radius: 11px; padding: 11px 16px; font-size: 15px; font-weight: 700; cursor: pointer; background: var(--surface-2); color: var(--text); }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.link { border: 0; background: none; color: var(--muted); font-size: 15px; padding: 6px; cursor: pointer; }
.link.primary { color: var(--link); font-weight: 700; }

/* ---------- 画面骨格 ---------- */
.app { position: relative; display: flex; flex-direction: column; height: calc(100dvh - var(--ad-h)); }
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); padding-top: var(--safe-top); }
.topbar-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.topbar-row.second { padding-top: 0; overflow-x: auto; scrollbar-width: none; }
.topbar-row.second::-webkit-scrollbar { display: none; }
.period { flex: 1; display: flex; align-items: center; justify-content: center; gap: 4px; }
.period h2 { font-size: 17px; margin: 0; min-width: 9.5em; text-align: center; }
.icon-btn { display: grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 10px; background: transparent; color: var(--text); cursor: pointer; }
.icon-btn:active { background: var(--surface-2); }

.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 6px 13px; border-radius: 8px; font-weight: 700; font-size: 13px; cursor: pointer; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.chips { display: flex; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 5px 11px; font-size: 12px; font-weight: 700; white-space: nowrap; cursor: pointer; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.chip.on { color: var(--text); border-color: transparent; background: var(--surface-2); }
.chip.off { opacity: .45; }

.calendar { flex: 1; overflow: hidden; position: relative; }

/* ---------- 月表示 ---------- */
.month { display: flex; flex-direction: column; height: 100%; }
.month-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--line); background: var(--surface); }
.month-head div { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); padding: 6px 0; }
.month-head div.sat { color: var(--sat); } .month-head div.sun { color: var(--sun); }
.month-grid { flex: 1; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-rows: minmax(82px, 1fr); overflow-y: auto; }
.mcell { min-width: 0; overflow: hidden; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 3px 3px 2px; min-height: 82px; display: flex; flex-direction: column; gap: 2px; background: var(--surface); }
.mcell:nth-child(7n) { border-right: 0; }
.mcell.other { background: var(--muted-bg); }
.mcell.other .mday { opacity: .35; }
.mcell.today { background: var(--today); }
.mday { font-size: 12px; font-weight: 700; text-align: center; }
.mday.sat { color: var(--sat); } .mday.sun { color: var(--sun); }
.mday .n { display: inline-grid; place-items: center; min-width: 21px; height: 21px; border-radius: 999px; }
.mcell.today .mday .n { background: var(--primary); color: var(--primary-ink); }
.ev { font-size: 11px; line-height: 1.35; border-radius: 5px; padding: 1px 5px; color: #fff; --ink: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.ev.allday { font-weight: 700; }
.ev.dotted { background: transparent !important; color: var(--text); display: flex; align-items: center; gap: 4px; padding-left: 2px; }
.ev.dotted i { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.ev.dotted .t { color: var(--muted); flex: 0 0 auto; }
.ev.dotted .ttl { overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 700px) { .ev.dotted .t { display: none; } }
.more { font-size: 10px; color: var(--muted); text-align: center; cursor: pointer; }
.month.compact .month-grid { flex: 0 0 auto; grid-auto-rows: minmax(52px, auto); }
.mcell .dots { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; padding-top: 2px; }
.mcell .dots i { width: 6px; height: 6px; border-radius: 50%; }
.mcell.selected { box-shadow: inset 0 0 0 2px var(--primary); }
.agenda { flex: 1; min-height: 0; display: flex; flex-direction: column; border-top: 1px solid var(--line); background: var(--bg); }
.agenda-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px 0; font-weight: 700; font-size: 14px; }
.agenda .daylist { overflow-y: auto; padding-top: 8px; }
.dl-time { white-space: pre-line; }

/* ---------- 週・日表示 ---------- */
.grid-view { display: flex; flex-direction: column; height: 100%; background: var(--surface); }
.gv-head { display: grid; border-bottom: 1px solid var(--line); }
.gv-head .gutter { border-right: 1px solid var(--line); }
.gv-daycell { text-align: center; padding: 5px 0; border-right: 1px solid var(--line); font-size: 11px; color: var(--muted); font-weight: 700; }
.gv-daycell .num { display: inline-grid; place-items: center; min-width: 24px; height: 24px; border-radius: 999px; font-size: 14px; color: var(--text); }
.gv-daycell.today .num { background: var(--primary); color: var(--primary-ink); }
.gv-daycell.sat .num, .gv-daycell.sat { color: var(--sat); } .gv-daycell.sun .num, .gv-daycell.sun { color: var(--sun); }
.gv-allday { display: grid; border-bottom: 1px solid var(--line); min-height: 24px; max-height: 84px; overflow-y: auto; }
.gv-allday .gutter { border-right: 1px solid var(--line); font-size: 10px; color: var(--muted); display: grid; place-items: center; }
.gv-allday .cell { border-right: 1px solid var(--line); padding: 2px; display: grid; gap: 2px; align-content: start; }
.gv-body { flex: 1; overflow-y: auto; position: relative; }
.gv-canvas { display: grid; position: relative; }
.gv-hours { border-right: 1px solid var(--line); }
.hour { height: 48px; border-bottom: 1px solid var(--line); font-size: 10px; color: var(--muted); text-align: right; padding-right: 5px; }
.gv-col { border-right: 1px solid var(--line); position: relative; }
.gv-col .hline { height: 48px; border-bottom: 1px solid var(--line); }
.tev { position: absolute; left: 2px; right: 2px; border-radius: 6px; padding: 2px 5px; font-size: 11px; line-height: 1.25; overflow: hidden; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.tev b { display: block; font-weight: 700; }
.tev small { opacity: .9; font-size: 10px; }
.nowline { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 3; pointer-events: none; }
.nowline::before { content: ''; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }

/* ---------- 日表示のリスト ---------- */
.daylist { padding: 10px 12px calc(90px + var(--safe-bottom)); display: grid; gap: 8px; }
.dl-item { display: flex; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; cursor: pointer; }
.dl-bar { width: 4px; border-radius: 4px; flex: 0 0 auto; }
.dl-time { font-size: 12px; color: var(--muted); font-weight: 700; min-width: 5.2em; }
.dl-title { font-weight: 700; }
.dl-meta { font-size: 12px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); font-size: 13px; padding: 28px 0; }

/* ---------- FAB / トースト ---------- */
.fab {
  color: var(--primary-ink);
  position: absolute; right: 18px; bottom: calc(18px + var(--safe-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--primary); box-shadow: var(--shadow); cursor: pointer;
  display: grid; place-items: center;
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.4; }
.toast {
  position: fixed; left: 50%; transform: translate(-50%, 20px);
  bottom: calc(84px + var(--safe-bottom)); background: #16202f; color: #fff;
  padding: 10px 16px; border-radius: 999px; font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: 88vw; text-align: center;
}
.toast.show { opacity: .95; transform: translate(-50%, 0); }

/* ---------- ダイアログ ---------- */
dialog.sheet {
  border: 0; padding: 0; background: var(--surface); color: var(--text);
  border-radius: 18px 18px 0 0; width: 100%; max-width: 560px;
  margin: auto auto 0; max-height: 92dvh; box-shadow: var(--shadow);
}
dialog.sheet::backdrop { background: rgba(10, 16, 28, .45); }
@media (min-width: 640px) { dialog.sheet { border-radius: 18px; margin: auto; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.sheet-head strong { font-size: 15px; }
.sheet-body { padding: 14px; overflow-y: auto; max-height: calc(92dvh - 52px); padding-bottom: calc(20px + var(--safe-bottom)); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-check { display: flex; flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
.row-check input { width: auto; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 0; }
legend { font-size: 12px; color: var(--muted); font-weight: 700; padding: 0 4px; }
.chips-wrap { display: flex; flex-wrap: wrap; gap: 7px; }
.chips-wrap label { display: inline-flex; align-items: center; }
.chips-wrap input { position: absolute; opacity: 0; width: 0; height: 0; }
.chips-wrap span { display: inline-block; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 12px; font-weight: 700; color: var(--muted); cursor: pointer; }
.chips-wrap input:checked + span { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.colors { display: flex; flex-wrap: wrap; gap: 8px; }
.colors button { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.colors button.sel { border-color: var(--text); }

.ad-slot { display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom); overflow: hidden; }
.ad-slot.on { display: block; }
.ad-slot.dummy { display: grid; place-items: center; text-align: center; height: 56px;
  font-size: 11px; color: var(--muted); padding: 0 12px; }

.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: grid; gap: 8px; background: var(--surface); }
.card h3 { margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card h3 .dot { width: 10px; height: 10px; border-radius: 50%; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row .name { font-size: 14px; }
.row .sub { font-size: 11px; color: var(--muted); }
.badge { font-size: 11px; font-weight: 700; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; }
.invite { display: flex; align-items: center; gap: 8px; }
.invite code { flex: 1; font-size: 17px; letter-spacing: .18em; font-weight: 700; background: var(--surface-2); border-radius: 9px; padding: 9px 12px; text-align: center; }
.detail-row { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.detail-row .k { color: var(--muted); font-size: 12px; min-width: 5.5em; padding-top: 2px; }
.avatars { display: flex; flex-wrap: wrap; gap: 6px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
