:root {
  color-scheme: light;
  --bg-start: #fffdf6;
  --bg-end: #faf6e9;
  --ink: #33372b;
  --muted: #6d715f;
  --panel: rgba(255, 253, 246, 0.94);
  --line: #e5dfcb;
  --soft-line: #efe8d8;
  --accent: #ddeb9d;
  --accent-dark: #a0c878;
  --green: #a0c878;
  --danger: #c65f55;
  --shadow: 0 22px 54px rgba(99, 116, 70, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(221, 235, 157, 0.42), rgba(160, 200, 120, 0.22)),
    linear-gradient(180deg, var(--bg-start), var(--bg-end));
}

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

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px max(24px, calc((100vw - 1152px) / 2));
  border-bottom: 1px solid rgba(160, 200, 120, 0.28);
  background: rgba(255, 253, 246, 0.76);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 28px;
  place-items: center;
  border-radius: 6px;
  color: #688d4c;
  background: #faf6e9;
  box-shadow: 0 4px 10px rgba(99, 116, 70, 0.18);
}

.brand-mark img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.icon {
  display: block;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  object-fit: contain;
}

.button-label {
  min-width: 0;
}

.brand strong {
  display: block;
  font-family: "Brush Script MT", "Segoe Script", cursive;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  line-height: 0.9;
  text-shadow: 0 2px 8px rgba(160, 200, 120, 0.3);
}

.brand small {
  display: block;
  margin-top: 6px;
  font-size: 0.98rem;
  opacity: 0.9;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 12px 20px;
  border: 1px solid rgba(160, 200, 120, 0.34);
  border-radius: 999px;
  color: #4f6540;
  text-decoration: none;
  background: rgba(255, 253, 246, 0.58);
  transition: transform 160ms ease, background 160ms ease;
}

.nav-link:hover,
.nav-link:focus-visible,
.nav-link.active {
  background: rgba(221, 235, 157, 0.5);
  transform: translateY(-1px);
}

main {
  padding: 34px 24px 64px;
}

.is-hidden {
  display: none !important;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 550px) minmax(0, 550px);
  gap: 32px;
  align-items: start;
  max-width: 1152px;
  margin: 0 auto;
}

.panel {
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.compose-panel,
.preview-panel {
  padding: clamp(22px, 4vw, 32px);
}

.section-title {
  margin-bottom: 24px;
  text-align: center;
}

.section-title h1,
.section-title h2,
.wall-heading h2 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 1.75rem);
  line-height: 1.2;
}

.section-title p,
.wall-heading p {
  margin: 8px 0 0;
  color: var(--muted);
}

