:root {
  color-scheme: light;
  --canvas: #f5f2ef;
  --surface: #fffdfb;
  --surface-muted: #f8f5f2;
  --surface-tint: #f4ebe8;
  --text: #292522;
  --text-soft: #736b65;
  --text-faint: #9b928b;
  --border: #e6dfd9;
  --border-strong: #d8cec6;
  --action: #8b5f58;
  --action-hover: #754b45;
  --action-soft: #f1dfdb;
  --focus: #356c83;
  --success: #4d7c66;
  --warning: #a36d2e;
  --error: #a84545;
  --rose: #e7bfc9;
  --lavender: #d7cfeb;
  --sage: #bfd6c5;
  --sky: #c7dceb;
  --peach: #e9c9b6;
  --shadow-soft: 0 16px 45px rgba(68, 53, 44, 0.09);
  --shadow-paper: 0 20px 50px rgba(55, 45, 39, 0.13), 0 2px 8px rgba(55, 45, 39, 0.05);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --header-height: 64px;
  --footer-height: 30px;
  --sidebar-width: 312px;
  --motion-fast: 160ms ease;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="lavender"] { --canvas: #f3f0f7; --surface-tint: #eee9f6; --action: #6f608d; --action-hover: #594a75; --action-soft: #e6def2; }
html[data-theme="sage"] { --canvas: #f0f4f0; --surface-tint: #e7efe8; --action: #55745f; --action-hover: #41604b; --action-soft: #dce9df; }
html[data-theme="sky"] { --canvas: #eff4f7; --surface-tint: #e4eef4; --action: #4d7185; --action-hover: #385c70; --action-soft: #dae9f1; }
html[data-theme="peach"] { --canvas: #f7f1ed; --surface-tint: #f4e8df; --action: #8a604c; --action-hover: #704936; --action-soft: #f0dfd4; }

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  margin: 0;
}

body {
  color: var(--text);
  background: var(--canvas);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

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

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  border: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

button:not(:disabled) {
  cursor: pointer;
}

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

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 78%, white);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: white;
  background: var(--text);
  transform: translateY(-160%);
  transition: transform var(--motion-fast);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  display: grid;
  grid-template-rows: var(--header-height) minmax(0, 1fr) var(--footer-height);
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(270px, 1.15fr) auto;
  align-items: center;
  gap: 18px;
  min-width: 0;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 94%, var(--surface-tint));
}

.brand,
.brand-copy,
.calendar-context,
.header-actions,
.preview-meta,
.category-legend,
.legal-footer {
  display: flex;
  align-items: center;
}

.brand {
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  display: grid;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--action) 18%, transparent);
  border-radius: 12px;
  color: var(--action);
  background: linear-gradient(145deg, #fff 15%, var(--action-soft));
}

.brand-mark svg {
  width: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.brand-copy {
  min-width: 0;
  align-items: flex-start;
  flex-direction: column;
  line-height: 1.15;
}

.brand-copy strong,
.calendar-switcher strong {
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy strong {
  letter-spacing: -0.015em;
}

.brand-copy span,
.calendar-switcher small,
.save-status,
.field-hint,
.month-control small,
.control-copy span,
.section-description {
  color: var(--text-soft);
}

.brand-copy span {
  margin-top: 3px;
  font-size: 11px;
}

.calendar-context {
  justify-content: center;
  gap: 12px;
  min-width: 0;
}

.calendar-switcher {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 230px;
  max-width: 360px;
  height: 44px;
  padding: 5px 12px 5px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  text-align: left;
  background: var(--surface);
}

.calendar-switcher > span {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.calendar-switcher small {
  font-size: 10px;
}

.calendar-switcher svg,
.button svg,
.icon-button svg,
.section-tab svg,
.mobile-tabbar svg,
.notice-card svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.calendar-switcher svg {
  width: 18px;
}

.save-status {
  gap: 6px;
  flex: 0 0 auto;
  font-size: 12px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning) 15%, transparent);
}

.save-status[data-state="saved"] .status-dot {
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 15%, transparent);
}

.save-status[data-state="saving"] .status-dot {
  background: var(--warning);
}

.save-status[data-state="failed"] .status-dot,
.save-status[data-state="unavailable"] .status-dot {
  background: var(--error);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--error) 15%, transparent);
}

