:root {
  color-scheme: light;
}

html.dark {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  font-family: "Manrope", ui-sans-serif, system-ui, sans-serif;
  letter-spacing: -0.01em;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

.grain {
  background:
    radial-gradient(
      circle at 12% 16%,
      rgba(196, 181, 253, 0.14),
      transparent 22%
    ),
    radial-gradient(
      circle at 84% 18%,
      rgba(251, 191, 36, 0.1),
      transparent 18%
    ),
    radial-gradient(
      circle at bottom right,
      rgba(214, 211, 209, 0.3),
      transparent 24%
    ),
    linear-gradient(180deg, #f7f2ea 0%, #f2ece4 52%, #ebe5de 100%);
}

html.dark .grain {
  background:
    radial-gradient(
      circle at 10% 14%,
      rgba(245, 158, 11, 0.08),
      transparent 20%
    ),
    radial-gradient(
      circle at 88% 14%,
      rgba(96, 165, 250, 0.08),
      transparent 18%
    ),
    radial-gradient(
      circle at bottom right,
      rgba(68, 64, 60, 0.2),
      transparent 20%
    ),
    linear-gradient(180deg, #0d0d0d 0%, #151515 44%, #1a1a1a 100%);
}

.grain::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.18;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 26px 26px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.7), transparent 90%);
  pointer-events: none;
}

.panel {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.8),
    rgba(250, 250, 249, 0.68)
  );
  border: 1px solid rgba(231, 229, 228, 0.95);
  box-shadow:
    0 32px 90px rgba(28, 25, 23, 0.08),
    0 8px 24px rgba(28, 25, 23, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(22px);
}

html.dark .panel {
  background: linear-gradient(
    180deg,
    rgba(26, 26, 28, 0.88),
    rgba(19, 19, 20, 0.78)
  );
  border-color: rgba(63, 63, 70, 0.75);
  box-shadow:
    0 34px 96px rgba(0, 0, 0, 0.32),
    0 10px 24px rgba(0, 0, 0, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.topbar-compact {
  transition:
    opacity 260ms ease,
    transform 260ms ease,
    max-height 260ms ease,
    margin 260ms ease,
    padding 260ms ease;
}

.topbar-controls {
  min-width: 0;
}

.mobile-menu {
  max-height: 0;
  margin-top: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  border-width: 0;
  overflow: hidden;
  transform: translateY(-0.4rem) scale(0.985);
}

.mobile-menu.open {
  max-height: 18rem;
  margin-top: 0.75rem !important;
  padding-top: 0.75rem !important;
  padding-bottom: 0.75rem !important;
  border-width: 1px;
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.entry-card {
  position: relative;
  border: 1px solid rgba(231, 229, 228, 0.95);
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.82),
    rgba(250, 250, 249, 0.7)
  );
  transition:
    transform 220ms ease,
    border-color 220ms ease,
    background-color 220ms ease,
    box-shadow 220ms ease;
}

html.dark .entry-card {
  border-color: rgba(63, 63, 70, 0.8);
  background: linear-gradient(
    180deg,
    rgba(33, 33, 36, 0.84),
    rgba(27, 27, 29, 0.74)
  );
}

.entry-card:hover {
  transform: translateY(-3px);
  border-color: rgba(168, 162, 158, 1);
  box-shadow:
    0 24px 32px rgba(28, 25, 23, 0.09),
    0 8px 14px rgba(28, 25, 23, 0.05);
}

html.dark .entry-card:hover {
  border-color: rgba(113, 113, 122, 0.95);
  box-shadow:
    0 24px 32px rgba(0, 0, 0, 0.26),
    0 8px 14px rgba(0, 0, 0, 0.12);
}

.entry-card.active {
  border-color: rgba(41, 37, 36, 0.9);
  background: linear-gradient(
    180deg,
    rgba(250, 250, 249, 0.98),
    rgba(245, 245, 244, 0.92)
  );
  box-shadow:
    0 26px 40px rgba(28, 25, 23, 0.09),
    0 10px 18px rgba(28, 25, 23, 0.06);
}

html.dark .entry-card.active {
  border-color: rgba(214, 211, 209, 0.35);
  background: linear-gradient(
    180deg,
    rgba(43, 43, 46, 0.96),
    rgba(33, 33, 35, 0.92)
  );
}

.entry-preview {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

#titleInput {
  font-family: "Cormorant Garamond", Georgia, serif;
  line-height: 0.95;
}

#titleInput::placeholder {
  transition: color 180ms ease;
}

