:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #17202e;
  --muted: #667085;
  --green: #217a51;
  --red: #b33232;
  --blue: #2463eb;
  --soft-blue: #e9f0ff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: white;
  border-radius: 8px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
}

button:disabled {
  opacity: .55;
  cursor: not-allowed;
}

button.ghost {
  background: white;
  color: var(--text);
  border-color: var(--line);
}

button.danger {
  color: var(--red);
  border-color: #efc3c3;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 44px;
  padding: 10px 12px;
  background: white;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 440px) minmax(420px, 640px);
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 32px;
  background:
    linear-gradient(90deg, rgba(247, 248, 250, .94) 0%, rgba(247, 248, 250, .82) 44%, rgba(247, 248, 250, .22) 100%),
    url("/static/climber-background.jpg") center / cover no-repeat;
}

.login-panel {
  width: 100%;
  display: grid;
  gap: 16px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 46px rgba(23, 32, 46, .12);
}

.qr-poster-panel {
  width: min(560px, 100%);
  justify-self: center;
}

.qr-poster-panel img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .28);
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.register-page {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

[hidden],
.is-hidden {
  display: none;
}

.login-panel h1,
.login-panel h2,
.topbar h1,
.day-panel h2,
dialog h2 {
  margin: 0;
}

.login-panel p,
.eyebrow {
  margin: 0;
  color: var(--muted);
}

.error {
  min-height: 20px;
  color: var(--red);
}

.error.success {
  color: var(--green);
}

.notice {
  min-height: 22px;
  margin: 0 0 12px;
  color: var(--blue);
  overflow-wrap: anywhere;
}

.shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar,
.calendar-toolbar,
.workspace,
.panel-head,
.dialog-head,
.top-actions {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.top-actions,
.calendar-toolbar {
  gap: 10px;
}

.calendar-toolbar {
  margin-bottom: 8px;
}

.holiday-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 12px;
}

.holiday-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.holiday-legend i {
  width: 15px;
  height: 15px;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.legend-weekend {
  background: rgba(255, 247, 237, .9);
}

.legend-holiday {
  background: rgba(254, 243, 199, .9);
}

.legend-workday {
  background: rgba(238, 244, 255, .95);
}

.workspace {
  align-items: stretch;
  gap: 18px;
}

.calendar-area,
.day-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.calendar-area {
  flex: 1;
  min-width: 0;
  padding: 14px;
}

.weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.weekdays {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
  text-align: center;
}

.day {
  position: relative;
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: white;
  color: var(--text);
  text-align: left;
  overflow: hidden;
}

.day.is-outside {
  opacity: .38;
}

.day.is-selected {
  border-color: var(--blue);
  background: var(--soft-blue);
}

.day.is-weekend {
  background: rgba(255, 247, 237, .72);
}

.day.is-holiday {
  background: rgba(254, 243, 199, .72);
}

.day.is-workday {
  background: rgba(238, 244, 255, .86);
}

.day.is-selected.is-weekend,
.day.is-selected.is-holiday,
.day.is-selected.is-workday {
  border-color: var(--blue);
}

.day.has-activity {
  border-color: rgba(36, 99, 235, .42);
}

.day-number {
  font-weight: 700;
  margin-bottom: 8px;
}

.holiday-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  min-width: 24px;
  height: 22px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}

.holiday-badge-weekend {
  color: #9a3412;
  background: #ffedd5;
}

.holiday-badge-holiday {
  color: #92400e;
  background: #fde68a;
}

.holiday-badge-workday {
  color: #1d4ed8;
  background: #dbeafe;
}

.holiday-name {
  display: block;
  margin: -3px 0 6px;
  color: #92400e;
  font-size: 12px;
  line-height: 1.2;
}

.event-chip,
.event-empty {
  min-height: 28px;
  margin-bottom: 8px;
  border-radius: 8px;
  padding: 5px 7px;
  font-size: 12px;
  line-height: 1.25;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.event-chip {
  background: #eef6ff;
  color: #1751b8;
  border: 1px solid #c8dcff;
}

.event-chip {
  display: grid;
  gap: 2px;
  border-left: 4px solid var(--blue);
}

.event-chip strong,
.event-chip span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.more-events,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.day-panel {
  width: 340px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.lists {
  display: grid;
  gap: 14px;
}

.event-list-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: white;
}

.event-list-card h3 {
  margin: 0 0 4px;
  font-size: 16px;
  overflow-wrap: anywhere;
}

.event-list-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.activity-detail {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcff;
}

.activity-detail h3 {
  margin: 6px 0;
  font-size: 17px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.my-response-card {
  border: 1px solid #c8dcff;
  border-radius: 8px;
  padding: 12px;
  background: #f5f9ff;
}

.my-response-card strong {
  display: block;
  margin-top: 5px;
  color: #1751b8;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.activity-meta {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.slot-row,
.slot-choices,
.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.slot-pill,
.slot-choice {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  background: white;
  font-size: 13px;
}

.slot-choice {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  min-height: 42px;
}

.slot-choice input {
  width: auto;
  min-height: auto;
}

.slot-choices.needs-attention {
  border: 1px solid #f5a000;
  border-radius: 8px;
  padding: 8px;
  background: #fff8e6;
}

.event-detail,
.response-editor {
  display: grid;
  gap: 12px;
}

.response-editor {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.response-help {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.form-hint {
  margin: 0;
  color: var(--red);
  font-size: 13px;
  line-height: 1.45;
}

.response-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.response-summary span {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
  background: white;
}

.summary-join {
  color: var(--green);
}

.summary-decline {
  color: var(--red);
}

.summary-maybe {
  color: #a16207;
}

.group h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.names {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.name {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 9px;
  background: white;
  overflow-wrap: anywhere;
}

.name small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

dialog {
  width: min(720px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

dialog::backdrop {
  background: rgba(23, 32, 46, .28);
  backdrop-filter: blur(2px);
}

.dialog-head {
  justify-content: space-between;
  margin-bottom: 16px;
}

.member-form {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 140px auto;
  gap: 8px;
  margin-bottom: 16px;
}

#groupForm,
#joinGroupForm {
  grid-template-columns: 1fr auto;
}

.group-page,
.stack-form {
  display: grid;
  gap: 12px;
}

.group-page[hidden] {
  display: none;
}

.group-page-actions,
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.group-page-actions button,
.dialog-actions button {
  flex: 1 1 140px;
}

.confirm-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcff;
}

.confirm-card h3 {
  margin: 6px 0;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.confirm-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.invite-code {
  margin-top: 12px;
  border: 1px dashed #9bb8ff;
  border-radius: 8px;
  padding: 14px;
  background: #eef6ff;
  color: #1751b8;
  font-size: 20px;
  font-weight: 800;
  text-align: center;
  overflow-wrap: anywhere;
  user-select: all;
  width: 100%;
  cursor: pointer;
  min-height: 54px;
}

.activity-form {
  display: grid;
  gap: 12px;
}

.response-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.member-list {
  display: grid;
  gap: 14px;
}

.group-list-section {
  display: grid;
  gap: 8px;
}

.group-list-section h3 {
  margin: 0;
  font-size: 15px;
}

.member-row.is-muted {
  color: var(--muted);
}

.member-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.mobile-back-hint {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 1000;
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  border-radius: 999px;
  padding: 10px 14px;
  background: rgba(23, 32, 46, .92);
  color: white;
  font-size: 14px;
  transition: opacity .18s ease, transform .18s ease;
}

.mobile-back-hint.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 860px) {
  body {
    background: var(--bg);
  }

  button {
    padding: 10px 12px;
  }

  .login-shell {
    align-items: start;
    grid-template-columns: 1fr;
    min-height: 100dvh;
    padding: max(28px, env(safe-area-inset-top)) 14px 20px;
    background: var(--bg);
  }

  .login-panel {
    width: 100%;
    max-width: 420px;
    justify-self: center;
    border-radius: 8px;
    padding: 24px 18px;
    box-shadow: none;
    backdrop-filter: none;
  }

  .login-panel h1 {
    font-size: 26px;
  }

  .auth-form {
    gap: 14px;
  }

  .auth-form button {
    min-height: 48px;
  }

  .qr-poster-panel {
    display: none;
  }

  .auth-actions button {
    flex: 1 1 120px;
  }

  .shell {
    padding: 0 0 max(22px, env(safe-area-inset-bottom));
  }

  .topbar,
  .workspace {
    flex-direction: column;
    align-items: stretch;
  }

  .day-panel {
    width: 100%;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    gap: 10px;
    margin-bottom: 0;
    padding: max(12px, env(safe-area-inset-top)) 12px 10px;
    background: rgba(247, 248, 250, .96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
  }

  .topbar h1 {
    font-size: 22px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    gap: 8px;
    width: 100%;
  }

  .top-actions span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    align-self: center;
    font-size: 14px;
  }

  .top-actions button {
    min-height: 40px;
    padding: 8px 10px;
    white-space: nowrap;
  }

  .calendar-toolbar {
    display: grid;
    grid-template-columns: 1fr 1.4fr 1fr;
    gap: 8px;
    margin: 10px 0;
    padding: 0 10px;
  }

  .calendar-area,
  .day-panel {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .calendar-area {
    margin: 0 10px;
    padding: 10px 8px 12px;
    border-radius: 8px;
  }

  .weekdays,
  .calendar-grid {
    gap: 5px;
  }

  .weekdays {
    font-size: 12px;
    margin-bottom: 6px;
  }

  .day {
    min-height: 58px;
    border-radius: 6px;
    padding: 6px 4px 5px;
    text-align: center;
  }

  .day-number {
    margin-bottom: 4px;
    font-size: 14px;
    line-height: 1;
  }

  .event-chip,
  .event-empty {
    margin: 0;
    padding: 0 2px;
    border: 0;
    background: transparent;
    min-height: 14px;
    font-size: 10px;
    line-height: 1.2;
    -webkit-line-clamp: 1;
  }

  .event-chip {
    display: block;
    color: #1751b8;
  }

  .event-chip span {
    display: none;
  }

  .day.has-activity::after {
    content: "";
    position: absolute;
    bottom: 6px;
    right: 6px;
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: var(--blue);
  }

  .holiday-badge {
    top: 4px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    font-size: 10px;
  }

  .holiday-name {
    display: none;
  }

  .day-panel {
    margin-top: 12px;
    padding: 14px 10px 18px;
    gap: 12px;
    border-top: 1px solid var(--line);
    background: white;
  }

  .day-panel h2 {
    font-size: 20px;
  }

  .member-form {
    grid-template-columns: 1fr;
  }

  .form-grid,
  #groupForm,
  #joinGroupForm,
  .dialog-actions,
  .group-page-actions {
    grid-template-columns: 1fr;
  }

  .dialog-actions,
  .group-page-actions {
    display: grid;
  }

  .event-list-card {
    grid-template-columns: 1fr;
  }

  .response-actions {
    grid-template-columns: 1fr;
  }

  .member-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
    padding: 0 16px max(18px, env(safe-area-inset-bottom));
    overflow-y: auto;
  }

  .dialog-head {
    position: sticky;
    top: 0;
    z-index: 2;
    margin: 0 -16px 16px;
    padding: max(12px, env(safe-area-inset-top)) 16px 12px;
    background: rgba(255, 255, 255, .97);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
  }

  .activity-form,
  .event-detail,
  .response-editor {
    padding-bottom: 12px;
  }

  #eventForm > button[type="submit"],
  #groupForm button,
  #joinGroupForm button {
    width: 100%;
  }
}

@media (max-width: 430px) {
  .shell {
    padding-left: 0;
    padding-right: 0;
  }

  .topbar,
  .calendar-toolbar {
    padding-left: 10px;
    padding-right: 10px;
  }

  .calendar-area {
    padding-left: 6px;
    padding-right: 6px;
  }

  .day {
    min-height: 52px;
    padding: 5px 3px;
  }

  .event-chip,
  .event-empty {
    font-size: 9px;
  }

  .response-summary {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .top-actions {
    grid-template-columns: 1fr 1fr;
  }

  .top-actions span {
    grid-column: 1 / -1;
  }

  .top-actions button {
    width: 100%;
  }
}
