:root {
  --vh: 1vh;
  --hud-bg: #f5f5f5;
  --hud-text: #151515;
  --hud-border: rgba(0, 0, 0, 0.16);
  --modal-bg: rgba(255, 255, 255, 0.78);
  --modal-header-bg: rgba(255, 255, 255, 0.82);
  --modal-text: #1a1a1a;
  --modal-border: rgba(255, 255, 255, 0.4);
  --field-bg: rgba(255, 255, 255, 0.92);
  --field-text: #111;
  --field-border: rgba(0, 0, 0, 0.2);
  --control-bg: rgba(17, 17, 17, 0.08);
  --control-bg-active: rgba(17, 17, 17, 0.22);
  --control-text: #123d8e;
  --control-text-active: #0f56ff;
  --surface-subtle: rgba(255, 255, 255, 0.55);
  --surface-border: rgba(0, 0, 0, 0.12);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  --grid-line: #888;
  --weekday-bg: #fff;
  --weekend-bg: #fff3c4;
  --void-bg: #d0d0d0;
  --outer-bg: #fff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--outer-bg);
  color: #111;
  height: calc(var(--vh) * 100);
  overflow: hidden;
}

:root[data-theme="dark"] {
  --hud-bg: rgba(21, 24, 30, 0.94);
  --hud-text: #f1f5ff;
  --hud-border: rgba(202, 212, 232, 0.25);
  --modal-bg: rgba(16, 18, 22, 0.86);
  --modal-header-bg: rgba(12, 15, 20, 0.94);
  --modal-text: #edf2ff;
  --modal-border: rgba(190, 202, 235, 0.2);
  --field-bg: rgba(7, 10, 14, 0.9);
  --field-text: #f3f7ff;
  --field-border: rgba(185, 200, 235, 0.35);
  --control-bg: rgba(66, 85, 124, 0.36);
  --control-bg-active: rgba(105, 143, 231, 0.35);
  --control-text: #d7e6ff;
  --control-text-active: #ffffff;
  --surface-subtle: rgba(38, 44, 58, 0.76);
  --surface-border: rgba(184, 196, 230, 0.25);
  --shadow: 0 14px 32px rgba(0, 0, 0, 0.45);
}

#app {
  height: 100%;
  width: 100%;
}

.app-shell {
  position: relative;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.modal-backdrop.login-screen {
  padding: 24px;
  background: var(--outer-bg);
}

.login-modal {
  width: min(360px, 92vw);
}

.login-modal-content input {
  width: 100%;
}

.login-error {
  color: #b00020;
  font-size: 13px;
  min-height: 18px;
}

.hud-layer {
  position: absolute;
  inset: calc(env(safe-area-inset-top) + 8px) 8px auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  z-index: 30;
  pointer-events: none;
}

.hud-group {
  position: relative;
  pointer-events: auto;
}

.hud-capsule {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: var(--hud-bg);
  color: var(--hud-text);
  border-radius: 999px;
  border: 1px solid var(--hud-border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  pointer-events: auto;
}

.hud-capsule button {
  min-width: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 999px;
  color: inherit;
  font-size: 24px;
  line-height: 1;
}

.hud-capsule .year-nav {
  display: flex;
  align-items: center;
  gap: 2px;
}

.hud-capsule .year-nav span {
  min-width: 58px;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
}

.hud-capsule .year-nav button {
  font-size: 26px;
}

.calendar-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--modal-header-bg);
  border: 1px solid var(--surface-border);
  color: var(--modal-text);
  border-radius: 10px;
  padding: 10px;
  box-shadow: var(--shadow);
  z-index: 32;
}

.calendar-popover label {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}

.grid-container {
  flex: 1;
  position: relative;
  padding-top: 56px;
  overflow: hidden;
}

.grid-scroll {
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  position: relative;
}

.grid-scroll.fallback-scroll {
  overflow-y: auto;
}

.grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-template-rows: 24px repeat(31, var(--row-height, 18px));
  min-width: 960px;
  border: var(--year-border-width, 2px) solid var(--year-border-color, #333);
  background: var(--outer-bg);
}

