.tray-controls {
  display: flex;
  align-items: center;
  gap: clamp(6px, 1.3vw, 16px);
}

.button.tray-add, .range-dialog .range-primary {
  border-color: var(--season-dark, #324b3f);
  background: var(--season-dark, #324b3f);
  color: #fffaf1;
}

.button.tray-add {
  min-height: 38px;
  padding-inline: 12px;
  gap: 4px;
  white-space: nowrap;
}

.button.tray-add:hover, .range-dialog .range-primary:hover { filter: brightness(1.13); }
.button.range-queue-status { min-height: 32px; margin: 0 0 8px 2px; padding: 3px 9px; color: var(--muted); font-size: .81rem; }
.range-summary { display: none; }

.tile-slot { container: calendar-day / inline-size; }
.tile-date-line { display: flex; align-items: center; min-width: 0; }
.tile-slot.has-range { --range-extra: 0px; min-height: max(var(--size), calc(108px + var(--range-extra))); }
.tile-slot.has-two-ranges { --range-extra: 29px; }
.tile-slot.has-range:has(.tile-editing, .tile-caption, .tile-tasks) { min-height: max(var(--size), calc(123px + var(--range-extra))); }
.tile-slot.has-range:has(.tile-caption ~ .tile-tasks, .tile-more) { min-height: max(var(--size), calc(139px + var(--range-extra))); }
.has-range .tile-face { padding-top: 8px; gap: 5px; }
.has-range .tile-date-line { position: relative; z-index: 1; }
.has-range .tile-date { font-size: clamp(1.33rem, 2.2vw, 1.85rem); }
.has-range .tile .tile-art.sticker-art { inset-block: auto 1px; width: 54%; height: min(67px, 55%); }
.has-range .tile.has-tasks .tile-art.sticker-art { width: 43%; }
.has-two-ranges .tile .tile-art.sticker-art { width: 42%; height: min(48px, 38%); }
.has-range .tile-editing { top: calc(38px + var(--range-extra)); }

:is(.tile-range-label, .range-card)[data-kind="vacation"] {
  --event-ink: #304c3a;
  --event-fill: #e1ebdd;
  --event-line: #96ad92;
  --event-flag: #648567;
}

:is(.tile-range-label, .range-card)[data-kind="work"] {
  --event-ink: #693e34;
  --event-fill: #f4e1d8;
  --event-line: #ce9d90;
  --event-flag: #ab6957;
}

:is(.tile-range-label, .range-card)[data-kind="other"] {
  --event-ink: #59475b;
  --event-fill: #eee5f0;
  --event-line: #c3abc7;
  --event-flag: #94749d;
}

.tile-range-label:not([data-owner]) {
  --event-ink: #51435e;
  --event-fill: #eee8f4;
  --event-flag: #9b86ac;
}

:is(.tile-range-label, .range-card)[data-owner="boy"] {
  --event-ink: #2d4839;
  --event-fill: #e2ece2;
  --event-line: #a2b4a6;
  --event-flag: #789682;
}

:is(.tile-range-label, .range-card)[data-owner="girl"] {
  --event-ink: #643d42;
  --event-fill: #f4e4e3;
  --event-line: #cda9b0;
  --event-flag: #bf8b8e;
}

.tile-range-stack { display: grid; width: 100%; min-width: 0; gap: 4px; }

.tile-range-label {
  position: relative;
  z-index: 2;
  display: flex;
  min-width: 0;
  width: 100%;
  min-height: 25px;
  flex: none;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  border-inline-start: 2px solid var(--event-flag);
  border-radius: 4px 9px 9px 4px;
  background: var(--event-fill);
  color: var(--event-ink);
  font-size: .82rem;
  font-weight: 670;
  line-height: 1.25;
}

.tile-range-title, .range-card-content strong {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.range-kind-icon { display: inline-flex; flex: none; align-items: center; }
.range-kind-icon svg { width: .95rem; height: .95rem; }
.range-avatars { display: inline-flex; flex: none; align-items: center; gap: 1px; }
.range-avatars .author-badge { padding: 0; width: 20px; min-width: 20px; height: 20px; border-radius: 50%; }
.range-avatars .author-badge svg { width: 15px; height: 15px; }
.tile-range-label .author-badge { width: 16px; min-width: 16px; height: 16px; }
.tile-range-label .author-badge svg { width: 11px; height: 11px; }

@container calendar-day (max-width: 100px) {
  .tile-range-label { gap: 3px; padding-inline: 3px; }
  .tile-range-label .author-badge { width: 13px; min-width: 13px; height: 13px; }
  .tile-range-label .author-badge svg { width: 9px; height: 9px; }
  .tile-range-label .range-avatars:has(.author-badge + .author-badge) { gap: 0; }
  .tile-range-label .author-badge + .author-badge { margin-inline-start: -3px; }
  .has-range .tile-editing { top: calc(34px + var(--range-extra)); right: 4px; width: 6px; height: 6px; padding: 0; border-radius: 50%; background: #785a88; font-size: 0; }
  .has-range .tile-editing .author-badge { display: none; }
}

.range-card {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  width: 100%;
  min-height: 52px;
  padding: 7px 9px;
  border: 1px solid color-mix(in srgb, var(--event-line) 55%, transparent);
  border-radius: 11px;
  color: var(--event-ink);
  background: var(--event-fill);
  text-align: left;
}

.range-card:hover { border-color: var(--event-flag); }
.range-card-icon { display: grid; flex: none; place-items: center; }
.range-card-icon svg { width: 1.18rem; height: 1.18rem; }
.range-card-content { display: grid; flex: 1; min-width: 0; gap: 1px; line-height: 1.3; }
.range-card-content strong { font-size: .91rem; font-weight: 690; }
.range-card-date { font-size: .74rem; font-variant-numeric: tabular-nums; }
.range-summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr)); gap: 7px; }
.range-summary-more { margin-block: 6px 0; }
.range-summary-more summary { width: max-content; padding: 5px 3px; color: var(--muted); font-size: .82rem; cursor: pointer; }
.range-summary-more[open] > .range-summary-grid { margin-top: 4px; }

.day-ranges { display: grid; gap: 7px; margin: 0 0 15px; }
.day-ranges > h3 { color: #604a3e; font-size: .92rem; font-weight: 690; }
.day-range-list { display: grid; gap: 6px; }
.day-ranges .range-card { min-height: 44px; }
.day-quick { display: flex; flex-wrap: wrap; gap: 6px; }
.day-quick > .add-form { flex-basis: 100%; }

.range-dialog[open] {
  width: min(calc(100% - 30px), 470px);
  max-height: 90dvh;
  padding: 0;
  border: 1px solid #dfd0bd;
  border-radius: 21px;
  color: #403c31;
  background: #fffaf0;
  box-shadow: 0 22px 80px #493b2f35;
  overscroll-behavior: contain;
}

.range-dialog::backdrop { background: #362c2b65; backdrop-filter: blur(3px); }
body:has(.range-dialog[open]) { overflow: hidden; }
.range-dialog-header {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 12px clamp(14px, 4.5vw, 23px);
  border-bottom: 1px solid #e7dac8;
  background: linear-gradient(105deg, #f7eddb, #fffaf0);
}

.range-dialog-header h2 { font: 700 1.28rem/1.25 var(--display); letter-spacing: .025em; }
.range-dialog-header .button.icon-button { width: 40px; min-height: 40px; background: #fffaf1; }
.range-dialog-body { padding: 14px clamp(14px, 4.5vw, 23px) 18px; }

.range-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  margin-bottom: 14px;
  padding: 3px;
  border: 1px solid #eee4d4;
  border-radius: 11px;
  background: #f5eee2;
}

.range-modes .button { min-height: 36px; padding-block: 4px; border-color: transparent; background: transparent; }
.range-modes .button[aria-pressed="true"] { border-color: #dfd1c1; background: #fffcf6; }
.range-form { display: grid; align-items: start; gap: 6px; }
.range-form > :is(input, .range-date-pair, .range-kind) { margin-bottom: 4px; }
.range-form label, .range-fieldset legend { font-size: .87rem; font-weight: 650; }

.range-form :is(input:not([type="radio"], [type="checkbox"]), select) {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid #d9cbb7;
  border-radius: 9px;
  background: #fffcf6;
  padding: 5px 8px;
  color: inherit;
  font: inherit;
}

.range-form :is(input, select):disabled { opacity: .72; }
.range-date-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.range-field { display: grid; gap: 6px; min-width: 0; }
.range-form .range-count { min-height: 1.2rem; margin: 0 0 4px; color: #587050; font-size: .82rem; font-weight: 640; }
.range-count:empty { display: none; }
.range-count.is-invalid { color: #8b463b; }
.range-fieldset { min-width: 0; margin: 0 0 3px; padding: 0; border: 0; }
.range-fieldset legend { margin-bottom: 5px; }
.range-segmented { display: flex; gap: 7px; }
.range-segmented label { display: flex; position: relative; }
.range-segmented input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.range-segmented label span { padding: 6px 13px; border: 1px solid #ddd0be; border-radius: 9px; background: #fffaf2; }
.range-segmented input:checked + span { border-color: #8eaa8e; color: #3d5941; background: #e8f0e4; }
.range-segmented input:focus-visible + span { outline: 2px solid #75538b; outline-offset: 2px; }
.range-segmented input:disabled + span { opacity: .67; }
.range-kind { display: grid; grid-template-columns: max-content minmax(0, 150px); gap: 9px; align-items: center; }
.range-form .range-kind select { min-height: 36px; font-size: .88rem; }
.range-checkbox { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; }
.range-checkbox input { width: 17px; height: 17px; accent-color: #516d55; }
.range-form-footer { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 46px; }
.range-form-footer button { flex: none; margin-inline-start: auto; min-height: 42px; }
.range-storage, .range-feedback { color: #625649; font-size: .81rem; }
.range-feedback { padding-top: 6px; }
.range-delete { margin-top: 5px; color: #81463b; background: transparent; }
.range-danger { color: white; border-color: #864f45; background: #864f45; }
.range-danger:hover { background: #76463e; }
.range-delete-confirm, .range-conflict { margin-top: 10px; padding: 10px; border: 1px solid #e1c6b2; border-radius: 9px; background: #fff2e9; font-size: .84rem; }
.range-conflict h3 { margin-bottom: 6px; font-size: .93rem; }
.range-conflict-versions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-bottom: 8px; }
.range-conflict-versions > div { padding: 7px; border-radius: 6px; background: #fffaf3; overflow-wrap: anywhere; white-space: pre-line; }
.range-inline-actions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.range-inline-actions .button { min-height: 36px; padding: 4px 8px; }

@media (max-width: 830px) {
  .range-summary { display: block; margin-bottom: 9px; }
  .range-summary:empty { display: none; }
  .tile-slot.has-two-ranges { --range-extra: 25px; }
  .tile-slot.has-range { min-height: calc(clamp(84px, 17vw, 108px) + var(--range-extra)); }
  .tile-slot.has-range:has(.tile-editing, .tile-caption, .tile-tasks) { min-height: calc(106px + var(--range-extra)); }
  .tile-slot.has-range:has(.tile-caption ~ .tile-tasks, .tile-more) { min-height: calc(123px + var(--range-extra)); }
  .has-range .tile-face { padding-top: 5px; gap: 4px; }
  .has-range .tile-date { font-size: clamp(1.24rem, 4.2vw, 1.55rem); }
  .has-range .tile .tile-art.sticker-art { height: min(48px, 49%); }
  .has-two-ranges .tile .tile-art.sticker-art { height: min(36px, 34%); }
  .tile-range-label { min-height: 21px; gap: 4px; font-size: .74rem; }
  .range-dialog[open] { position: fixed; inset: auto 0 0; width: min(100%, 490px); margin: 0 auto; border-radius: 17px 17px 0 0; }
  .range-dialog-body { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
}

@media (max-width: 420px) {
  .tray-toolbar { gap: 4px; }
  .tray-heading-row { min-width: 0; flex-direction: column; align-items: start; gap: 3px; }
  .tray-heading-row .view-mode { max-width: 100%; padding-inline: 4px; font-size: .65rem; white-space: nowrap; }
  .tray-controls { gap: 5px; }
  .month-navigation { gap: 3px; }
  .month-navigation .button.icon-button { width: 30px; min-height: 34px; }
  .navigation-month { min-width: 0; font-size: .81rem; white-space: nowrap; }
  .button.tray-add { min-height: 36px; padding-inline: 6px; font-size: .81rem; }
  .range-card { gap: 5px; padding-inline: 7px; }
  .range-card-date { font-size: .7rem; }
  .range-card .author-badge { width: 17px; min-width: 17px; height: 17px; }
  .range-card .author-badge svg { width: 13px; height: 13px; }
}
