:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --text: #1d1f1e;
  --muted: #676d69;
  --line: #e3e1dc;
  --cell: #ecebe6;
  --accent: #1f8a5b;
  --accent-strong: #136b44;
  --on-accent: #ffffff;
  --danger: #b4372f;
  --radius: 10px;
  color-scheme: light dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Noto Sans SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121413;
    --surface: #1a1d1b;
    --text: #e6e8e6;
    --muted: #9aa19c;
    --line: #2b302d;
    --cell: #262a28;
    --accent: #3db57f;
    --accent-strong: #6bd6a3;
    --on-accent: #08170f;
    --danger: #ef7a70;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.top, main { max-width: 1240px; margin: 0 auto; padding-left: 20px; padding-right: 20px; }
.top { display: flex; justify-content: space-between; align-items: center; padding-top: 14px; padding-bottom: 14px; }
main { padding-bottom: 64px; }
.brand { font-weight: 600; color: var(--text); text-decoration: none; }

h1 { font-size: 1.6rem; margin: .4rem 0 .3rem; font-weight: 650; overflow-wrap: anywhere; }
h2 { font-size: 1rem; margin: 0 0 .6rem; }
h3 { font-size: .85rem; margin: 1rem 0 .4rem; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.lead { color: var(--muted); margin: 0 0 1.2rem; max-width: 40rem; }
.error { color: var(--danger); }
.hint { color: var(--muted); font-size: .85rem; margin: .3rem 0 .8rem; }

button, select, input { font: inherit; color: inherit; }
button, .cell { -webkit-tap-highlight-color: transparent; }
button {
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: .45rem .9rem;
}
button:disabled { cursor: default; opacity: .45; }
button.primary, a.button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.ghost, .lang { background: transparent; }
button.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent-strong);
  text-decoration: underline;
  text-underline-offset: 2px;
}
button.icon { width: 2rem; height: 2rem; padding: 0; font-size: 1.2rem; line-height: 1; }
a.button { display: inline-block; padding: .5rem 1rem; border-radius: 8px; text-decoration: none; }
input[type="text"], input[type="password"], select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: .45rem .6rem;
  min-height: 2.4rem;
  max-width: 100%;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.offscreen { position: fixed; left: -9999px; top: 0; }

.card, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card { padding: 20px; max-width: 34rem; }
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1.1rem; }
.field > span:first-child { font-size: .85rem; color: var(--muted); }
.field-row { display: flex; flex-wrap: wrap; gap: 0 1.2rem; }
.grow { flex: 1 1 14rem; min-width: 0; }
.hours { display: flex; align-items: center; gap: .5rem; }
.submit-row { display: flex; gap: .6rem; align-items: center; }

.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .4rem; }
.cal-title { font-weight: 600; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; user-select: none; -webkit-user-select: none; }
.cal-dow { text-align: center; font-size: .75rem; color: var(--muted); padding: .2rem 0; }
.day {
  min-height: 2.4rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--cell);
  touch-action: none;
  font-variant-numeric: tabular-nums;
}
.day.today { border-color: var(--accent); font-weight: 650; }
.day.on { background: var(--accent); color: var(--on-accent); }
.day:disabled { background: transparent; opacity: .35; }
.cal-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: .6rem; }
.cal-summary { margin: 0; font-size: .85rem; color: var(--muted); }
.cal-summary.error { color: var(--danger); }