#titleInput:focus::placeholder {
  color: transparent;
}

.editor-shell {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.42),
    rgba(255, 255, 255, 0.14)
  );
  transition:
    max-width 360ms ease,
    padding 360ms ease,
    background 280ms ease,
    transform 360ms ease,
    box-shadow 280ms ease;
  padding-right: 1rem;
  padding-bottom: 6.5rem;
}

html.dark .editor-shell {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.02),
    rgba(255, 255, 255, 0.01)
  );
}

.editor-toolbar {
  position: relative;
  transition:
    opacity 280ms ease,
    transform 280ms ease,
    max-height 280ms ease,
    margin 280ms ease;
}

.journal-area {
  position: relative;
  min-height: 420px;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 19px;
  line-height: 1.95;
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-y: auto;
}

.journal-area:empty::before {
  content: attr(data-placeholder);
  color: #a8a29e;
  pointer-events: none;
}

html.dark .journal-area:empty::before {
  color: #57534e;
}

.journal-area:focus {
  outline: none;
}

.journal-area [data-font-family="serif"] {
  font-family: "Cormorant Garamond", Georgia, serif;
}

.journal-area [data-font-family="sans"] {
  font-family: "Manrope", ui-sans-serif, system-ui, sans-serif;
  letter-spacing: -0.01em;
}

.journal-area [data-font-family="mono"] {
  font-family: "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
  letter-spacing: -0.015em;
}

.journal-area [data-font-weight="bold"] {
  font-weight: 700;
}

.journal-area [data-font-weight="regular"] {
  font-weight: 500;
}

.journal-area [data-font-style="italic"] {
  font-style: italic;
}

.journal-area [data-font-style="roman"] {
  font-style: normal;
}

#editToolbar {
  position: fixed !important;
  left: 50% !important;
  right: auto !important;
  top: auto !important;
  bottom: max(1rem, env(safe-area-inset-bottom)) !important;
  z-index: 9999 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  overflow: hidden;
  max-width: calc(100vw - 1.5rem);
  flex-shrink: 0;
  border-radius: 1.5rem;
  transform: translateX(-50%) !important;
  backdrop-filter: blur(18px);
  pointer-events: auto !important;
  visibility: visible !important;
  opacity: 1 !important;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.52),
    0 10px 24px rgba(28, 25, 23, 0.06);
  transition:
    opacity 220ms ease,
    transform 220ms ease,
    box-shadow 220ms ease;
}

.toolbar-mobile-field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.35rem;
  color: rgb(87 83 78);
}

html.dark .toolbar-mobile-field {
  color: rgb(168 162 158);
}

