/* Header gift — claim-only; slides into the cup pill as a third segment */
.daily-goal-cluster:has(.ref-gift-btn) .league-trophy-btn {
  border-radius: 0;
  border-start-end-radius: 0;
  border-end-end-radius: 0;
}
.daily-goal-cluster .ref-gift-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  flex: 0 0 auto;
  padding: 0 0.42rem 0 0.18rem;
  border: 0;
  border-inline-start: 1px solid rgba(148, 163, 184, 0.22);
  border-start-end-radius: 999px;
  border-end-end-radius: 999px;
  background: transparent;
  color: #fbbf24;
  cursor: pointer;
  min-width: 0;
  opacity: 0;
  transform: translateX(8px) scale(0.92);
  transition: opacity 0.28s ease, transform 0.28s ease, background 0.15s ease, color 0.15s ease;
}
html[dir="rtl"] .daily-goal-cluster .ref-gift-btn {
  transform: translateX(-8px) scale(0.92);
}
.daily-goal-cluster .ref-gift-btn.ref-gift-btn--in {
  opacity: 1;
  transform: none;
}
.daily-goal-cluster .ref-gift-btn.ref-gift-btn--ready {
  color: #fbbf24;
}
.daily-goal-cluster .ref-gift-btn:hover,
.daily-goal-cluster .ref-gift-btn:focus-visible {
  color: #fde68a;
  background: rgba(251, 191, 36, 0.14);
  outline: none;
}
.daily-goal-cluster .ref-gift-btn svg {
  width: 15px;
  height: 15px;
  display: block;
}
.ref-gift-dot {
  position: absolute;
  inset-block-start: 4px;
  inset-inline-end: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.85);
  pointer-events: none;
}
body.theme-day .ref-gift-dot {
  box-shadow: 0 0 0 2px #f8fafc;
}
.ref-gift-btn[hidden] { display: none !important; }

.ref-gift-ready-tip {
  position: fixed;
  z-index: 9600;
  max-width: min(88vw, 16.5rem);
  padding: 0.55rem 0.7rem;
  border-radius: 0.65rem;
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid rgba(251, 191, 36, 0.45);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  font-size: 0.82rem;
  font-weight: 650;
  line-height: 1.3;
  text-align: start;
  pointer-events: auto;
  animation: ref-gift-tip-in 0.28s ease;
}
body.theme-day .ref-gift-ready-tip {
  background: #fffbeb;
  color: #78350f;
  border-color: rgba(245, 158, 11, 0.45);
  box-shadow: 0 10px 24px rgba(120, 53, 15, 0.18);
}
@keyframes ref-gift-tip-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

/* Settings row — match other Settings secondary buttons in every theme */
#ref-invite-settings-row.row-layout {
  display: block;
}
#settings-modal #ref-invite-settings-btn.ref-settings-row-btn,
.ref-settings-row-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 0.75rem;
  padding: 0.62rem 0.95rem;
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.2), rgba(96, 165, 250, 0.2));
  color: #e0f2fe;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: start;
  cursor: pointer;
  box-sizing: border-box;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}
#settings-modal #ref-invite-settings-btn.ref-settings-row-btn:hover,
.ref-settings-row-btn:hover {
  border-color: rgba(56, 189, 248, 0.8);
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.28), rgba(96, 165, 250, 0.3));
  box-shadow: 0 8px 24px rgba(14, 116, 144, 0.28);
  color: #f0f9ff;
}
body.theme-day #settings-modal #ref-invite-settings-btn.ref-settings-row-btn,
body.theme-day .ref-settings-row-btn {
  border-color: rgba(14, 165, 233, 0.45);
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.12), rgba(59, 130, 246, 0.14));
  color: #0c4a6e;
}
body.theme-day #settings-modal #ref-invite-settings-btn.ref-settings-row-btn:hover,
body.theme-day .ref-settings-row-btn:hover {
  border-color: rgba(2, 132, 199, 0.7);
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.2), rgba(59, 130, 246, 0.22));
  color: #075985;
  box-shadow: 0 6px 18px rgba(14, 116, 144, 0.18);
}
html[dir="rtl"] .ref-settings-row-btn { text-align: start; }

