:root {
  color-scheme: light;
  --ink: #202124;
  --muted: #72766f;
  --line: #d9ddd5;
  --paper: #fbfaf7;
  --panel: #ffffff;
  --accent: #1d6f5f;
  --accent-soft: #e8f1ed;
  --danger: #9a241d;
  --shadow: 0 18px 50px rgba(32, 33, 36, 0.08);
  --font-sans: "Imprima", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-heading: "Playwrite US Modern", "Imprima", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "Space Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 6px;
  padding: 0.66rem 0.92rem;
  cursor: pointer;
  text-decoration: none;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.48rem;
  min-height: 2.72rem;
}

button:hover,
.button:hover {
  filter: brightness(0.96);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.ghost {
  background: transparent;
  color: var(--accent);
}

.icon {
  width: 1.08rem;
  height: 1.08rem;
  flex: 0 0 auto;
}

.icon-button {
  width: 2.72rem;
  height: 2.72rem;
  padding: 0;
  border-color: var(--line);
  background: transparent;
  color: var(--accent);
}

.icon-button.active,
.home-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.icon-text {
  min-height: 2.4rem;
  padding-inline: 0.68rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 0.66rem 0.76rem;
  font-family: var(--font-mono);
}

input[type="date"] {
  min-height: 3.1rem;
  padding-block: 0.48rem;
}

textarea {
  resize: vertical;
  line-height: 1.48;
}

label {
  display: grid;
  gap: 0.34rem;
}

label span,
.list-meta,
small {
  color: var(--muted);
  font-size: 0.82rem;
}

label span,
form small,
.segmented button {
  font-family: var(--font-mono);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1,
h2,
h3 {
  font-family: var(--font-heading);
  font-weight: 400;
}

.eyebrow {
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  font-variant-caps: all-small-caps;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login-panel {
  width: min(100%, 380px);
  display: grid;
  gap: 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.shell,
.share-shell {
  min-height: 100vh;
}

.shell {
  display: grid;
  grid-template-rows: auto 1fr;
}

.share-shell {
  display: block;
}

.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 250, 247, 0.94);
  padding: 0.82rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(12px);
}

.home-button {
  background: transparent;
  color: var(--ink);
  border-color: transparent;
  font-size: 1.02rem;
  padding-inline: 0.66rem;
}

.top-actions,
.editor-actions,
.modal-actions,
.settings-actions {
  display: flex;
  align-items: center;
  gap: 0.58rem;
  flex-wrap: wrap;
}

.editor-actions {
  flex-wrap: nowrap;
  flex: 0 0 auto;
  gap: 0.5rem;
}

.editor-actions button,
.editor-actions .button {
  white-space: nowrap;
}

.icon-only-action {
  width: 2.72rem;
  padding-inline: 0;
}

.logout-button {
  border-color: transparent;
  min-height: 2.72rem;
}

.home-view {
  min-height: calc(100vh - 68px);
  display: grid;
  place-items: center;
  padding: clamp(1.2rem, 4vw, 3rem);
}

.home-actions {
  width: min(680px, 100%);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.home-card {
  min-height: 180px;
  border-color: var(--line);
  background: white;
  color: var(--ink);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.8rem;
  font-size: 1.25rem;
  box-shadow: none;
}

.home-card .icon {
  width: 2rem;
  height: 2rem;
  color: var(--accent);
}

.archives-page,
.settings-page,
.new-letter-page {
  width: min(1320px, 100%);
  margin: 0 auto;
  padding: clamp(1rem, 2vw, 2rem);
  display: grid;
  gap: 1rem;
  align-content: start;
}

.gallery-filters {
  display: grid;
  grid-template-columns: minmax(280px, 1.5fr) minmax(180px, 0.8fr) minmax(130px, 0.5fr);
  gap: 0.8rem;
  align-items: end;
  border-bottom: 1px solid var(--line);
  padding-bottom: 1rem;
}

.filters {
  display: grid;
  gap: 0.6rem;
}

.search-field {
  position: relative;
}

.search-field input {
  padding-left: 2.36rem;
}

.input-icon {
  position: absolute;
  left: 0.78rem;
  bottom: 0.82rem;
  color: var(--muted);
  display: grid;
  place-items: center;
  pointer-events: none;
}

.gallery-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.archive-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.78rem;
  align-items: start;
}

.letter-card {
  position: relative;
  min-height: 148px;
  display: grid;
  align-content: start;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  border-color: var(--line);
  background: white;
  color: var(--ink);
  padding: 1rem 3.15rem 1rem 1rem;
  cursor: pointer;
}

.letter-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.letter-card strong {
  font-size: 1.18rem;
  font-weight: 400;
  line-height: 1.16;
}

.letter-card span:not(.card-year) {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.card-actions {
  position: absolute;
  top: 0.82rem;
  right: 0.82rem;
  display: flex;
  gap: 0.28rem;
}

.card-icon-button {
  width: 1.86rem;
  height: 1.86rem;
  min-height: 0;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--accent);
}

.card-icon-button:hover,
.card-icon-button:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.card-icon-button .icon {
  width: 1rem;
  height: 1rem;
}

.card-year {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.gallery-pager {
  justify-self: center;
  width: min(360px, 100%);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  min-height: 0;
}

.editor-workspace {
  min-height: calc(100vh - 68px);
  display: grid;
  justify-items: center;
  align-items: start;
  padding-inline: clamp(0.2rem, 2vw, 1.2rem);
}

.archive {
  border-right: 1px solid var(--line);
  padding: 1rem;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 0.8rem;
  min-height: calc(100vh - 68px);
}

.letter-list {
  display: grid;
  align-content: start;
  gap: 0.45rem;
  overflow: auto;
  padding-right: 0.2rem;
}

.letter-row {
  display: grid;
  gap: 0.25rem;
  width: 100%;
  min-height: 72px;
  text-align: left;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  border-radius: 8px;
  padding: 0.72rem;
}

.letter-row.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.letter-row span {
  font-weight: 700;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.editor {
  min-width: 0;
  padding: 1.1rem clamp(1rem, 2vw, 2rem) 2rem;
  display: grid;
  gap: 1rem;
  align-content: start;
}

.share-shell .editor {
  width: min(1120px, 100%);
  margin: 0 auto;
}

.editor-workspace .editor {
  width: min(1120px, 100%);
}

.editor-form,
.share-panel {
  display: grid;
  gap: 1rem;
}

.editor-head,
.share-panel {
  border-bottom: 1px solid var(--line);
  padding-bottom: 1rem;
}

.editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.editor-head h2 {
  font-size: clamp(1.28rem, 2.1vw, 1.72rem);
  line-height: 1.18;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.78rem;
  align-items: start;
}

.field-subject,
.field-to {
  grid-column: span 2;
}

.form-grid.compact label,
.settings-grid label {
  grid-column: auto;
}

.field-customdate,
.field-custom_date {
  align-self: start;
}

.field-customdate input,
.field-custom_date input {
  height: 3.1rem;
}

.details {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.9rem;
  background: rgba(255, 255, 255, 0.62);
}

.details summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 700;
}

.body-editor textarea {
  min-height: 48vh;
  font-family: var(--font-mono);
  font-size: 0.92rem;
}

.share-panel {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 420px);
  align-items: end;
}

.share-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
}

.share-link {
  grid-column: 1 / -1;
}

.settings-form {
  display: grid;
  gap: 1rem;
}

.new-letter-form {
  width: min(1120px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 1rem;
}

.settings-section {
  display: grid;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 1rem;
}

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

.template-section {
  border-bottom: 0;
}

.template-form,
.template-list,
.template-card,
.category-form,
.category-list,
.category-card {
  display: grid;
  gap: 0.8rem;
}

.template-list,
.category-list {
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

.template-card,
.category-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 0.9rem;
}

.category-form {
  grid-template-columns: minmax(260px, 420px) auto;
  align-items: end;
}

.category-card small {
  font-family: var(--font-mono);
}

.template-card textarea,
.template-form textarea {
  min-height: 14rem;
}

.template-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.72rem;
}

.checkbox-field input {
  width: auto;
}

.notice {
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  padding: 0.75rem 0.9rem;
  border-radius: 6px;
}

.error {
  color: var(--danger);
}

.empty,
.empty-note {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(32, 33, 36, 0.28);
  display: grid;
  place-items: center;
  padding: 1rem;
}

.command-backdrop {
  align-items: start;
  padding-top: min(12vh, 6rem);
  z-index: 30;
}

.command-modal {
  width: min(720px, 100%);
  max-height: min(720px, 86vh);
  overflow: hidden;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
}

.command-search {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
  padding: 0.82rem;
  border-bottom: 1px solid var(--line);
}

.command-search form {
  position: relative;
}

.command-search input {
  min-height: 2.72rem;
  padding-left: 2.36rem;
}

.command-results {
  display: grid;
  gap: 0.45rem;
  align-content: start;
  max-height: min(560px, 68vh);
  overflow: auto;
  padding: 0.82rem;
}

.command-results button {
  display: grid;
  grid-template-columns: auto 1fr;
  justify-content: start;
  align-items: center;
  width: 100%;
  min-height: 4.2rem;
  text-align: left;
  border-color: var(--line);
  background: white;
  color: var(--ink);
}

.command-results button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.command-results span {
  display: grid;
  gap: 0.22rem;
}

.command-results strong {
  font-weight: 400;
}

.modal {
  width: min(1040px, 100%);
  max-height: min(860px, 94vh);
  overflow: auto;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 1rem;
  display: grid;
  gap: 1rem;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.email-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.email-form label:has(textarea),
.email-form .segmented,
.modal-actions {
  grid-column: 1 / -1;
}

.segmented {
  display: inline-flex;
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.segmented button {
  border: 0;
  border-radius: 0;
  background: white;
  color: var(--ink);
}

.segmented button.active {
  background: var(--accent);
  color: white;
}

.preview-area {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

.preview-list {
  display: grid;
  gap: 0.4rem;
  align-content: start;
}

.preview-list button {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem;
  align-items: center;
  text-align: left;
  background: white;
  color: var(--ink);
  border-color: var(--line);
}

.preview-list button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.preview-list input {
  width: auto;
}

.preview-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  display: grid;
  gap: 0.8rem;
}

@media (max-width: 880px) {
  .topbar,
  .editor-head {
    align-items: stretch;
    display: grid;
  }

  .editor-actions {
    flex-wrap: wrap;
  }

  .home-button {
    justify-content: start;
  }

  .home-actions,
  .workspace,
  .gallery-filters,
  .form-grid,
  .email-form,
  .preview-area,
  .share-panel,
  .settings-grid,
  .category-form,
  .category-list,
  .template-list {
    grid-template-columns: 1fr;
  }

  .archive {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .form-grid label:nth-child(4),
  .form-grid label:nth-child(5) {
    grid-column: auto;
  }

  .field-subject,
  .field-to {
    grid-column: auto;
  }

  .home-card {
    min-height: 136px;
  }
}