.toolbar-mobile-field span:first-child {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.toolbar-mobile-select,
.toolbar-mobile-stepper {
  border: 1px solid rgba(231, 229, 228, 0.9);
  background: rgba(245, 245, 244, 0.82);
  color: rgb(41 37 36);
}

html.dark .toolbar-mobile-select,
html.dark .toolbar-mobile-stepper {
  border-color: rgba(63, 63, 70, 0.85);
  background: rgba(17, 17, 17, 0.72);
  color: rgb(231 229 228);
}

.toolbar-mobile-select {
  min-width: 5.25rem;
  appearance: none;
  border-radius: 1rem;
  padding: 0.7rem 2rem 0.7rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  outline: none;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    calc(100% - 1rem) calc(50% - 1px),
    calc(100% - 0.7rem) calc(50% - 1px);
  background-size:
    0.38rem 0.38rem,
    0.38rem 0.38rem;
  background-repeat: no-repeat;
}

.toolbar-mobile-size {
  min-width: 7rem;
}

.toolbar-mobile-stepper {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
  border-radius: 1rem;
  padding: 0.25rem;
}

.toolbar-mobile-stepper-btn {
  display: inline-flex;
  height: 2rem;
  width: 2rem;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 0.8rem;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.toolbar-mobile-size-value {
  min-width: 2.9rem;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
}

html.dark #editToolbar {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 10px 24px rgba(0, 0, 0, 0.14);
}

.toolbar-value {
  display: inline-block;
  min-width: 3.6rem;
  text-align: right;
  white-space: nowrap;
}

.wheel-control {
  cursor: ns-resize;
  user-select: none;
  min-height: 2.75rem;
  flex: 0 0 auto;
  border: 1px solid rgba(231, 229, 228, 0.8);
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    background-color 180ms ease,
    color 180ms ease,
    border-color 180ms ease;
}

html.dark .wheel-control {
  border-color: rgba(63, 63, 70, 0.8);
}

.wheel-control:hover {
  transform: translateY(-1px);
  border-color: rgba(168, 162, 158, 0.95);
  box-shadow: 0 12px 24px rgba(28, 25, 23, 0.08);
}

html.dark .wheel-control:hover {
  border-color: rgba(113, 113, 122, 0.95);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.16);
}

.journal-area::-webkit-scrollbar,
#entriesList::-webkit-scrollbar {
  width: 10px;
}

.journal-area::-webkit-scrollbar-thumb,
#entriesList::-webkit-scrollbar-thumb {
  background: rgba(168, 162, 158, 0.8);
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
}

html.dark .journal-area::-webkit-scrollbar-thumb,
html.dark #entriesList::-webkit-scrollbar-thumb {
  background: rgba(113, 113, 122, 0.8);
  background-clip: content-box;
}

.journal-area::-webkit-scrollbar-track,
#entriesList::-webkit-scrollbar-track {
  background: transparent;
}

#sidebar {
  transition:
    transform 320ms ease,
    opacity 320ms ease,
    width 320ms ease,
    padding 320ms ease,
    margin 320ms ease,
    border-width 320ms ease;
}

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

#sidebarBackdrop.open {
  display: block;
}

.modal-open {
  overflow: hidden;
}

#deleteModal.open {
  opacity: 1;
  pointer-events: auto;
}

body.focus-mode #topBar {
  opacity: 0;
  transform: translateY(-24px) scale(0.98);
  pointer-events: none;
  max-height: 0;
  margin: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
}

body.focus-mode #sidebar {
  opacity: 0;
  transform: translateX(-40px) scale(0.98);
  pointer-events: none;
  width: 0;
  min-width: 0;
  padding: 0;
  margin: 0;
  border-width: 0;
  overflow: hidden;
}

body.focus-mode #workspace {
  margin-top: 0;
}

body.focus-mode #workspace > main {
  min-height: calc(100vh - 2rem);
}

body.focus-mode .editor-toolbar {
  opacity: 1;
  transform: none;
  max-height: none;
  overflow: visible;
  pointer-events: auto;
  margin: 0;
}

body.focus-mode #editToolbar {
  position: fixed !important;
  left: 50% !important;
  right: auto !important;
  top: auto !important;
  bottom: max(1rem, env(safe-area-inset-bottom)) !important;
  z-index: 9999 !important;
  transform: translateX(-50%) !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  visibility: visible !important;
  max-width: calc(100vw - 1.5rem);
  width: max-content;
}

body.focus-mode .editor-toolbar > div:first-child {
  display: none;
}

body.focus-mode .editor-shell {
  max-width: 860px;
  padding-top: 4rem;
  padding-bottom: 4rem;
  transform: translateY(0);
}

body.focus-mode #focusExitBtn {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

body.focus-mode #emptyState {
  min-height: calc(100vh - 6rem);
}

body.focus-mode #editorSection:not(.hidden) {
  display: flex;
  align-items: center;
  justify-content: center;
}

button,
input,
[contenteditable="true"] {
  transition:
    background-color 180ms ease,
    border-color 180ms ease,
    color 180ms ease,
    box-shadow 180ms ease,
    transform 180ms ease;
}

