:root {
  color-scheme: light;
  --bg: #f7efe2;
  --bg-soft: #fff8ee;
  --card: rgba(255, 255, 255, 0.86);
  --card-strong: #ffffff;
  --text: #241b16;
  --muted: #7c6758;
  --border: rgba(95, 66, 45, 0.14);
  --accent: #d85c27;
  --accent-strong: #b94416;
  --accent-soft: #ffe1ce;
  --success: #1f8a5b;
  --warning: #b97914;
  --danger: #b94444;
  --shadow: 0 18px 60px rgba(80, 48, 26, 0.14);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15110f;
  --bg-soft: #201915;
  --card: rgba(42, 32, 27, 0.9);
  --card-strong: #30241e;
  --text: #fff4ea;
  --muted: #c7ad9d;
  --border: rgba(255, 232, 212, 0.13);
  --accent: #ff8a4a;
  --accent-strong: #ffb07e;
  --accent-soft: rgba(255, 138, 74, 0.16);
  --success: #6ed6a2;
  --warning: #f2bf61;
  --danger: #ff8d8d;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, var(--accent-soft), transparent 34rem),
    linear-gradient(180deg, var(--bg), var(--bg-soft));
  color: var(--text);
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px 104px;
}

.topbar,
.section-head,
.month-bar,
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.screen-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar {
  align-items: flex-start;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 18px;
}

.topbar-actions {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 10px;
}

.title-block {
  min-width: 0;
}

.theme-toggle {
  flex: 0 0 auto;
}

.account-chip {
  min-width: min(280px, 46vw);
  max-width: 360px;
}

.account-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  color: var(--muted);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 10px 30px rgba(80, 48, 26, 0.08);
}

.topbar h1,
.hero-card h2,
.section-head h3,
.month-bar h3,
.sheet-head h2 {
  margin: 0;
  line-height: 1.05;
}

.topbar h1 {
  max-width: none;
  font-size: clamp(26px, 5.2vw, 44px);
  letter-spacing: -0.045em;
  white-space: nowrap;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.theme-select,
input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card-strong);
  color: var(--text);
  padding: 13px 14px;
  outline: none;
}

.theme-select {
  min-width: 118px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 74px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card-strong);
  color: var(--text);
  padding: 4px;
}

.theme-toggle-svg {
  width: 64px;
  height: 34px;
  flex: 0 0 auto;
}

.theme-toggle-track {
  fill: var(--accent-soft);
  stroke: var(--border);
  stroke-width: 1.5;
}

.theme-toggle-thumb {
  fill: var(--accent);
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.18));
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.18s ease;
}

.theme-toggle[data-mode="dark"] .theme-toggle-thumb {
  transform: translateX(29px);
}

.theme-toggle-sun,
.theme-toggle-moon {
  fill: none;
  stroke: var(--accent-strong);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.status-panel,
.hero-card,
.calendar-card,
.day-card,
.detail-card,
.sheet-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.status-panel {
  display: grid;
  place-items: center;
  gap: 14px;
  min-height: 280px;
  text-align: center;
  color: var(--muted);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.main-app {
  display: grid;
  gap: 16px;
}

.empty-state p,
.activity-meta,
.response-comment {
  color: var(--muted);
}

.mode-badge,
.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 800;
}

.layout {
  display: grid;
  gap: 16px;
}

.calendar-card,
.day-card,
.detail-card {
  padding: 18px;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card-strong);
  color: var(--text);
  font-size: 26px;
  line-height: 1;
}

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

.weekdays {
  margin: 18px 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.calendar-day {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 64px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card-strong);
  color: var(--text);
  font-weight: 800;
  padding: 10px 5px 18px;
}

.calendar-day.is-muted {
  opacity: 0.35;
}

.calendar-day.is-past {
  cursor: not-allowed;
  opacity: 0.42;
}

.calendar-day.is-selected {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.calendar-day.has-activities::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  transform: translateX(-50%);
}

.activity-count {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 15px;
  height: 15px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 950;
  line-height: 15px;
  text-align: center;
}

.calendar-day.is-selected .activity-count {
  background: #fff;
  color: var(--accent);
}

