:root {
  --page-bg: #e8eef8;
  --card-bg: rgba(255, 255, 255, 0.94);
  --border: #c9d6ea;
  --primary: #245dff;
  --primary-soft: rgba(36, 93, 255, 0.14);
  --primary-strong: #153ea8;
  --text-main: #13233f;
  --text-muted: #54657e;
  --danger-bg: #fff0f3;
  --danger-text: #b83751;
  --danger-border: #f0bcc8;
  --shadow: 0 24px 60px rgba(17, 35, 69, 0.14);
  --shadow-strong: 0 26px 80px rgba(19, 35, 63, 0.18);
  --radius-xl: 28px;
  --radius-lg: 24px;
  --radius-md: 20px;
  --radius-sm: 16px;
  --max-width: 1180px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(36, 93, 255, 0.18), transparent 28%),
    radial-gradient(circle at 85% 15%, rgba(20, 93, 180, 0.12), transparent 22%),
    linear-gradient(180deg, #f7fbff 0%, var(--page-bg) 100%);
  color: var(--text-main);
  font-family: "Aptos", "Trebuchet MS", "Segoe UI", sans-serif;
  line-height: 1.5;
  position: relative;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.28) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.28) 1px, transparent 1px);
  background-size: 32px 32px;
  opacity: 0.2;
  pointer-events: none;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.88);
  color: var(--text-main);
  padding: 0.95rem 1rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    transform 0.2s ease,
    background 0.2s ease;
}

input::placeholder,
textarea::placeholder {
  color: #6c7c93;
}

textarea {
  min-height: 240px;
  resize: vertical;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

.app-shell {
  width: min(calc(100% - 1.5rem), var(--max-width));
  margin: 0 auto;
  padding: 1rem 0 2.5rem;
  display: grid;
  gap: 1rem;
}

.app-shell > * {
  min-width: 0;
}

.card,
.hero-card,
.ad-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  position: relative;
  overflow: visible;
}

.card::before,
.hero-card::before,
.ad-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 5px;
  background: linear-gradient(90deg, var(--primary), #73a1ff 55%, #b8d0ff 100%);
}

.hero-card,
.card,
.ad-card {
  padding: 1.2rem;
}

.hero-card,
.content-row,
.editor-layout,
.insights-layout,
.editor-fields,
.toolbar-actions,
.guided-action,
.mood-grid,
.stats-grid,
.editor-actions,
.insights-notes,
.utility-actions {
  display: grid;
  gap: 1rem;
}

.hero-copy,
.hero-tools,
.calendar-card,
.sidebar-card,
.editor-card,
.entries-card,
.card-header > div,
.selected-summary,
.stat-card {
  min-width: 0;
}

.calendar-card,
.editor-card {
  z-index: 20;
}

.sidebar-card,
.entries-card,
.ad-card {
  z-index: 1;
}

.section-kicker,
.ad-title {
  margin: 0 0 0.45rem;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.hero-copy h1,
.card-header h2 {
  margin: 0;
  letter-spacing: -0.04em;
}

.hero-copy h1 {
  font-size: clamp(2.2rem, 7vw, 3.9rem);
  line-height: 0.96;
}

.hero-text,
.entries-meta,
.site-footer p,
.ad-text {
  color: var(--text-muted);
}

.hero-text {
  margin: 0.7rem 0 1rem;
  max-width: 34rem;
  font-size: 1.05rem;
}

.hero-tools {
  align-content: start;
}

.hero-entries-card {
  padding: 1rem;
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 34px rgba(19, 35, 63, 0.08);
}

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.pill {
  padding: 0.5rem 0.95rem;
  border: 1px solid #d4e0f1;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff, #eef4ff);
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 700;
}

.field-group {
  display: grid;
  gap: 0.45rem;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.95rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #ffffff 0%, #eef4ff 100%);
  font-weight: 700;
}

.toggle-row input {
  width: 20px;
  height: 20px;
  margin: 0;
  box-shadow: none;
}

.editor-fields > .field-group > .field-label {
  text-align: left;
  padding-left: 0.35rem;
  margin-bottom: 0.2rem;
}
#generatedTitleText {
  margin-top: 11px;
  margin-bottom: 5px;
}
.field-label,
.summary-label {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-main);
}

.button {
  width: 100%;
  min-height: 50px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 0.9rem 1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    border-color 0.18s ease,
    background 0.18s ease;
}

.button:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 30px rgba(19, 35, 63, 0.1);
}
.button-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  color: #fff;
  box-shadow: 0 18px 36px rgba(36, 93, 255, 0.24);
}

.button-ghost {
  background: linear-gradient(180deg, #ffffff 0%, #cfe4fc 100%);
  color: var(--text-main);
  border-color: var(--border);
}

#allEntriesButton {
  margin-top: 0.5rem;
}