#searchInput,
#themeToggle,
#exportBtn,
#importBtn,
#sidebarToggle,
#newEntryBtn,
#closeSidebarBtn,
#deleteBtn,
#emptyStateNewBtn,
#deleteCancelBtn,
#deleteConfirmBtn {
  backdrop-filter: blur(10px);
}

#searchInput {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

html.dark #searchInput {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

#saveStatus {
  letter-spacing: 0.02em;
}

/* ── Entry date groups ──────────────────────────────────── */
.entry-group {
  margin-bottom: 0.25rem;
}

.entry-group-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #a8a29e;
  padding: 0.15rem 0.25rem 0.55rem;
  margin-bottom: 0.25rem;
}

html.dark .entry-group-label {
  color: #57534e;
}

/* ── Editor footer stats ────────────────────────────────── */
#readingTime {
  opacity: 0.75;
}

@media (max-width: 640px) {
  #readingTime {
    display: none;
  }
}

@media (max-width: 1023px) {
  body {
    overflow-x: hidden;
  }

  .controls-wrap {
    width: 100%;
  }

  body.focus-mode #workspace > main {
    min-height: calc(100vh - 1.5rem);
  }

  .editor-shell {
    padding-right: 1rem;
    padding-bottom: 7.25rem;
  }
}

@media (min-width: 1024px) {
  .topbar-controls {
    max-width: min(70%, 780px);
  }
}

@media (max-width: 640px) {
  #appShell {
    padding-left: 0.9rem;
    padding-right: 0.9rem;
    padding-top: 0.9rem;
    padding-bottom: 1rem;
  }

  #topBar {
    align-items: center;
    gap: 0.9rem;
    padding: 0.95rem;
  }

  .topbar-controls {
    flex-wrap: nowrap;
    gap: 0.75rem;
  }

  .topbar-controls label {
    min-width: 0;
  }

  #searchInput {
    height: 2.9rem;
    padding-top: 0;
    padding-bottom: 0;
    font-size: 0.9rem;
  }

  #sidebar {
    inset: 5.9rem 0.9rem 0.9rem 0.9rem;
    width: auto;
    max-width: none;
    border-radius: 1.7rem;
  }

  main.panel {
    padding: 1rem;
    border-radius: 1.9rem;
  }

  .editor-toolbar {
    gap: 0.9rem;
  }

  .editor-toolbar > div:first-child {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.45rem;
    align-items: stretch;
  }

  .editor-toolbar > div:first-child button,
  .editor-toolbar > div:first-child span {
    min-height: 2.6rem;
    width: 100%;
    justify-content: center;
    text-align: center;
    border-radius: 1rem;
    padding-left: 0.65rem;
    padding-right: 0.65rem;
  }

  #mobileQuickNewBtn,
  #focusToggle,
  #deleteBtn {
    font-size: 0.78rem;
  }

  #mobileQuickNewBtn,
  #focusToggle,
  #deleteBtn {
    gap: 0.35rem;
  }

  #focusToggle svg,
  #deleteBtn svg,
  #mobileQuickNewBtn svg {
    flex-shrink: 0;
  }

  #saveStatus {
    display: none !important;
  }

  #titleInput {
    font-size: 3rem;
  }

  .journal-area {
    font-size: 1.25rem;
    line-height: 2.1rem;
  }

  .editor-shell {
    padding-bottom: calc(7.8rem + env(safe-area-inset-bottom));
  }

  #editToolbar {
    width: calc(100vw - 1.3rem);
    max-width: 24rem;
    justify-content: center;
    padding: 0.75rem;
    border-radius: 1.45rem;
    bottom: max(0.75rem, env(safe-area-inset-bottom)) !important;
  }

  .toolbar-desktop {
    display: none !important;
  }

  .toolbar-mobile {
    display: grid !important;
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar-mobile-field {
    width: 100%;
  }

  body.focus-mode #editToolbar {
    width: calc(100vw - 1.3rem);
    max-width: 24rem;
  }
}

@media (min-width: 641px) {
  .toolbar-mobile {
    display: none !important;
  }
}

@media (min-width: 1280px) {
  .editor-toolbar {
    flex-wrap: nowrap;
  }
}