.activity-day-title {
  position: absolute;
  right: 5px;
  bottom: 8px;
  left: 5px;
  overflow: hidden;
  color: var(--accent-strong);
  font-size: 8px;
  font-weight: 900;
  line-height: 1.1;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-day.is-selected .activity-day-title {
  color: #fff;
}

.activity-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.activity-item,
.response-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card-strong);
  padding: 14px;
}

.activity-item {
  width: 100%;
  color: var(--text);
  text-align: left;
}

.activity-item.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.activity-item h4,
.detail-card h2,
.empty-state h4 {
  margin: 0;
}

.activity-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  font-size: 13px;
}

.empty-state {
  display: grid;
  gap: 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
}

.empty-state.compact {
  margin: 12px 0;
  padding: 14px;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 46px;
  border: 0;
  border-radius: 16px;
  padding: 0 16px;
  font-weight: 900;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.secondary-button {
  border: 1px solid var(--border);
  background: var(--card-strong);
  color: var(--text);
}

.danger-button {
  border: 1px solid rgba(185, 68, 68, 0.32);
  background: rgba(185, 68, 68, 0.12);
  color: var(--danger);
}

input:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.detail-card {
  display: grid;
  gap: 18px;
}

.detail-actions,
.link-row,
.response-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.link-row a {
  color: var(--accent-strong);
  font-weight: 800;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.answer-option {
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--card-strong);
  padding: 12px 8px;
  text-align: center;
  font-weight: 900;
}

.answer-option.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

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

.vote-results {
  display: grid;
  gap: 12px;
  margin: 14px 0 16px;
}

.vote-row {
  display: grid;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card-strong);
  padding: 12px;
}

.vote-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.vote-row-head span {
  color: var(--muted);
  font-weight: 900;
  white-space: nowrap;
}

.vote-bar {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--accent-soft);
}

.vote-bar span {
  display: block;
  min-width: 3px;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
}

.vote-voters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.voter-chip,
.muted-chip {
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 800;
}

.voter-chip {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.muted-chip {
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--border);
}

.response-row {
  display: grid;
  gap: 4px;
}

.fab {
  position: fixed;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 10;
  min-height: 54px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  padding: 0 20px;
  font-weight: 950;
  box-shadow: var(--shadow);
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  gap: 14px;
  max-height: min(92vh, 780px);
  overflow: auto;
  border-radius: 28px 28px 0 0;
  padding: 18px 16px max(22px, env(safe-area-inset-bottom));
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-error {
  margin: 0;
  border-radius: 14px;
  background: rgba(185, 68, 68, 0.12);
  color: var(--danger);
  padding: 12px;
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(88px, calc(env(safe-area-inset-bottom) + 88px));
  z-index: 30;
  width: min(360px, calc(100% - 32px));
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-strong);
  color: var(--text);
  padding: 14px 18px;
  text-align: center;
  font-weight: 900;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

@media (min-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .sheet-panel {
    left: 50%;
    right: auto;
    bottom: 28px;
    width: min(620px, calc(100% - 32px));
    border-radius: var(--radius-xl);
    transform: translateX(-50%);
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding-inline: 12px;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "title theme"
      "account account";
    align-items: start;
    row-gap: 12px;
  }

  .topbar-actions {
    display: contents;
  }

  .title-block {
    grid-area: title;
    padding-right: 8px;
  }

  .topbar h1 {
    font-size: clamp(22px, 7vw, 30px);
    letter-spacing: -0.055em;
  }

  .account-chip {
    grid-area: account;
    width: 100%;
    min-width: 0;
    max-width: none;
    justify-content: space-between;
  }

  .theme-toggle {
    grid-area: theme;
    width: 74px;
    min-width: 0;
    align-self: start;
    justify-self: end;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .screen-title {
    width: 100%;
  }

  .screen-title > div {
    min-width: 0;
  }

  .screen-title h2,
  .screen-title h3 {
    overflow-wrap: anywhere;
  }

  .detail-actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .detail-actions .secondary-button,
  .detail-actions .danger-button {
    width: 100%;
  }

  .answer-grid {
    grid-template-columns: 1fr;
  }

  .vote-row-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .voter-chip,
  .muted-chip {
    max-width: 100%;
    overflow-wrap: anywhere;
    white-space: normal;
  }

  .calendar-card,
  .day-card,
  .detail-card {
    border-radius: 22px;
    padding: 15px;
  }

  .answer-grid {
    grid-template-columns: 1fr;
  }
}