.storage-banner {
  position: fixed;
  z-index: 90;
  top: calc(var(--header-height) + 8px);
  left: 50%;
  display: flex;
  width: min(92vw, 720px);
  min-height: 46px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px 9px 14px;
  border: 1px solid color-mix(in srgb, var(--warning) 30%, var(--border));
  border-radius: 14px;
  color: #5b4327;
  background: #fff8ed;
  box-shadow: var(--shadow-soft);
  transform: translateX(-50%);
  font-size: 11px;
}

.storage-banner[hidden] {
  display: none;
}

.storage-banner > div {
  display: flex;
  gap: 6px;
}

.storage-banner button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: inherit;
  background: transparent;
  font-size: 10px;
  font-weight: 800;
}

html[data-readonly="true"] .day-cell[tabindex="0"] {
  cursor: default;
}

.header-actions {
  justify-content: flex-end;
  gap: 8px;
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  transition: background var(--motion-fast), border-color var(--motion-fast), color var(--motion-fast), transform var(--motion-fast);
}

.button {
  min-height: 40px;
  gap: 7px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.button svg {
  width: 17px;
}

.button-primary {
  color: white;
  background: var(--action);
}

.button-primary:not(:disabled):hover {
  background: var(--action-hover);
  transform: translateY(-1px);
}

.button-secondary {
  border-color: var(--border);
  background: var(--surface);
}

.button-secondary:not(:disabled):hover {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.button-danger {
  color: white;
  background: var(--error);
}

.button-wide {
  width: 100%;
  background: var(--action-soft);
}

.icon-button {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  border-color: var(--border);
  border-radius: 50%;
  background: var(--surface);
}

.icon-button svg {
  width: 18px;
}

.icon-button:not(:disabled):hover {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.mobile-action,
.sidebar-close,
.mobile-tabbar,
.mobile-actions-panel,
.panel-scrim {
  display: none;
}

.workspace {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  position: relative;
  z-index: 12;
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.sidebar-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 20px 16px;
}

.sidebar-heading h1,
.control-section h2,
.preview-toolbar h2 {
  margin: 2px 0 0;
  letter-spacing: -0.025em;
}

.sidebar-heading h1 {
  max-width: 230px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  font-weight: 500;
  line-height: 1.12;
}

.eyebrow,
.calendar-kicker {
  color: var(--action);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.section-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  margin: 0 14px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-muted);
}

.section-tab {
  display: flex;
  min-width: 0;
  min-height: 54px;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex-direction: column;
  padding: 5px 2px;
  border: 0;
  border-radius: 10px;
  color: var(--text-soft);
  background: transparent;
  font-size: 10px;
  font-weight: 700;
}

.section-tab svg {
  width: 18px;
}

.section-tab.is-active {
  color: var(--action);
  background: var(--surface);
  box-shadow: 0 3px 10px rgba(60, 45, 36, 0.07);
}

.sidebar-content {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.control-section {
  padding: 22px 20px 28px;
}

.control-section[hidden] {
  display: none;
}

.control-section h2 {
  font-size: 17px;
}

.section-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.phase-badge {
  flex: 0 0 auto;
  padding: 5px 8px;
  border-radius: 999px;
  color: var(--action);
  background: var(--action-soft);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.field-group {
  display: flex;
  margin-bottom: 16px;
  flex-direction: column;
  gap: 7px;
}

.field-group label {
  font-size: 12px;
  font-weight: 750;
}

.field-group input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: var(--surface-muted);
}

.field-hint {
  font-size: 10px;
}

.month-control {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  gap: 8px;
  margin: 18px 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
}

.month-control > div {
  display: flex;
  align-items: center;
  flex-direction: column;
  line-height: 1.3;
}

.month-control small {
  font-size: 10px;
}

.control-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}

.control-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.control-copy strong {
  font-size: 12px;
}

.control-copy span {
  font-size: 10px;
}

.switch {
  position: relative;
  flex: 0 0 40px;
  width: 40px;
  height: 23px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--border-strong);
}

.switch span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(42, 34, 29, 0.2);
}

.switch.is-on {
  background: var(--action);
}

.switch.is-on span {
  left: 20px;
}