.button-danger {
  background: linear-gradient(180deg, #fff8fa 0%, var(--danger-bg) 100%);
  color: var(--danger-text);
  border-color: var(--danger-border);
}

.button-small {
  width: auto;
  min-height: 42px;
  padding-inline: 0.95rem;
}

.guided-action {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.45rem;
  align-items: start;
  align-content: start;
  position: relative;
  z-index: 200;
}

.guided-action.is-guide-open {
  z-index: 10000;
}

.toolbar-actions,
.editor-actions {
  grid-auto-rows: 1fr;
  align-items: start;
}

.guided-action-compact {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
}

.guide-tab {
  justify-self: start;
  align-self: center;
  min-width: 68px;
  min-height: 44px;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #f2f6ff 0%, #e3edff 100%);
  color: var(--primary);
  font-size: 0.84rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.guide-tab:hover {
  transform: translateY(-1px);
}

.guide-tab[aria-expanded="true"] {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.guide-tab-compact {
  min-width: 60px;
  min-height: 40px;
  padding: 0.3rem 0.75rem;
  align-self: center;
  justify-self: auto;
}

.guided-action-compact .guide-panel {
  width: min(320px, calc(100vw - 2rem));
}

.guided-action-compact .guide-panel::before {
  left: 1.1rem;
  right: auto;
  bottom: calc(100% - 1px);
  top: auto;
  transform: rotate(135deg);
}

.guided-action-compact .guide-panel.is-visible {
  transform: translateY(0) scale(1);
}

.guided-action-compact .guide-panel.is-hiding {
  transform: translateY(-6px) scale(0.92);
}

.guide-panel {
  position: absolute;
  top: calc(100% + 0.55rem);
  left: 0;
  z-index: 9999;
  grid-column: 1 / -1;
  width: min(320px, calc(100vw - 2rem));
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(180deg, #ffffff 0%, #eef4ff 100%);
  color: var(--text-main);
  font-size: 0.88rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
  box-shadow: 0 22px 44px rgba(19, 35, 63, 0.16);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-6px) scale(0.92);
  transform-origin: top left;
  transition:
    opacity 0.22s ease,
    transform 0.22s ease,
    visibility 0.22s ease;
}

.guide-panel::before {
  content: "";
  position: absolute;
  left: 1.1rem;
  bottom: calc(100% - 1px);
  width: 14px;
  height: 14px;
  background: #f7fbff;
  border-left: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  transform: rotate(135deg);
}

.guide-panel.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.guide-panel.is-hiding {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-6px) scale(0.92);
}

.guide-panel[hidden] {
  display: none !important;
}

.ad-placeholder {
  min-height: 110px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #f8fbff 0%, #eef4fb 100%);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1rem;
}

.ad-placeholder-sidebar {
  min-height: 100%;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.calendar-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  margin-top: 0.5rem;
}

.selected-summary {
  display: grid;
  gap: 0.25rem;
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #ffffff 0%, #eef4ff 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.summary-card,
.utility-section {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #ffffff 0%, #eef4ff 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92);
}

.summary-title,
.helper-text {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.summary-card strong {
  display: block;
  margin-top: 0.3rem;
  font-size: 1rem;
}

.weekday-row,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.45rem;
}

.weekday-row {
  margin-bottom: 0.55rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: center;
}

.day-cell {
  width: 100%;
  min-height: 84px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(180deg, #ffffff 0%, #f6f9ff 100%);
  padding: 0.65rem;
  text-align: left;
  position: relative;
  display: flex;
  align-items: flex-start;
  box-shadow: 0 10px 18px rgba(19, 35, 63, 0.05);
}

.day-cell.is-outside {
  background: #f8fbff;
  color: #99acbf;
}

.day-cell.is-selected {
  background: linear-gradient(180deg, rgba(36, 93, 255, 0.16) 0%, rgba(36, 93, 255, 0.07) 100%);
  border-color: var(--primary);
  box-shadow: 0 14px 28px rgba(36, 93, 255, 0.18);
}

.day-cell.is-today {
  box-shadow: inset 0 0 0 1px rgba(59, 110, 234, 0.35);
}

.day-cell.has-entry::after {
  content: "";
  position: absolute;
  right: 0.7rem;
  bottom: 0.7rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
}

.day-inner {
  display: grid;
  gap: 0.35rem;
}

.day-number {
  font-weight: 800;
}

.entry-preview {
  color: var(--text-muted);
  font-size: 0.78rem;
}

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

.mood-chip {
  min-height: 46px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #ffffff 0%, #f2f6fd 100%);
  color: var(--text-main);
  font-weight: 800;
  padding: 0.75rem 0.9rem;
  box-shadow: 0 10px 18px rgba(19, 35, 63, 0.05);
}

.mood-chip.is-active {
  border-color: var(--primary);
  background: linear-gradient(180deg, rgba(36, 93, 255, 0.2) 0%, rgba(36, 93, 255, 0.1) 100%);
  color: var(--primary);
  box-shadow: 0 14px 28px rgba(36, 93, 255, 0.16);
}

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

.stats-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 1rem 0;
}

.stat-card {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #ffffff 0%, #eef4ff 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.92);
}

.stat-card span {
  display: block;
  color: var(--text-muted);
  font-size: 0.86rem;
  margin-bottom: 0.3rem;
}

.stat-card strong {
  display: block;
  font-size: 1rem;
  color: var(--text-main);
}

.entries-card {
  display: flex;
  flex-direction: column;
}

.insights-card,
.utility-card {
  display: grid;
  gap: 1rem;
}

.utility-section h2 {
  margin: 0 0 0.8rem;
}

.utility-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

#backupPreview {
  min-height: 220px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.86rem;
  line-height: 1.5;
}

.helper-text {
  margin: 0;
}

.status-message {
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #ffffff 0%, #eef4ff 100%);
  color: var(--text-main);
  font-weight: 700;
}

.status-message.is-success {
  border-color: #b9d8c6;
  background: linear-gradient(180deg, #ffffff 0%, #eaf8ef 100%);
  color: #16663a;
}

.status-message.is-warning {
  border-color: #e9d2a4;
  background: linear-gradient(180deg, #fffef8 0%, #fff3d9 100%);
  color: #835200;
}

.status-message.is-danger {
  border-color: var(--danger-border);
  background: linear-gradient(180deg, #fffafc 0%, #ffe8ee 100%);
  color: var(--danger-text);
}

.entries-list {
  display: grid;
  gap: 0.8rem;
  align-content: start;
}

.entry-item,
.empty-state {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #ffffff 0%, #f3f7ff 100%);
  box-shadow: 0 14px 26px rgba(19, 35, 63, 0.05);
}

.entry-item {
  width: 100%;
  min-height: 88px;
  text-align: left;
}

.entry-item strong,
.entry-item span {
  display: block;
}

.entry-item strong {
  margin-bottom: 0.3rem;
}

.entry-item span {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.empty-state strong,
.empty-state span {
  display: block;
}

.empty-state strong {
  margin-bottom: 0.3rem;
}

.empty-state span {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.entry-item.is-selected {
  border-color: var(--primary);
  background: linear-gradient(180deg, rgba(36, 93, 255, 0.18) 0%, rgba(36, 93, 255, 0.08) 100%);
}

.editor-card {
  box-shadow: var(--shadow-strong);
}

.site-footer {
  text-align: center;
  padding: 0.2rem 0 0.8rem;
}

.site-footer p {
  margin: 0;
  font-size: 0.92rem;
}

@media (min-width: 720px) {
  .app-shell {
    width: min(calc(100% - 2.5rem), var(--max-width));
    padding-top: 1.5rem;
    gap: 1.25rem;
  }

  .hero-card {
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
    align-items: start;
    padding: 1.6rem;
  }

  .toolbar-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .guided-action > .guide-panel {
    width: min(320px, 34vw);
  }

  .guided-action-compact > .guide-panel {
    width: min(320px, 30vw);
  }

  .editor-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .editor-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .insights-layout {
    grid-template-columns: minmax(0, 1.1fr) minmax(300px, 0.9fr);
    align-items: start;
  }

  .insights-notes {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 980px) {
  .content-row {
    grid-template-columns: minmax(0, 1fr) 280px;
    align-items: start;
  }

  .editor-layout {
    grid-template-columns: minmax(0, 1fr) 320px;
    align-items: start;
  }

  .sidebar-card,
  .entries-card,
  .utility-card {
    position: sticky;
    top: 1.25rem;
  }

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

  .insights-stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(calc(100% - 1rem), var(--max-width));
  }

  .hero-card,
  .card,
  .ad-card {
    padding: 1rem;
    border-radius: 22px;
  }

  .hero-copy h1 {
    font-size: clamp(2rem, 11vw, 3rem);
  }

  .hero-text {
    font-size: 0.98rem;
  }

  .card-header {
    flex-direction: column;
    align-items: stretch;
  }

  .calendar-nav {
    width: 100%;
  }

  .weekday-row {
    font-size: 0.74rem;
    gap: 0.25rem;
  }

  .calendar-grid {
    gap: 0.3rem;
  }

  .day-cell {
    min-height: 64px;
    padding: 0.45rem;
    border-radius: 15px;
  }

  .entry-preview {
    display: none;
  }

  .stats-grid,
  .mood-grid,
  .editor-actions,
  .utility-actions,
  .insights-notes {
    grid-template-columns: 1fr;
  }

  .guided-action {
    gap: 0.55rem;
  }

  .guided-action-compact {
    display: grid;
    justify-items: stretch;
  }

  .guide-panel {
    width: min(100%, calc(100vw - 2rem));
  }

  .guide-panel::before {
    left: 1rem;
  }

  .guided-action-compact .guide-panel {
    width: min(100%, calc(100vw - 2rem));
  }

  .guided-action-compact .guide-panel::before {
    left: 1rem;
  }

  .button-small,
  .guide-tab-compact {
    width: 100%;
  }

  .button,
  .guide-tab {
    min-height: 52px;
  }

  textarea {
    min-height: 220px;
  }

  #backupPreview {
    min-height: 180px;
  }
}