/* Keep gift compact beside the cup on phone header layouts */
html body:not(.fullscreen) #reader-view .top-bar .daily-goal-cluster .ref-gift-btn {
  min-width: 30px !important;
  min-height: 30px !important;
  width: auto !important;
  height: auto !important;
  flex: 0 0 auto !important;
}
html body:not(.fullscreen) #reader-view .top-bar .daily-goal-cluster .ref-gift-btn svg {
  width: 15px !important;
  height: 15px !important;
}

/* Happy-moment prompt card */
.ref-prompt {
  position: fixed;
  z-index: 9990;
  inset-inline: 0.75rem;
  inset-block-end: max(0.85rem, env(safe-area-inset-bottom, 0px));
  margin-inline: auto;
  max-inline-size: 360px;
  padding: 0.85rem 0.95rem 0.8rem;
  border-radius: 0.85rem;
  background: #ffffff;
  color: #1a1a1a;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
  text-align: start;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.ref-prompt__close {
  position: absolute;
  inset-block-start: 0.25rem;
  inset-inline-end: 0.25rem;
  inline-size: 1.75rem;
  block-size: 1.75rem;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
.ref-prompt__close:hover { background: rgba(0, 0, 0, 0.08); }
.ref-prompt__body {
  margin: 0;
  padding-inline-end: 1.4rem;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.35;
}
.ref-prompt__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.ref-prompt__actions .ref-btn {
  flex: 1 1 auto;
  min-inline-size: 6.5rem;
}

.ref-modal {
  position: fixed;
  inset: 0;
  /* Above soft update banner (~9000); align with other sheets. */
  z-index: 100100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.ref-modal__card {
  position: relative;
  inline-size: 100%;
  max-inline-size: 420px;
  max-block-size: min(100dvh - 1.5rem, 100vh - 1.5rem);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 1.1rem 1.15rem 0.95rem;
  border-radius: 1rem;
  background: #ffffff;
  color: #1a1a1a;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  text-align: start;
}

.ref-modal__card--notice {
  max-inline-size: 340px;
}

.ref-modal__close {
  position: absolute;
  inset-block-start: 0.35rem;
  inset-inline-end: 0.35rem;
  inline-size: 2rem;
  block-size: 2rem;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.ref-modal__close:hover { background: rgba(0, 0, 0, 0.08); }

.ref-modal__title {
  margin: 0;
  padding-inline-end: 1.5rem;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.25;
}

.ref-modal__headline {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.35;
  font-weight: 600;
}

.ref-modal__bonus {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.35;
  opacity: 0.75;
}

.ref-slots {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-block: 0.15rem 0.1rem;
}

.ref-slots__count {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.8;
}

.ref-slots__row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.35rem;
}

.ref-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-block-size: 3.1rem;
  padding: 0.3rem 0.15rem;
  border-radius: 0.55rem;
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: #f7f7f9;
  text-align: center;
}

.ref-slot__mark {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
}

.ref-slot__name {
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.15;
  max-inline-size: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ref-slot__label {
  font-size: 0.58rem;
  font-weight: 600;
  line-height: 1.1;
  opacity: 0.85;
}

.ref-slot--empty {
  opacity: 0.55;
  border-style: dashed;
}

.ref-slot--invited {
  border-color: rgba(37, 99, 235, 0.35);
  background: rgba(37, 99, 235, 0.08);
}

.ref-slot--joined {
  border-color: rgba(217, 119, 6, 0.4);
  background: rgba(217, 119, 6, 0.1);
}

.ref-slot--active {
  border-color: rgba(22, 163, 74, 0.4);
  background: rgba(22, 163, 74, 0.12);
}

.ref-hint {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.35;
  opacity: 0.72;
}

.ref-weeks {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.85;
}

.ref-weeks--capped {
  color: #b45309;
}

.ref-code-alt {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.35;
  text-align: center;
  opacity: 0.75;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
  user-select: all;
  word-break: break-all;
}

.ref-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.45rem;
}

.ref-btn {
  flex: 1 1 0;
  min-inline-size: 0;
  padding: 0.55em 0.85em;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 0.55em;
  background: #f5f5f7;
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.ref-btn:hover { background: #ececf0; }
.ref-btn:disabled { opacity: 0.6; cursor: default; }

.ref-btn--primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #ffffff;
}
.ref-btn--primary:hover { background: #1d4ed8; }

.ref-enter {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem;
  align-items: end;
  padding-block-start: 0.35rem;
  border-block-start: 1px solid rgba(0, 0, 0, 0.08);
}

.ref-enter__label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  grid-column: 1 / -1;
}

.ref-enter__input {
  display: block;
  inline-size: 100%;
  padding: 0.45em 0.6em;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 0.45em;
  background: #ffffff;
  color: inherit;
  font: inherit;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-sizing: border-box;
}

.ref-enter .ref-btn {
  flex: 0 0 auto;
}

.ref-enter__err {
  grid-column: 1 / -1;
  margin: 0;
  color: #dc2626;
  font-size: 0.75rem;
}

.ref-terms {
  margin: 0;
  font-size: 0.68rem;
  line-height: 1.35;
  opacity: 0.6;
}

.ref-toast {
  position: fixed;
  inset-block-end: 1.5rem;
  inset-inline-start: 50%;
  transform: translateX(-50%) translateY(1rem);
  z-index: 10001;
  padding: 0.6em 1.2em;
  border-radius: 0.6em;
  background: #1a1a1a;
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.ref-toast--show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 380px) {
  .ref-modal__card {
    padding: 0.95rem 0.85rem 0.8rem;
    gap: 0.35rem;
  }
  .ref-slot {
    min-block-size: 2.8rem;
  }
  .ref-slot__label {
    font-size: 0.55rem;
  }
  .ref-slot__name {
    font-size: 0.6rem;
  }
}

@media (prefers-color-scheme: dark) {
  .ref-settings-row-btn {
    background: #2a2a2e;
    border-color: rgba(255, 255, 255, 0.15);
    color: #f0f0f0;
  }
  .ref-settings-row-btn:hover { background: #333338; }

  .ref-prompt {
    background: #1e1e22;
    color: #f0f0f0;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  }
  .ref-prompt__close:hover { background: rgba(255, 255, 255, 0.1); }

  .ref-modal__card {
    background: #1e1e22;
    color: #f0f0f0;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  }
  .ref-modal__close:hover { background: rgba(255, 255, 255, 0.1); }

  .ref-slot {
    background: #2a2a2e;
    border-color: rgba(255, 255, 255, 0.12);
  }
  .ref-slot--invited { background: rgba(59, 130, 246, 0.16); }
  .ref-slot--joined { background: rgba(245, 158, 11, 0.16); }
  .ref-slot--active { background: rgba(34, 197, 94, 0.16); }

  .ref-btn {
    background: #2a2a2e;
    border-color: rgba(255, 255, 255, 0.15);
    color: #f0f0f0;
  }
  .ref-btn:hover { background: #333338; }
  .ref-btn--primary {
    background: #3b82f6;
    border-color: #3b82f6;
    color: #ffffff;
  }
  .ref-btn--primary:hover { background: #2563eb; }

  .ref-enter {
    border-block-start-color: rgba(255, 255, 255, 0.1);
  }
  .ref-enter__input {
    background: #2a2a2e;
    border-color: rgba(255, 255, 255, 0.2);
    color: #f0f0f0;
  }
  .ref-toast {
    background: #f0f0f0;
    color: #1a1a1a;
  }
}
