/* Letters to My Future Self — base styles
   Inter font, white card on light grey background, mobile-friendly.
   Light & dark themes via CSS variables. */

/* ---- Theme tokens ------------------------------------------------------- */
:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #1f2937;
  --text-strong: #111827;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --border: #e5e7eb;
  --thumb-bg: #f3f4f6;
  --btn-primary-bg: #111827;
  --btn-primary-bg-hover: #1f2937;
  --btn-primary-text: #ffffff;
  --btn-primary-disabled: #9ca3af;
  --btn-ghost-bg: #f3f4f6;
  --btn-ghost-bg-hover: #e5e7eb;
  --btn-ghost-text: #374151;
  --status-error: #b91c1c;
  --status-success: #047857;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --thumb-overlay: rgba(17, 24, 39, 0.75);
  --thumb-overlay-hover: rgba(17, 24, 39, 0.9);
  --color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0f1115;
  --card: #1a1d23;
  --text: #e5e7eb;
  --text-strong: #f9fafb;
  --text-muted: #9ca3af;
  --text-faint: #6b7280;
  --border: #2a2e36;
  --thumb-bg: #2a2e36;
  --btn-primary-bg: #f3f4f6;
  --btn-primary-bg-hover: #ffffff;
  --btn-primary-text: #111827;
  --btn-primary-disabled: #4b5563;
  --btn-ghost-bg: #2a2e36;
  --btn-ghost-bg-hover: #353a44;
  --btn-ghost-text: #e5e7eb;
  --status-error: #f87171;
  --status-success: #34d399;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.5);
  --thumb-overlay: rgba(0, 0, 0, 0.7);
  --thumb-overlay-hover: rgba(0, 0, 0, 0.9);
  --color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  color-scheme: var(--color-scheme);
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 17px;
  line-height: 1.6;
  transition: background 200ms ease, color 200ms ease;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 20px 48px;
}

/* View switching */
.view {
  display: none;
  width: 100%;
  max-width: 720px;
}
.view--active {
  display: block;
}

/* Card */
.card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  transition: background 200ms ease, box-shadow 200ms ease;
}

@media (max-width: 600px) {
  .app {
    padding: 16px 12px 32px;
  }
  .card {
    padding: 20px;
    border-radius: 14px;
  }
}

/* Drag-and-drop highlight */
.card {
  position: relative;
  outline: 2px dashed transparent;
  outline-offset: -8px;
  transition: outline-color 120ms ease, background 200ms ease;
}
.card--drag {
  outline-color: var(--text-strong);
}
.card--drag::after {
  content: "Drop photos to attach";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  color: var(--text-strong);
  font-weight: 500;
  font-size: 18px;
  border-radius: inherit;
  pointer-events: none;
  z-index: 1;
}

/* Auth bar */
.auth-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: var(--btn-ghost-bg);
  border-radius: 10px;
  font-size: 13px;
}
.auth-status {
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.auth-status--connected { color: var(--status-success); }
.auth-status--disconnected { color: var(--text-muted); }
.auth-status--error { color: var(--status-error); }
.auth-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}

/* Letter header */
.letter-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
}

.letter-header__date-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 2px 6px;
  margin-left: -6px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-strong);
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background 120ms ease;
  -webkit-tap-highlight-color: transparent;
  width: fit-content;
}
.letter-header__date-wrap:hover {
  background: var(--btn-ghost-bg);
}
.letter-header__date-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}
/* Native date input layered invisibly over the date text.
   Clicks pass through to it so the OS picker opens & dismisses correctly. */
.letter-header__date-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: transparent;
  background: transparent;
}
.letter-header__date-input::-webkit-calendar-picker-indicator {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  cursor: pointer;
  opacity: 0;
}

.letter-header__meta {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 400;
}

.letter-header__meta .dot {
  margin: 0 6px;
  color: var(--text-faint);
}

/* Letter body */
.letter-body {
  width: 100%;
  min-height: 360px;
  resize: vertical;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 17px;
  line-height: 1.7;
  color: var(--text);
  background: transparent;
  padding: 0;
}

.letter-body::placeholder {
  color: var(--text-faint);
  font-style: italic;
}

@media (max-width: 600px) {
  .letter-body {
    min-height: 280px;
    font-size: 16px;
  }
}

/* Photo hint */
.photo-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* Photo previews */
.photo-previews {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}

.photo-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  background: var(--thumb-bg);
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-thumb__remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--thumb-overlay);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.photo-thumb__remove:hover {
  background: var(--thumb-overlay-hover);
}

/* Footer / actions */
.letter-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-top: 4px;
}

@media (max-width: 600px) {
  .letter-footer {
    flex-direction: column-reverse;
    align-items: stretch;
  }
}

/* Buttons */
[hidden] { display: none !important; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  padding: 10px 18px;
  cursor: pointer;
  transition: background 120ms ease, transform 80ms ease, color 120ms ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}
.btn--primary:hover {
  background: var(--btn-primary-bg-hover);
}
.btn--primary:disabled {
  background: var(--btn-primary-disabled);
  cursor: not-allowed;
}

.btn--ghost {
  background: var(--btn-ghost-bg);
  color: var(--btn-ghost-text);
}
.btn--ghost:hover {
  background: var(--btn-ghost-bg-hover);
}

.btn--small {
  font-size: 14px;
  padding: 6px 12px;
}

/* Status line */
.status {
  font-size: 14px;
  color: var(--text-muted);
  min-height: 20px;
}
.status--error {
  color: var(--status-error);
}
.status--success {
  color: var(--status-success);
}

/* Bottom nav */
.nav {
  margin-top: 16px;
  text-align: center;
}
.nav__link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 8px;
}
.nav__link:hover {
  color: var(--text-strong);
}

/* Archive view */
.archive-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
}
.archive-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-strong);
}
.archive-empty {
  color: var(--text-muted);
  margin: 0;
}

/* Theme toggle (floating top-right) */
.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-strong);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: background 120ms ease, color 120ms ease, transform 80ms ease;
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
}
.theme-toggle:hover {
  color: var(--text-strong);
  background: var(--btn-ghost-bg-hover);
}
.theme-toggle:active {
  transform: scale(0.95);
}
.theme-toggle__icon {
  width: 18px;
  height: 18px;
}
/* Show only the icon matching the current theme */
[data-theme="dark"] .theme-toggle__icon--moon { display: none; }
[data-theme="dark"] .theme-toggle__icon--sun  { display: block; }
:root:not([data-theme="dark"]) .theme-toggle__icon--moon { display: block; }
:root:not([data-theme="dark"]) .theme-toggle__icon--sun  { display: none; }

@media (max-width: 600px) {
  .theme-toggle {
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
  }
}