.notice-card {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  padding: 13px;
  border: 1px solid color-mix(in srgb, var(--warning) 20%, var(--border));
  border-radius: var(--radius-md);
  color: color-mix(in srgb, var(--warning) 75%, var(--text));
  background: color-mix(in srgb, var(--warning) 7%, white);
}

.notice-card svg {
  flex: 0 0 18px;
  width: 18px;
}

.notice-card p {
  margin: 0;
  font-size: 10px;
}

.section-description {
  margin: 10px 0 20px;
  font-size: 12px;
}

.manage-categories-button {
  margin-top: 10px;
}

.event-summary {
  display: grid;
  gap: 7px;
  margin-top: 18px;
}

.event-summary-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  font-size: 11px;
}

.event-summary-item span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-summary-empty {
  color: var(--text-soft);
  font-size: 11px;
}

.swatch-row {
  display: flex;
  gap: 10px;
}

.theme-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 0;
  border: 0;
  margin: 18px 0;
}

.theme-picker legend,
.control-label {
  margin-bottom: 8px;
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 750;
}

.theme-picker label {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 11px;
}

.theme-picker input { margin: 0; }
.theme-picker .swatch { width: 22px; height: 22px; border-width: 2px; }

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

.color-grid label { color: var(--text-soft); font-size: 10px; }
.color-grid input { display: block; width: 100%; min-height: 38px; margin-top: 5px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); }
.logo-controls { display: grid; gap: 10px; padding-top: 16px; border-top: 1px solid var(--border); margin-top: 16px; }
.control-label { display: block; margin-top: 18px; }

.data-tools-dialog .dialog-card { width: min(760px, calc(100vw - 32px)); }
.data-tools-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.data-tool-card { display: flex; min-width: 0; flex-direction: column; align-items: flex-start; gap: 10px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-muted); }
.data-tool-card h3, .data-tool-card p { margin: 0; }
.data-tool-card h3 { font-size: 14px; }
.data-tool-card p { color: var(--text-soft); font-size: 11px; }
.data-tool-card .button { width: 100%; }
.data-tool-card input[type="text"] { width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.data-tool-danger { grid-column: 1 / -1; border-color: color-mix(in srgb, var(--error) 28%, var(--border)); background: color-mix(in srgb, var(--error) 5%, var(--surface)); }
.data-tools-status { min-height: 42px; padding: 10px 18px 16px; margin: 0; color: var(--text-soft); font-size: 11px; }
.data-tools-status.is-error { color: var(--error); font-weight: 700; }

.output-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
}
.output-summary strong { font-family: Georgia, "Times New Roman", serif; font-size: 18px; font-weight: 400; }
.output-summary span { color: var(--text-soft); font-size: 11px; font-weight: 750; }

.pwa-help-content { display: grid; gap: 12px; }
.pwa-help-content h3, .pwa-help-content ol, .pwa-help-content p { margin: 0; }
.pwa-help-content ol { display: grid; gap: 8px; padding-left: 22px; color: var(--text-soft); font-size: 12px; }
.pwa-status { padding: 10px 12px; border: 1px solid color-mix(in srgb, var(--success) 28%, var(--border)); border-radius: 12px; color: #365f4c; background: #f1f8f3; font-size: 11px; font-weight: 700; }
.update-banner { position: fixed; z-index: 110; right: 18px; bottom: calc(var(--footer-height) + 18px); display: flex; width: min(92vw, 520px); min-height: 52px; align-items: center; gap: 10px; padding: 9px 10px 9px 14px; border: 1px solid var(--border-strong); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-soft); font-size: 11px; }
.update-banner[hidden] { display: none; }
.update-banner span { flex: 1; }
.update-banner button { min-height: 36px; padding: 0 11px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-muted); font-size: 10px; font-weight: 800; }
.update-banner button:first-of-type { border-color: transparent; color: white; background: var(--action); }

.swatch {
  width: 36px;
  height: 36px;
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--border), 0 3px 8px rgba(50, 40, 34, 0.08);
}

.swatch-rose { background: var(--rose); }
.swatch-lavender { background: var(--lavender); }
.swatch-sage { background: var(--sage); }
.swatch-sky { background: var(--sky); }
.swatch-peach { background: var(--peach); }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-muted);
}

.segmented button {
  min-height: 40px;
  border: 0;
  border-radius: 9px;
  background: transparent;
}

