:root {
  color-scheme: dark;
  --paper: #121418;
  --ink: #e8eaed;
  --muted: #9aa0a6;
  --line: #2c313a;
  --accent: #7aa2f7;
  --accent-ink: #0e1116;
  --card: #1a1e26;
  --ok: #7fd3a8;
  --danger: #f0a0a0;
  --flash: #24332a;
  --flash-error: #3a2428;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "PingFang SC", "Noto Sans SC", "Hiragino Sans GB", ui-sans-serif, system-ui, sans-serif;
}

body {
  padding: calc(16px + env(safe-area-inset-top)) 18px calc(36px + env(safe-area-inset-bottom));
}

.page {
  width: min(560px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 14px;
}

.page.wide {
  width: min(640px, 100%);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.tab {
  flex: 1;
  text-align: center;
  padding: 8px 10px;
  border-radius: 9px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

.tab.current {
  background: #121418;
  color: var(--ink);
}

.cal-panel {
  padding: 14px;
}

.cal-head {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.cal-head h2 {
  margin: 0;
  text-align: center;
  font-size: 16px;
  letter-spacing: 0.06em;
  text-transform: none;
  color: var(--ink);
}

.cal-dows,
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-dows {
  margin-bottom: 6px;
}

.cal-dows span {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 0;
}

.cal-cell {
  min-height: 72px;
  border-radius: 10px;
  padding: 6px 5px;
  background: #121418;
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  color: var(--ink);
  font: inherit;
  text-align: left;
}

.cal-cell.empty {
  background: transparent;
  min-height: 0;
  pointer-events: none;
}

.cal-cell.off {
  background: #2a1c1c;
}

.cal-cell.work {
  background: #1c2433;
}

.cal-cell.today {
  outline: 1px solid var(--accent);
}

.cal-cell.selected {
  border-color: var(--accent);
}

.cal-num {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.cal-tag {
  font-size: 10px;
  line-height: 1;
  padding: 1px 4px;
  border-radius: 4px;
}

.cal-tag.off {
  color: #2a1c1c;
  background: var(--danger);
}

.cal-tag.work {
  color: #121418;
  background: var(--accent);
}

.cal-tag.fest {
  color: #243018;
  background: #c9b27c;
}

.cal-name {
  font-size: 10px;
  color: var(--muted);
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.cal-dots {
  display: flex;
  gap: 3px;
  margin-top: auto;
}

.dot,
.cal-dots .dot,
.cal-legend .dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
}

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.cal-legend .mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 10px;
}

.cal-legend .mark.off {
  color: #2a1c1c;
  background: var(--danger);
}

.cal-legend .mark.work {
  color: #121418;
  background: var(--accent);
}

.cal-legend .mark.fest {
  color: #243018;
  background: #c9b27c;
}

.cal-source {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.cal-cell.weekend .cal-num {
  color: #c4b8a4;
}

.cal-cell.off .cal-num,
.cal-cell.work .cal-num {
  color: var(--ink);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar h1,
.auth-card h1 {
  margin: 0;
  font-family: "Songti SC", "Noto Serif SC", "Iowan Old Style", Georgia, serif;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.status-line {
  min-height: 0;
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.hint {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
}

.hint a {
  color: var(--accent);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--ink);
}

.check-row input {
  width: auto;
  margin: 0;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 18px;
}

.panel-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: inherit;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.panel-title {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-summary {
  flex: 1;
  min-width: 0;
  text-align: right;
}

.panel:not(.collapsed) .panel-summary {
  display: none;
}

.panel.collapsed .weather-place {
  display: none;
}

.weather-place {
  flex: 1;
  text-align: right;
}

.chevron {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.chevron::before {
  content: "▾";
}

.panel.collapsed .chevron::before {
  content: "▸";
}

.panel.collapsed .panel-body {
  display: none;
}

.panel-body {
  margin-top: 14px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

h2 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-head h2 {
  margin: 0;
}

.weather-strip {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px 16px;
  text-align: left;
}

.weather-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--ink);
}

.weather-chip .when {
  color: var(--muted);
  font-size: 12px;
}

.wx-mark {
  position: relative;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
}

.wx-mark img {
  position: absolute;
  inset: 0;
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.weather-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.weather-day {
  background: #121418;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 4px;
}

.weather-day .when {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.weather-day strong {
  font-size: 18px;
}

.weather-day .temp {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
}

.weather-day .wind,
.weather-source {
  color: var(--muted);
  font-size: 12px;
}

.weather-source {
  grid-column: 1 / -1;
  margin: 2px 0 0;
}

.weather-source a {
  color: var(--accent);
}

.weather-grid > .muted,
.weather-grid > .banner {
  grid-column: 1 / -1;
}

.field-row {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #121418;
  color: var(--ink);
  padding: 11px 12px;
  font: inherit;
  font-size: 16px;
  color-scheme: dark;
}

input:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

button {
  appearance: none;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 10px 14px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.sm {
  padding: 7px 10px;
  font-size: 12px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.events,
.devices {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.event,
.device {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 14px 0 0;
  border-top: 1px solid var(--line);
}

.event:first-child,
.device:first-child {
  border-top: 0;
  padding-top: 2px;
}

.device.current strong {
  color: var(--accent);
}

.event time {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
}

.event strong,
.device strong {
  font-size: 16px;
}

.event .meta,
.device .meta {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.event .meta {
  grid-column: 1 / -1;
}

.event.commute .pin {
  margin-left: 8px;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.event.commute .logic {
  line-height: 1.55;
}

.linkish {
  background: none;
  color: var(--muted);
  padding: 0;
  border: 0;
  border-radius: 0;
  font-size: 13px;
}

.banner {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--flash);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
}

.banner.error {
  background: var(--flash-error);
  color: var(--danger);
}

.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal-card {
  position: relative;
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  z-index: 1;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(380px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 24px 24px;
}

.brand-mark {
  margin: 0 0 6px;
  color: var(--accent);
  letter-spacing: 0.28em;
  font-size: 12px;
}

.auth-card h1 {
  margin-bottom: 22px;
  font-size: 28px;
}

.auth-card button {
  width: 100%;
  margin-top: 8px;
  padding: 12px 14px;
}

@media (max-width: 520px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}