label {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

label span {
  color: #555965;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: rgba(255, 253, 246, 0.82);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

input {
  min-height: 44px;
  padding: 0 14px;
}

select {
  min-height: 44px;
  padding: 0 38px 0 14px;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #6d715f 50%),
    linear-gradient(135deg, #6d715f 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 19px,
    calc(100% - 12px) 19px;
  background-repeat: no-repeat;
  background-size: 6px 6px;
}

textarea {
  min-height: 198px;
  resize: vertical;
  padding: 14px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(160, 200, 120, 0.9);
  background-color: #fffdf6;
  box-shadow: 0 0 0 4px rgba(221, 235, 157, 0.42);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.consent {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  margin: 2px 0 16px;
  padding: 12px;
  border: 1px solid var(--soft-line);
  border-radius: 10px;
  background: rgba(250, 246, 233, 0.58);
}

.consent input {
  width: 17px;
  min-height: 17px;
  accent-color: var(--accent);
}

.consent label {
  display: block;
  margin: 0;
  color: #58664b;
  font-size: 0.9rem;
}

.actions,
.file-actions {
  display: grid;
  gap: 10px;
}

.actions {
  grid-template-columns: 1fr auto auto;
}

.file-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 12px;
}

.primary,
.ghost,
.download,
.file-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  border: 0;
  border-radius: 10px;
  font-weight: 700;
}

.primary {
  color: #fffdf6;
  background: linear-gradient(135deg, #b2d284, var(--accent-dark));
}

.ghost,
.file-actions button {
  border: 1px solid var(--line);
  color: #58664b;
  background: rgba(255, 253, 246, 0.72);
}

.download {
  width: min(210px, 100%);
  margin: 18px auto 0;
  color: #fffdf6;
  background: var(--green);
}

.primary:hover,
.download:hover,
.ghost:hover,
.file-actions button:hover {
  filter: brightness(1.03);
  transform: translateY(-1px);
}

.status {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.paper-wrap {
  padding: 16px;
  border-radius: 12px;
  background: #efe8d4;
  box-shadow: inset 0 0 18px rgba(99, 116, 70, 0.1);
}

.paper {
  position: relative;
  min-height: 300px;
  padding: 34px 28px;
  overflow: hidden;
  border-radius: 8px;
  color: #34343a;
  font-family: "Times New Roman", Times, serif;
  background:
    repeating-linear-gradient(#fffdf6 0 31px, #ece7d8 32px),
    #fffdf6;
  box-shadow: 0 10px 22px rgba(99, 116, 70, 0.16);
}

.paper-meta {
  display: grid;
  justify-items: end;
  gap: 8px;
  min-height: 56px;
  color: #68626a;
  font-size: 1rem;
  font-style: italic;
}

.salutation {
  margin: 32px 0 18px;
  font-size: clamp(1.45rem, 4vw, 1.9rem);
  font-style: italic;
}

.letter-body {
  min-height: 110px;
  margin: 0;
  white-space: pre-wrap;
  font-size: 1.1rem;
  line-height: 1.85;
}

.signature {
  display: grid;
  justify-items: end;
  margin-top: 22px;
  font-size: 1.1rem;
  font-style: italic;
}

.signature strong {
  min-height: 24px;
  font-weight: 700;
}

.wall-section {
  max-width: 1152px;
  margin: 36px auto 0;
  padding: 28px;
  border-radius: 16px;
  background: rgba(250, 246, 233, 0.52);
  backdrop-filter: blur(10px);
}

.wall-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  color: var(--ink);
}

.wall-heading p {
  color: var(--muted);
}

#letterCount {
  flex: 0 0 auto;
  padding: 8px 12px;
  border-radius: 999px;
  color: #526842;
  background: rgba(221, 235, 157, 0.58);
}

.wall-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
}

.search-field {
  margin: 0;
}

.search-field span {
  color: #66704f;
}

.wall-compose-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  color: #fffdf6;
  background: var(--green);
  font-weight: 700;
  text-decoration: none;
}

.letters-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.letter-card {
  position: relative;
  min-height: 190px;
  padding: 22px;
  border-radius: 12px;
  color: #37363d;
  font-family: "Times New Roman", Times, serif;
  background: repeating-linear-gradient(#fffdf6 0 29px, #ece7d8 30px);
  box-shadow: 0 14px 34px rgba(99, 116, 70, 0.14);
}

.card-topline {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-height: 24px;
  margin-bottom: 2px;
}

.music-badge,
.edited-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 800;
}

.music-badge {
  color: #526842;
  background: rgba(160, 200, 120, 0.22);
}

.music-badge .icon {
  width: 14px;
  height: 14px;
}

.edited-badge {
  color: #5d7347;
  background: rgba(221, 235, 157, 0.58);
}

.card-to {
  margin: 0 0 12px;
  font-size: 1.3rem;
  font-style: italic;
}

.card-message {
  display: -webkit-box;
  min-height: 86px;
  margin: 0;
  overflow: hidden;
  font-size: 1.02rem;
  line-height: 1.55;
  white-space: pre-wrap;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.letter-card footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  color: #74725f;
  font-size: 0.92rem;
}

.card-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 16px;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
}

.card-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  border: 1px solid rgba(160, 200, 120, 0.28);
  border-radius: 8px;
  color: #58664b;
  background: rgba(255, 253, 246, 0.74);
  font-size: 0.86rem;
  font-weight: 800;
}

.card-action.danger {
  color: var(--danger);
}