.segmented .is-selected {
  background: white;
  box-shadow: 0 2px 8px rgba(50, 40, 34, 0.08);
}

.preview-workspace {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: 58px minmax(0, 1fr);
  background:
    radial-gradient(circle at 86% 12%, rgba(223, 207, 196, 0.36), transparent 27%),
    radial-gradient(circle at 12% 92%, rgba(207, 220, 211, 0.3), transparent 30%),
    var(--canvas);
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 22px 4px;
}

.preview-toolbar h2 {
  font-size: 16px;
}

.preview-meta {
  gap: 5px;
}

.preview-meta span {
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-soft);
  background: color-mix(in srgb, white 78%, transparent);
  font-size: 9px;
  font-weight: 750;
}

.canvas-stage {
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  padding: 14px 24px 22px;
  overflow: hidden;
}

.calendar-page {
  --page-ratio: 1.414;
  --document-heading: Georgia, "Times New Roman", serif;
  --document-body: Arial, Helvetica, sans-serif;
  --document-accent: #8b5f58;
  --document-text: #292522;
  --document-background: #ffffff;
  display: grid;
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: var(--page-ratio) / 1;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  padding: clamp(14px, 2.3vw, 28px);
  border: 1px solid rgba(128, 108, 94, 0.13);
  border-radius: clamp(15px, 2vw, 22px);
  color: var(--document-text);
  background: var(--document-background);
  font-family: var(--document-body);
  box-shadow: var(--shadow-paper);
  container-type: size;
  overflow: hidden;
}

.calendar-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 1.2cqh;
  border-bottom: 1px solid #eadfd8;
}

.calendar-header h2 {
  margin: 0.3cqh 0 0;
  color: var(--document-accent);
  font-family: var(--document-heading);
  font-size: clamp(25px, 7cqh, 50px);
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: -0.045em;
}

.calendar-kicker {
  font-size: clamp(7px, 1.6cqh, 11px);
}

.calendar-year {
  color: var(--document-accent);
  font-family: var(--document-heading);
  font-size: clamp(22px, 5cqh, 38px);
  line-height: 1;
}

.calendar-branding { display: flex; align-items: center; gap: 1.5cqw; }
.calendar-logo { width: var(--logo-size); max-width: 180px; max-height: 7cqh; object-fit: contain; }
.calendar-page[data-logo-align="LEFT"] .calendar-header { flex-direction: row-reverse; }
.calendar-page[data-logo-align="CENTER"] .calendar-header { display: grid; grid-template-columns: 1fr auto 1fr; }
.calendar-page[data-logo-align="CENTER"] .calendar-branding { grid-column: 2; }
.calendar-page[data-logo-align="CENTER"] .calendar-header > div:first-child { grid-column: 1; grid-row: 1; }