.event-head { margin-bottom: 1rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .6rem; }
.admin-hint { font-size: .82rem; color: var(--muted); margin: .5rem 0 0; }
.tabs { display: none; }
.panels { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.panel { padding: 16px; min-width: 0; }
.whoami { display: flex; flex-wrap: wrap; gap: .3rem .8rem; align-items: baseline; font-size: .9rem; }
.status { margin-left: auto; color: var(--muted); font-size: .85rem; }
.status.error { color: var(--danger); }
.join { max-width: 24rem; }

.grid-scroll { overflow-x: auto; padding-bottom: 4px; }
.grid {
  display: grid;
  grid-template-columns: 3.1rem repeat(var(--cols), minmax(2.6rem, 1fr));
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.colhead { display: flex; flex-direction: column; align-items: center; font-size: .72rem; line-height: 1.25; padding-bottom: .35rem; }
.colhead .dow { color: var(--muted); }
.colhead .md { font-weight: 600; font-variant-numeric: tabular-nums; }
.rowhead, .wrap-gutter, .corner { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.rowhead {
  font-size: .7rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding-right: .45rem;
  line-height: 1.6rem;
}
.cell {
  position: relative;
  height: 1.6rem;
  background: var(--cell);
  border-right: 2px solid var(--surface);
  border-bottom: 2px solid var(--surface);
}
.cell.none { background: repeating-linear-gradient(135deg, transparent 0 4px, var(--line) 4px 5px); }
.gap { margin-top: .5rem; }
.wrap {
  margin: 2px 2px 3px 0;
  border-top: 2px solid var(--accent);
  color: var(--accent-strong);
  font-size: .66rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
}
.grid.mine .cell { cursor: pointer; touch-action: none; }
.grid.mine .cell.on { background: var(--accent); }
.grid.mine .cell.preview { outline: 2px solid var(--accent-strong); outline-offset: -2px; }
.grid.mine .cell.preview:not(.on) { opacity: .55; }
.grid.heat .cell { cursor: pointer; }
.grid.heat .cell::before { content: ""; position: absolute; inset: 0; background: var(--accent); opacity: var(--heat, 0); }
.grid.heat .cell.full::before { background: var(--accent-strong); }
.grid.heat .cell.focus { outline: 2px solid var(--text); outline-offset: -2px; z-index: 1; }

.legend { display: flex; align-items: center; gap: .5rem; font-size: .8rem; margin-bottom: .6rem; }
.ramp { width: 7rem; height: .7rem; border-radius: 3px; background: linear-gradient(to right, var(--cell), var(--accent)); }
.detail {
  margin: .8rem -16px 0;
  padding: .7rem 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  font-size: .88rem;
}
.detail p { margin: 0; }
.detail-time { font-weight: 600; }
.detail-cols { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.detail h3 { margin: .4rem 0 .2rem; }
.names, .roster { list-style: none; padding: 0; margin: 0; }
.best ol { padding-left: 1.2rem; margin: 0; }
.best li { margin: .15rem 0; }
.roster li { display: flex; align-items: center; gap: .6rem; padding: .35rem 0; border-bottom: 1px solid var(--line); }
.roster .name { font-weight: 500; overflow-wrap: anywhere; }
.tzname { font-size: .8rem; margin-left: auto; }
.remove { border: 0; background: transparent; color: var(--danger); font-size: 1.1rem; padding: 0 .4rem; line-height: 1; }
.missing, .loading { padding: 3rem 0; }

@media (max-width: 860px) {
  .tabs { display: flex; gap: 4px; margin-bottom: 12px; padding: 4px; border-radius: 10px; background: var(--cell); }
  .tab { flex: 1; border: 0; background: transparent; }
  .tab[aria-selected="true"] { background: var(--surface); font-weight: 600; }
  .panels { grid-template-columns: 1fr; }
  .panels[data-tab="mine"] .all-panel, .panels[data-tab="all"] .mine-panel { display: none; }
  .panel > h2 { display: none; }
  .detail { position: sticky; bottom: 0; z-index: 2; max-height: 40vh; overflow-y: auto; box-shadow: 0 -6px 12px -10px rgba(0, 0, 0, .35); }
}

@media (max-width: 520px) {
  .top, main { padding-left: 12px; padding-right: 12px; }
  .card, .panel { padding: 14px; }
  .detail { margin-left: -14px; margin-right: -14px; padding-left: 14px; padding-right: 14px; }
  .cell { height: 2rem; }
  .rowhead { line-height: 2rem; }
  h1 { font-size: 1.35rem; }
}