.empty-state {
  grid-column: 1 / -1;
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 30px;
  border: 1px dashed rgba(160, 200, 120, 0.72);
  border-radius: 12px;
  color: var(--ink);
  text-align: center;
}

.empty-state h3 {
  margin: 0;
  font-size: 1.35rem;
}

.empty-state p {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
}

.empty-state a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 10px;
  color: #526842;
  background: rgba(221, 235, 157, 0.58);
  font-weight: 800;
  text-decoration: none;
}

.route-section {
  max-width: 860px;
  margin: 34px auto 0;
}

.route-card {
  padding: clamp(24px, 5vw, 36px);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
}

.route-eyebrow {
  margin: 0 0 10px;
  color: #6f914f;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.route-card h2 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2rem);
}

.route-card p {
  color: var(--muted);
}

.view-paper-wrap {
  max-width: 680px;
  margin: 24px auto 0;
}

.view-paper {
  min-height: 520px;
  padding: clamp(28px, 5vw, 48px);
  text-align: left;
}

.view-paper .letter-body {
  min-height: 190px;
  font-size: clamp(1.08rem, 2vw, 1.22rem);
}

.music-player {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: min(680px, 100%);
  margin: 18px auto 0;
  padding: 12px;
  border: 1px solid rgba(160, 200, 120, 0.34);
  border-radius: 12px;
  background: rgba(250, 246, 233, 0.7);
}

.music-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  color: #fffdf6;
  background: var(--green);
  font-weight: 800;
}

.music-meta {
  display: grid;
  min-width: 0;
  text-align: left;
}

.music-meta span {
  color: #66704f;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.music-meta strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 0.95rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.music-player audio {
  display: none;
}

.music-player + .view-paper-wrap {
  margin-top: 16px;
}

.route-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 22px;
}

.route-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: #58664b;
  background: rgba(255, 253, 246, 0.74);
  font-weight: 700;
  text-decoration: none;
}

.primary-link {
  border-color: transparent;
  color: #fffdf6;
  background: linear-gradient(135deg, #b2d284, var(--accent-dark));
}

.share-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(73, 82, 55, 0.36);
  backdrop-filter: blur(8px);
}

.share-dialog {
  width: min(620px, 100%);
  padding: clamp(22px, 4vw, 30px);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.share-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.share-header h2 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2rem);
}

.share-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: #58664b;
  background: rgba(255, 253, 246, 0.78);
  padding: 0;
}

.share-field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.share-field label {
  display: block;
  margin: 0;
  color: #555965;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.share-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.share-row input {
  min-width: 0;
}

.share-row button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: #58664b;
  background: rgba(255, 253, 246, 0.74);
  font-weight: 800;
}

.share-field.private {
  padding: 14px;
  border: 1px solid rgba(160, 200, 120, 0.36);
  border-radius: 12px;
  background: rgba(221, 235, 157, 0.25);
}

.share-field.private p {
  margin: 0;
  color: #617146;
  font-size: 0.92rem;
}

.share-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

@media (max-width: 920px) {
  .topbar,
  .workspace,
  .wall-heading {
    align-items: stretch;
  }

  .topbar,
  .wall-heading {
    flex-direction: column;
  }

  .nav {
    justify-content: flex-start;
  }

  .workspace,
  .letters-grid,
  .wall-tools {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  main {
    padding: 24px 14px 48px;
  }

  .topbar {
    padding: 16px 14px;
  }

  .nav-link {
    flex: 1;
    text-align: center;
  }

  .field-grid,
  .actions,
  .file-actions {
    grid-template-columns: 1fr;
  }

  .compose-panel,
  .preview-panel,
  .wall-section {
    padding: 18px;
  }

  .paper {
    padding: 28px 20px;
  }

  .share-row,
  .share-actions {
    grid-template-columns: 1fr;
  }

  .share-row {
    display: grid;
  }

  .share-actions {
    justify-content: stretch;
  }

  .music-player {
    align-items: stretch;
    flex-direction: column;
  }

  .music-meta {
    text-align: center;
  }
}