.category-legend {
  justify-content: flex-end;
  gap: clamp(8px, 2.5cqw, 22px);
  min-height: clamp(18px, 5cqh, 32px);
  color: var(--text-soft);
  font-size: clamp(6px, 1.6cqh, 10px);
}

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

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.dot-sage { background: #9fbea7; }
.dot-rose { background: #dcaaba; }
.dot-sky { background: #a9c9dc; }

.calendar-grid {
  display: grid;
  min-height: 0;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: auto minmax(0, 1fr);
  border-top: 1px solid #ded5cf;
  border-left: 1px solid #ded5cf;
}

.calendar-page[data-grid-style="SOFT"] .calendar-grid,
.calendar-page[data-grid-style="SOFT"] .day-cell,
.calendar-page[data-grid-style="SOFT"] .weekday { border-color: color-mix(in srgb, var(--document-accent) 18%, white); }
.calendar-page[data-grid-style="BOLD"] .calendar-grid,
.calendar-page[data-grid-style="BOLD"] .day-cell,
.calendar-page[data-grid-style="BOLD"] .weekday { border-color: color-mix(in srgb, var(--document-accent) 48%, #777); border-width: 1.5px; }
.week-number { position: absolute; top: 0.5cqh; left: 0.5cqw; color: var(--document-accent); font-size: clamp(5px, 1.2cqh, 8px); font-weight: 800; }
.calendar-grid.has-week-numbers .day-number { margin-left: 1.8cqw; }

.weekday {
  padding: clamp(3px, 1cqh, 7px);
  border-right: 1px solid #ded5cf;
  border-bottom: 1px solid #ded5cf;
  color: #756c66;
  background: #faf7f5;
  font-size: clamp(6px, 1.55cqh, 10px);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
}

.weekday.weekend {
  background: #f8f2ef;
}

.calendar-days {
  display: grid;
  min-height: 0;
  grid-column: 1 / -1;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
}

.day-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: clamp(3px, 1cqh, 7px);
  border-right: 1px solid #ded5cf;
  border-bottom: 1px solid #ded5cf;
  background: white;
  overflow: hidden;
}

.day-cell.is-current {
  outline: 2px solid color-mix(in srgb, var(--action) 35%, transparent);
  outline-offset: -2px;
}

.day-cell[tabindex="0"] {
  cursor: pointer;
}

.day-cell[tabindex="0"]:focus-visible {
  z-index: 2;
  outline: 3px solid var(--focus);
  outline-offset: -3px;
}

.day-cell[data-weekend="true"] {
  background: #fffbf9;
}

.day-cell.is-outside {
  color: #c4bbb5;
  background: #fbf9f7;
}

.day-number {
  display: block;
  margin-bottom: clamp(1px, 0.6cqh, 4px);
  font-size: clamp(7px, 2cqh, 12px);
  font-weight: 750;
}

.event-card {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  padding: clamp(2px, 0.65cqh, 4px) clamp(3px, 0.8cqw, 6px);
  border-radius: 999px;
  font-size: clamp(5px, 1.45cqh, 9px);
  font-weight: 700;
  line-height: 1.15;
}

button.event-card {
  width: 100%;
  border: 0;
  text-align: left;
}

button.event-card:hover {
  filter: saturate(1.08) brightness(0.98);
}

.event-card > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-school { color: #3f5f49; background: #e7f0e9; }
.event-personal { color: #754c59; background: #f5e6eb; }
.event-planning { color: #42657a; background: #e5f0f6; }

.event-dot {
  flex: 0 0 5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.event-dot-school { background: #7ba187; }
.event-dot-personal { background: #c7889e; }
.event-dot-planning { background: #7aaac2; }

.calendar-notes {
  display: grid;
  grid-template-columns: auto minmax(180px, 0.55fr);
  align-items: end;
  gap: 2cqw;
  padding-top: 1.2cqh;
}

.calendar-notes > div:first-child {
  display: flex;
  flex-direction: column;
}

.calendar-notes span {
  color: var(--text-soft);
  font-size: clamp(6px, 1.4cqh, 9px);
}

.calendar-notes strong {
  max-width: 55cqw;
  overflow: hidden;
  font-family: var(--document-heading);
  font-size: clamp(8px, 2cqh, 13px);
  font-weight: 400;
}

.notes-lines {
  display: grid;
  gap: 1cqh;
}

.notes-lines span {
  display: block;
  border-bottom: 1px solid #e5ddd7;
}

.legal-footer {
  z-index: 25;
  justify-content: center;
  padding: 0 16px;
  border-top: 1px solid var(--border);
  color: var(--text-soft);
  background: var(--surface);
  font-size: 10px;
  text-align: center;
}

.legal-footer a {
  margin: 0 3px;
  color: var(--action);
  font-weight: 800;
}

.app-dialog {
  width: min(92vw, 560px);
  max-height: min(88dvh, 760px);
  padding: 0;
  border: 0;
  border-radius: 22px;
  color: var(--text);
  background: transparent;
  box-shadow: var(--shadow-soft);
  overflow: visible;
}

.app-dialog.dialog-wide {
  width: min(92vw, 680px);
}

.app-dialog::backdrop {
  background: rgba(39, 31, 27, 0.48);
  backdrop-filter: blur(3px);
}

.dialog-card {
  display: flex;
  max-height: min(88dvh, 760px);
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  overflow: hidden;
}

.dialog-card-wide {
  width: min(92vw, 680px);
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  background: var(--surface);
}

.dialog-header {
  border-bottom: 1px solid var(--border);
}

.dialog-header h2 {
  margin: 2px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  font-weight: 500;
}

.dialog-body,
.calendar-list,
.category-editor-list {
  min-height: 0;
  padding: 18px;
  overflow-y: auto;
}

.dialog-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}

.dialog-actions-split {
  justify-content: space-between;
}

.dialog-actions-split > div {
  display: flex;
  gap: 8px;
}

.event-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 14px;
}

.field-span {
  grid-column: 1 / -1;
}

.dialog-body input,
.dialog-body select,
.dialog-body textarea,
.category-editor-row input[type="text"] {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: white;
}

.dialog-body textarea {
  min-height: 76px;
  resize: vertical;
}

.check-field {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 9px;
  align-self: end;
  margin-bottom: 16px;
  font-weight: 700;
}

.check-field input {
  width: 20px;
  height: 20px;
  accent-color: var(--action);
}

.field-error {
  min-height: 14px;
  color: var(--error);
  font-size: 10px;
}

.calendar-list {
  display: grid;
  gap: 10px;
}

.calendar-list-empty {
  padding: 28px 10px;
  color: var(--text-soft);
  text-align: center;
}

.calendar-list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
}

.calendar-list-row.is-active {
  border-color: color-mix(in srgb, var(--action) 40%, var(--border));
  background: color-mix(in srgb, var(--action-soft) 48%, white);
}

.calendar-list-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.calendar-list-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-list-copy span {
  color: var(--text-soft);
  font-size: 11px;
}

.calendar-list-actions {
  display: flex;
  gap: 6px;
}

.calendar-list-actions button {
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: white;
  font-size: 10px;
  font-weight: 750;
}

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

.category-editor-row {
  display: grid;
  grid-template-columns: 28px 48px minmax(120px, 1fr) 48px auto;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.category-editor-row > span {
  color: var(--text-soft);
  font-size: 10px;
  font-weight: 800;
}

.category-editor-row input[type="color"] {
  width: 40px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
}

.category-editor-row label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
}

body:has(dialog[open]) {
  overflow: hidden;
}

@media (max-width: 1180px) {
  .pwa-help-button { display: none; }
  :root {
    --sidebar-width: 286px;
  }

  .topbar {
    grid-template-columns: minmax(190px, 0.8fr) minmax(220px, 1fr) auto;
    gap: 10px;
    padding-inline: 14px;
  }

  .brand-copy span,
  .save-status,
  .desktop-action {
    display: none;
  }

  .calendar-switcher {
    min-width: 210px;
  }
}

@media (max-width: 1023px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr) minmax(210px, 0.8fr) auto;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    z-index: 60;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(360px, calc(100vw - 48px));
    border-right: 1px solid var(--border);
    border-radius: 0 22px 22px 0;
    box-shadow: var(--shadow-soft);
    transform: translateX(-105%);
    transition: transform var(--motion-fast);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-close,
  .panel-scrim {
    display: flex;
  }

  .panel-scrim {
    position: fixed;
    z-index: 50;
    inset: 0;
    border: 0;
    background: rgba(39, 31, 27, 0.35);
    opacity: 0;
    transition: opacity var(--motion-fast);
  }

  .panel-scrim.is-visible {
    opacity: 1;
  }

  .preview-workspace {
    grid-template-rows: 56px minmax(0, 1fr);
  }

  .canvas-stage {
    padding: 12px 18px 20px;
  }

  .calendar-page {
    width: auto;
    height: 100%;
  }
}

@media (max-width: 767px) {
  :root {
    --header-height: 58px;
    --footer-height: 42px;
    --tabbar-height: 70px;
  }

  .app-shell {
    grid-template-rows: var(--header-height) minmax(0, 1fr) var(--footer-height) var(--tabbar-height);
  }

  .data-tools-dialog .dialog-card { width: 100%; }
  .data-tools-grid { grid-template-columns: 1fr; }
  .data-tool-danger { grid-column: auto; }
  .update-banner { right: 10px; bottom: calc(var(--footer-height) + var(--tabbar-height) + 10px); left: 10px; width: auto; flex-wrap: wrap; }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 0 10px;
  }

  .brand-mark {
    flex-basis: 36px;
    width: 36px;
    height: 36px;
  }

  .brand-copy strong {
    font-size: 13px;
  }

  .calendar-context,
  .button-primary {
    display: none;
  }

  .mobile-action {
    display: inline-flex;
  }

  .preview-workspace {
    grid-template-rows: 50px minmax(0, 1fr);
  }

  .preview-toolbar {
    padding: 7px 14px 2px;
  }

  .preview-meta span:nth-child(2),
  .preview-meta span:nth-child(3) {
    display: none;
  }

  .canvas-stage {
    align-items: start;
    padding: 8px 12px 12px;
    overflow: auto;
    overscroll-behavior: contain;
  }

  .calendar-page {
    width: max(100%, 620px);
    height: auto;
    max-height: none;
    aspect-ratio: var(--page-ratio) / 1;
    transform-origin: top left;
  }

  .legal-footer {
    padding: 3px 14px;
    font-size: 8.5px;
    line-height: 1.25;
  }

  .mobile-tabbar {
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 5px max(8px, env(safe-area-inset-right)) calc(5px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 96%, var(--surface-tint));
  }

  .mobile-tabbar button {
    display: flex;
    min-width: 0;
    min-height: 48px;
    align-items: center;
    justify-content: center;
    gap: 3px;
    flex-direction: column;
    border: 0;
    border-radius: 12px;
    color: var(--text-soft);
    background: transparent;
    font-size: 9px;
    font-weight: 750;
  }

  .mobile-tabbar button.is-active {
    color: var(--action);
    background: var(--action-soft);
  }

  .mobile-tabbar svg {
    width: 20px;
  }

  .mobile-actions-panel {
    position: fixed;
    z-index: 70;
    top: 52px;
    right: 10px;
    display: grid;
    width: 180px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow-soft);
  }

  .mobile-actions-panel[hidden] {
    display: none;
  }

  .mobile-actions-panel button {
    min-height: 44px;
    padding: 0 12px;
    border: 0;
    border-radius: 10px;
    text-align: left;
    background: transparent;
  }

  body.has-panel-open {
    overflow: hidden;
  }

  .app-dialog,
  .dialog-card,
  .dialog-card-wide {
    width: calc(100vw - 16px);
    max-width: none;
    max-height: calc(100dvh - 16px);
  }

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

  .field-span {
    grid-column: auto;
  }

  .dialog-actions-split {
    align-items: stretch;
    flex-direction: column;
  }

  .dialog-actions-split > div {
    justify-content: flex-end;
  }

  .category-editor-row {
    grid-template-columns: 24px 44px minmax(0, 1fr);
  }

  .category-editor-row input[type="color"]:nth-of-type(2),
  .category-editor-row label {
    display: none;
  }

  .calendar-list-row {
    grid-template-columns: 1fr;
  }

  .calendar-list-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 389px) {
  .brand-copy strong {
    max-width: 180px;
  }

  .preview-toolbar h2 {
    font-size: 14px;
  }

  .canvas-stage {
    padding-inline: 8px;
  }
}

@media (max-height: 699px) and (min-width: 1024px) {
  .app-shell {
    grid-template-rows: 58px minmax(0, 1fr) 28px;
  }

  .preview-workspace {
    grid-template-rows: 48px minmax(0, 1fr);
  }

  .sidebar-heading {
    padding-block: 13px 10px;
  }

  .section-tabs {
    grid-template-columns: repeat(4, 1fr);
  }

  .section-tab {
    min-height: 44px;
  }

  .control-section {
    padding-top: 14px;
  }

  .calendar-page {
    width: min(100%, calc((100dvh - 58px - 28px - 78px) * 1.414));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media print {
  html,
  body {
    width: var(--print-page-width);
    height: var(--print-page-height);
    padding: 0;
    margin: 0;
    background: white;
    overflow: hidden;
  }

  .topbar,
  .sidebar,
  .preview-toolbar,
  .legal-footer,
  .mobile-tabbar,
  .mobile-actions-panel {
    display: none !important;
  }

  dialog,
  .storage-banner,
  .panel-scrim {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .preview-workspace,
  .canvas-stage {
    display: block;
    width: auto;
    height: auto;
    overflow: visible;
    background: white;
  }

  .calendar-page {
    width: var(--print-page-width);
    height: var(--print-page-height);
    max-width: none;
    max-height: none;
    aspect-ratio: auto;
    padding: 8mm;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    break-after: avoid;
    break-inside: avoid;
    page-break-after: avoid;
    page-break-inside: avoid;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