.grid-header {
  grid-row: 1;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  background: var(--month-header-bg, #fff);
  color: var(--month-header-color, #111);
  user-select: none;
  -webkit-user-select: none;
}

.grid-cell {
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  position: relative;
  background: var(--weekday-bg);
}

/* Tweak this to control past-date gridline de-emphasis strength (lower % => more inactive look). */
.grid-cell.past {
  border-right-color: color-mix(in srgb, var(--grid-line) 46%, var(--weekday-bg));
  border-bottom-color: color-mix(in srgb, var(--grid-line) 46%, var(--weekday-bg));
}

/* Keep weekend past-cells blending against weekend background (not weekday background). */
.grid-cell.past.weekend {
  border-right-color: color-mix(in srgb, var(--grid-line) 46%, var(--weekend-bg));
  border-bottom-color: color-mix(in srgb, var(--grid-line) 46%, var(--weekend-bg));
}

.grid-cell.weekend {
  background: var(--weekend-bg);
}

.grid-cell.void {
  background: var(--void-bg);
}

.day-number {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: var(--day-number-size, 12px);
  font-weight: var(--day-number-weight, 500);
  color: var(--day-number-color, #111);
  user-select: none;
  -webkit-user-select: none;
}

/* Tweak this to increase/decrease the past-date day-number de-emphasis. */
.grid-cell.past .day-number {
  opacity: 0.38;
  color: color-mix(in srgb, var(--day-number-color, #111) 70%, var(--weekday-bg));
}

.grid-cell.past.weekend .day-number {
  color: color-mix(in srgb, var(--day-number-color, #111) 70%, var(--weekend-bg));
}

.grid-cell.today .day-number {
  font-weight: calc(var(--day-number-weight, 500) + 140);
  opacity: 1;
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 3;
}

.today-overlay {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 4;
}

/* Tweak ring color/alpha/width here to adjust today prominence. */
.today-marker {
  position: absolute;
  box-sizing: border-box;
  border: 2px solid color-mix(in srgb, var(--year-border-color, #333) 70%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #fff 45%, transparent);
}

.segment {
  position: absolute;
  border-radius: 6px;
  padding: 2px;
  overflow: hidden;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--fabric-gradient, #ddd);
  color: var(--fabric-text, #111);
  border: 1px solid var(--fabric-border, rgba(0, 0, 0, 0.24));
  box-shadow:
    inset 0 1px 0 var(--fabric-highlight, rgba(255, 255, 255, 0.35)),
    0 2px 5px var(--fabric-shadow, rgba(0, 0, 0, 0.2));
}

.segment .label,
.swatch .label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: var(--fabric-text-shadow, none);
}

.segment.vertical .label {
  transform-origin: center;
  flex-shrink: 0;
}

.segment.align-left .label {
  text-align: left;
}

.segment.align-right .label {
  text-align: right;
}

.segment.align-center .label {
  text-align: center;
}


.fabric--sunset {
  --fabric-gradient: linear-gradient(135deg, #ffbf47, #fff642);
  --fabric-text: #2d1f00;
  --fabric-border: #d5692f;
  --fabric-highlight: rgba(255, 241, 199, 0.5);
  --fabric-shadow: rgba(101, 71, 8, 0.22);
}

.fabric--garnet {
  --fabric-gradient: linear-gradient(135deg, #6e0a2b, #a60f3f);
  --fabric-text: #fff;
  --fabric-border: #5b0724;
  --fabric-highlight: rgba(255, 214, 226, 0.28);
  --fabric-shadow: rgba(74, 8, 30, 0.3);
}

.fabric--glacier {
  --fabric-gradient: linear-gradient(135deg, #8fd3f4, #84fab0);
  --fabric-text: #0b2c35;
  --fabric-border: #5fb2ce;
  --fabric-highlight: rgba(225, 251, 255, 0.42);
  --fabric-shadow: rgba(21, 80, 92, 0.2);
}
.fabric--dune {
  --fabric-gradient: linear-gradient(135deg, #f8e9af 0%, #eff28f 100%);
  --fabric-text: #2f2a22;
  --fabric-border: #cfb67b;
  --fabric-highlight: rgba(255, 251, 239, 0.55);
  --fabric-shadow: rgba(93, 78, 40, 0.2);
}

.fabric--leaf {
  --fabric-gradient: linear-gradient(135deg, #5b9f5c 0%, #3f7f46 100%);
  --fabric-text: #f2f8f1;
  --fabric-border: #2f6034;
  --fabric-highlight: rgba(234, 248, 233, 0.32);
  --fabric-shadow: rgba(33, 67, 35, 0.26);
}

.fabric--cobalt {
  --fabric-gradient: linear-gradient(135deg, #2d5dcf 0%, #1a2f71 100%);
  --fabric-text: #f4f8ff;
  --fabric-border: #16295f;
  --fabric-highlight: rgba(219, 232, 255, 0.35);
  --fabric-shadow: rgba(18, 35, 85, 0.28);
}

.fabric--fog {
  --fabric-gradient: linear-gradient(135deg, #f3f4f6 0%, #dde1e6 100%);
  --fabric-text: #3f464f;
  --fabric-border: #9ca5af;
  --fabric-highlight: rgba(255, 255, 255, 0.45);
  --fabric-shadow: rgba(73, 80, 92, 0.12);
}

.fabric--siren {
  --fabric-gradient: linear-gradient(135deg, #ff6767 0%, #ff002f 100%);
  --fabric-text: #fff;
  --fabric-border: #661021;
  --fabric-highlight: rgba(255, 220, 220, 0.35);
  --fabric-shadow: rgba(84, 11, 24, 0.28);
  --fabric-text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.ghost {
  position: absolute;
  border: 2px dashed rgba(0, 0, 0, 0.5);
  background: rgba(255, 255, 255, 0.1);
  pointer-events: none;
  z-index: 15;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  width: min(520px, 92vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--modal-bg);
  color: var(--modal-text);
  border-radius: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  border: 1px solid var(--modal-border);
}


.modal header {
  padding: 16px 20px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal .modal-header {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 12px 20px;
  background: var(--modal-header-bg);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--surface-border);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.modal header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.modal .modal-header h2 {
  text-align: center;
}

.form-row input,
.form-row select,
.form-row textarea,
.modal-form .section-body-static input,
.calendar-name-input,
.settings-add-fields input {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--field-border);
  background: var(--field-bg);
  color: var(--field-text);
  font: inherit;
}

.modal-content {
  padding: 0 20px 16px;
  overflow-y: auto;
}

.modal-action-btn {
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  font: inherit;
}

.modal-action-btn.primary {
  background: #063be9;
  color: #f4f8ff;
  justify-self: end;
}

.modal-action-btn.secondary {
  background: var(--control-bg);
  color: var(--control-text);
  border: 1px solid var(--surface-border);
  justify-self: start;
}

.modal-action-btn.danger {
  background: #b00020;
  color: #fff;
}

.modal-action-btn.danger-soft {
  background: rgba(176, 0, 32, 0.14);
  color: #7f0017;
}

.modal-action-btn--block {
  width: 100%;
}

.modal-action-btn:disabled {
  opacity: 0.6;
}

.section {

  margin-bottom: 16px;
}

.section-label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 300;
}


.modal-form {
  --modal-form-label-weight: 300;
  --modal-form-label-space-before: 10px;
  --modal-form-label-space-after: 4px;
}

.modal-form .section {
  margin-bottom: 0;
}

.modal-form .section + .section {
  margin-top: 0;
}

.modal-form .section > label,
.modal-form .form-row > label {
  display: block;
  margin-top: var(--modal-form-label-space-before);
  margin-bottom: var(--modal-form-label-space-after);
  font-size: 14px;
  font-weight: var(--modal-form-label-weight);
}

.modal-form .form-row {
  gap: 0;
  margin-bottom: 0;
}

.modal-form .section-body-static {
  gap: 10px;
}
.form-row label {
  font-size: 14px;
  font-weight: 500;
}

.section-body-static {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-weight: 600;
  margin-bottom: 8px;
}

.section-body.collapsed {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
}

.section-body {
  transition: max-height 180ms ease, opacity 180ms ease;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

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

.swatch {
  min-width: 74px;
  height: 30px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid var(--fabric-border, rgba(0, 0, 0, 0.24));
  box-shadow:
    inset 0 1px 0 var(--fabric-highlight, rgba(255, 255, 255, 0.35)),
    0 2px 5px var(--fabric-shadow, rgba(0, 0, 0, 0.2));
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--fabric-gradient, #ddd);
  color: var(--fabric-text, #111);
  cursor: pointer;
  user-select: none;
}

.swatch .label {
  width: 100%;
  text-align: center;
}

.swatch.selected {
  outline: 2px solid #111;
  outline-offset: 1px;
}

.date-range-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.date-range-row .form-row {
  margin-bottom: 0;
}

.geometry-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.geometry-row button {
  border: none;
  background: var(--control-bg);
  color: var(--control-text);
  padding: 6px 10px;
  border-radius: 6px;
  min-width: 36px;
}

.readout {
  font-size: 13px;
  color: color-mix(in srgb, var(--modal-text) 84%, transparent);
  margin-left: 4px;
}

@media (max-width: 560px) {
  .date-range-row {
    gap: 8px;
  }
}

.danger-zone {
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  padding-top: 12px;
}

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  padding: 8px 12px;
  border-radius: 12px;
  z-index: 60;
  font-size: 13px;
}

.banner-error {
  background: rgba(176, 0, 32, 0.12);
  color: #b00020;
  padding: 6px 10px;
  border-radius: 6px;
  margin-bottom: 10px;
  font-size: 13px;
}

.segmented {
  display: flex;
  gap: 6px;
}

.segmented button {
  flex: 1;
  border-radius: 6px;
  border: 1px solid var(--surface-border);
  padding: 6px;
  background: var(--control-bg);
  color: var(--control-text);
}

.segmented button.active {
  background: var(--control-bg-active);
  color: var(--control-text-active);
}

.segmented--compact {
  align-items: center;
}

.segmented--compact button {
  flex: 0 0 auto;
  min-width: 42px;
}

.segmented--compact .font-size-btn {
  width: 42px;
}

.font-size-readout {
  min-width: 54px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 8px;
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  background: var(--control-bg);
  color: var(--control-text-active);
}

.font-size-glyph {
  display: inline-block;
  line-height: 1;
  font-family: serif;
}

.font-size-glyph--small {
  font-size: 12px;
}

.font-size-glyph--large {
  font-size: 18px;
}

.align-icon {
  display: block;
  width: 16px;
  height: 12px;
  margin: 0 auto;
  background-repeat: no-repeat;
  background-image:
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor);
  background-size: 100% 2px, 72% 2px, 44% 2px;
}

.align-icon--left {
  background-position: left 0 top 0, left 0 top 5px, left 0 top 10px;
}

.align-icon--center {
  background-position: center top 0, center top 5px, center top 10px;
}

.align-icon--right {
  background-position: right 0 top 0, right 0 top 5px, right 0 top 10px;
}

.settings-modal {
  width: min(620px, 94vw);
}

.settings-modal-content {
  padding-top: 12px;
}

.settings-section-title {
  font-size: 15px;
  font-weight: 600;
  cursor: default;
  margin-bottom: 12px;
}

.settings-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.settings-stepper-btn {
  min-width: 40px;
  height: 34px;
  padding: 0;
}

.settings-stepper-value {
  min-width: 34px;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
}

.calendar-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--surface-border);
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 10px;
  background: var(--surface-subtle);
}

.calendar-id {
  grid-column: 1 / -1;
  font-size: 12px;
  opacity: 0.72;
}

.calendar-name-input {
  width: 100%;
}

.calendar-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 300;
}

.settings-add-calendar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.settings-add-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  background: var(--surface-subtle);
}

.settings-add-actions {
  display: flex;
  gap: 8px;
}

.settings-add-actions .modal-action-btn {
  flex: 1;
}

.import-errors {
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid var(--surface-border);
  padding: 8px;
  border-radius: 6px;
  background: var(--surface-subtle);
}
