@font-face {
  font-family: "TerrarumSansBitmap";
  src:
    local("TerrarumSansBitmap"),
    url("/fonts/TerrarumSansBitmap.otf") format("opentype");
  font-display: swap;
}

@font-face {
  font-family: "KyoboHandwriting2025LYB";
  src:
    local("KyoboHandwriting2025lyb"),
    local("교보손글씨 2025"),
    url("/fonts/KyoboHandwriting2025lyb.ttf") format("truetype");
  font-display: swap;
}

* {
  box-sizing: border-box;
}

:root {
  --ui-font: "TerrarumSansBitmap", "Gowun Dodum", "SUIT", "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --hand-font: "KyoboHandwriting2025LYB", "KyoboHandwriting2025lyb", "Nanum Pen Script", "Segoe Print", cursive;
  --bg: #f7efe4;
  --panel: rgba(255, 252, 246, 0.84);
  --ink: #2f2721;
  --soft-ink: #7a6b60;
  --line: rgba(70, 49, 34, 0.13);
  --accent: #8b5d3b;
  --accent-dark: #5e3d2a;
  --rose: #b56b62;
  --shadow: 0 24px 70px rgba(72, 48, 28, 0.12);
  --radius: 30px;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-size: 18px;
  background:
    radial-gradient(circle at 16% 0%, rgba(255, 244, 214, 0.95), transparent 34rem),
    radial-gradient(circle at 100% 18%, rgba(250, 221, 209, 0.58), transparent 28rem),
    linear-gradient(135deg, #f9f1e6 0%, #efe0cf 100%);
  font-family: var(--ui-font);
}

html {
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

body {
  overflow-x: hidden;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  opacity: 0.46;
  background-image:
    linear-gradient(rgba(62, 39, 24, 0.033) 1px, transparent 1px),
    linear-gradient(90deg, rgba(62, 39, 24, 0.024) 1px, transparent 1px);
  background-size: 38px 38px;
}

button,
input,
textarea,
select {
  font-family: inherit;
  font-size: 1rem;
}

button {
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

button:hover {
  transform: translateY(-2px);
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 78px;
}

body.auth-mode .app-shell {
  padding-top: clamp(62px, 7vh, 86px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 22px;
  align-items: flex-start;
  margin-bottom: 26px;
}

body.auth-mode .topbar {
  margin-bottom: clamp(38px, 5vh, 60px);
}

body.auth-mode main {
  padding-top: clamp(22px, 3vh, 36px);
}

.brand {
  max-width: 620px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 15px;
  text-transform: uppercase;
  font-weight: 900;
}

h1,
h2,
h3,
p {
  word-break: keep-all;
}

h1,
h2,
h3 {
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 76px;
  line-height: 0.98;
  letter-spacing: -0.04em;
}

h2 {
  margin: 0;
  font-size: 34px;
}

h3 {
  margin: 0;
  font-size: 22px;
}

.muted {
  color: var(--soft-ink);
  line-height: 1.7;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  padding: 26px;
  overflow: visible;
}

.hidden {
  display: none !important;
}

.profile-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  margin-top: 30px;
  background: rgba(255, 253, 248, 0.7);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px 6px 20px;
  color: var(--soft-ink);
  box-shadow: 0 12px 30px rgba(72, 48, 28, 0.07);
}

.profile-box span {
  display: inline-flex;
  align-items: center;
  min-height: 1em;
  line-height: 1.2;
  white-space: nowrap;
  transform: translateY(1px);
}

body.auth-mode .profile-box {
  padding: 6px 20px;
}

.profile-box .ghost-btn {
  min-height: 42px;
  padding: 9px 15px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--accent-dark);
}

button,
.primary-action {
  border: 0;
  border-radius: 17px;
  background: var(--accent);
  color: white;
  padding: 15px 20px;
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(100, 61, 34, 0.16);
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.68);
  color: var(--accent-dark);
  border: 1px solid var(--line);
  box-shadow: none;
  padding: 10px 13px;
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 30px;
  align-items: center;
  padding-bottom: 22px;
}

.auth-form {
  display: grid;
  gap: 12px;
  width: min(100%, 380px);
  justify-self: center;
  align-self: center;
}

.auth-form label {
  display: grid;
  gap: 7px;
  align-items: stretch;
  width: 100%;
}

.auth-form input {
  min-height: 54px;
  padding: 11px 15px;
  line-height: 1.2;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.auth-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  padding: 11px 16px;
  text-align: center;
}

.feedback {
  min-height: 22px;
  margin: 0;
  color: var(--soft-ink);
}

.feedback:empty {
  display: none;
}

.feedback.is-error {
  color: #9a3f34;
}

label,
legend,
.field-label {
  color: var(--soft-ink);
  font-weight: 900;
  font-size: 16px;
}

.field-label {
  margin: 0;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
  border-radius: 17px;
  padding: 13px 15px;
  outline: none;
}

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

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(139, 93, 59, 0.55);
  box-shadow: 0 0 0 4px rgba(139, 93, 59, 0.08);
}

.tabs {
  display: flex;
  gap: 10px;
  margin: -8px -4px 18px;
  padding: 8px 4px 14px;
  overflow-x: auto;
  overflow-y: visible;
}

.tab {
  background: rgba(255, 255, 255, 0.5);
  color: var(--accent-dark);
  border: 1px solid var(--line);
  box-shadow: none;
  white-space: nowrap;
}

.tab.active {
  background: var(--ink);
  color: white;
}

.view-grid {
  display: grid;
  grid-template-columns: minmax(390px, 1fr) minmax(390px, 1fr);
  gap: 20px;
  align-items: stretch;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 22px;
}

.status-pill {
  color: var(--accent-dark);
  background: rgba(139, 93, 59, 0.08);
  border: 1px solid rgba(139, 93, 59, 0.14);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 15px;
  font-weight: 900;
  white-space: nowrap;
}

.letter-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 20px;
  align-items: start;
}

.letter-form label {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.letter-form .wide,
.wide {
  grid-column: 1 / -1;
}

.delay-field {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.delay-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.letter-form input,
.letter-form select {
  min-height: 58px;
}

.helper-row {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--soft-ink);
}

.small-label {
  margin: 0 0 8px;
  color: var(--soft-ink);
  font-weight: 900;
  font-size: 16px;
}

.recipient-area {
  margin-top: 0;
}

.saved-recipients {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 44px;
  align-items: center;
}

.user-chip {
  background: rgba(255, 255, 255, 0.58);
  color: var(--accent-dark);
  border: 1px solid rgba(89, 58, 40, 0.12);
  border-radius: 999px;
  padding: 9px 13px;
  box-shadow: none;
}

.template-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.template-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: none;
  padding: 12px;
  text-align: left;
}

.template-card.active {
  outline: 3px solid rgba(139, 93, 59, 0.18);
  border-color: rgba(139, 93, 59, 0.48);
}

.template-swatch {
  display: block;
  width: 100%;
  height: 54px;
  border-radius: 14px;
  border: 1px solid rgba(60, 50, 42, 0.16);
}

.swatch-cream {
  background: #fff4d9;
}

.swatch-white {
  background: #fffefb;
}

.swatch-lined {
  background:
    repeating-linear-gradient(to bottom, #fffdf4 0 31px, rgba(80, 110, 160, 0.18) 32px),
    #fffdf4;
}

.swatch-rose {
  background: linear-gradient(135deg, #fff2ec, #ffe1da);
}

.primary-action {
  grid-column: 1 / -1;
  width: 100%;
  margin-top: 4px;
  font-size: 18px;
}

.compose-panel,
.preview-panel {
  min-height: 800px;
}

.compose-panel {
  display: flex;
  flex-direction: column;
}

.compose-panel .letter-form {
  flex: 1;
}

.preview-panel {
  position: sticky;
  top: 18px;
  display: flex;
  flex-direction: column;
}

.paper {
  min-height: 610px;
  border-radius: 25px;
  padding: 36px 36px 44px;
  position: relative;
  overflow: hidden;
  box-shadow:
    inset 0 0 0 1px rgba(78, 52, 34, 0.08),
    0 18px 44px rgba(70, 42, 22, 0.11);
}

.preview-panel .paper {
  flex: 1;
}

.paper::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
  background:
    radial-gradient(circle at 20% 20%, rgba(80, 40, 15, 0.045), transparent 13rem),
    radial-gradient(circle at 80% 90%, rgba(80, 40, 15, 0.038), transparent 13rem);
}

.template-cream {
  background: #fff4d9;
}

.template-white {
  background: #fffefb;
}

.template-lined {
  background:
    repeating-linear-gradient(to bottom, #fffdf4 0 38px, rgba(80, 110, 160, 0.16) 39px, #fffdf4 40px),
    #fffdf4;
}

.template-rose {
  background:
    radial-gradient(circle at 92% 8%, rgba(181, 107, 98, 0.14), transparent 12rem),
    linear-gradient(135deg, #fff5ef, #ffe7df);
}

.paper-header {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
  color: rgba(50, 39, 31, 0.62);
  font-weight: 900;
}

.handwriting {
  position: relative;
  z-index: 1;
  min-height: 360px;
  font-family: var(--hand-font);
  font-size: 42px;
  line-height: 2.02;
  letter-spacing: 0;
  color: rgba(31, 25, 19, 0.96);
  word-break: break-word;
}

.hw-char {
  display: inline-block;
  white-space: pre;
  transform-origin: 50% 72%;
  will-change: transform, opacity;
  margin-right: var(--mr, 0px);
  color: rgba(31, 25, 19, var(--alpha, 0.94));
}

.hw-space {
  width: 0.36em;
}

.letter-list {
  display: grid;
  gap: 12px;
}

.letter-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
  border-radius: 23px;
  padding: 16px;
}

.letter-card p {
  margin: 5px 0 0;
  color: var(--soft-ink);
  line-height: 1.5;
}

.letter-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.meta-pill {
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(139, 93, 59, 0.08);
  color: var(--accent-dark);
  font-size: 15px;
  font-weight: 900;
}

.reply-pill {
  background: rgba(94, 61, 42, 0.14);
  color: var(--ink);
}

.locked-card {
  opacity: 0.86;
}

.reader-panel {
  margin-top: 18px;
  margin-bottom: 34px;
}

#backToBoxBtn {
  margin-bottom: 30px;
}

.reader-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.reply-context {
  margin: 0;
  padding: 16px;
  border: 1px solid rgba(80, 54, 34, 0.12);
  border-radius: 22px;
  background: rgba(255, 248, 238, 0.68);
}

.reader-reply-context {
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid rgba(80, 54, 34, 0.12);
  border-radius: 23px;
  background: rgba(255, 248, 238, 0.74);
}

.source-paper {
  min-height: 0;
  max-height: 340px;
  overflow: auto;
  padding: 24px 26px 30px;
  border-radius: 20px;
}

.source-paper .paper-header {
  margin-bottom: 12px;
}

.reply-context-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.reply-context-meta {
  margin: 3px 0 0;
  color: var(--soft-ink);
  font-size: 15px;
  line-height: 1.45;
}

.reply-paper {
  max-height: 230px;
  overflow: auto;
  border-radius: 18px;
  padding: 20px 22px;
  background:
    repeating-linear-gradient(to bottom, #fffdf5 0 34px, rgba(86, 105, 132, 0.12) 35px, #fffdf5 36px),
    #fffdf5;
  box-shadow: inset 0 0 0 1px rgba(78, 52, 34, 0.08);
}

.reply-handwriting {
  min-height: auto;
  font-size: 30px;
  line-height: 1.85;
}

.reply-handwriting.muted-source {
  font-family: var(--ui-font);
  font-size: 18px;
  line-height: 1.7;
  color: var(--soft-ink);
}

.reply-note {
  margin: 12px 0 0;
  color: var(--soft-ink);
  font-weight: 900;
  font-size: 15px;
}

.locked-view {
  text-align: center;
  padding: 76px 20px 86px;
}

.lock-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 90px;
  height: 74px;
  margin-bottom: 22px;
  border: 0;
  color: #c49ac9;
  background: transparent;
  font-size: 58px;
  line-height: 1;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", var(--ui-font);
  font-weight: 400;
  text-shadow: 0 10px 24px rgba(120, 76, 140, 0.13);
  box-shadow: none;
}

.locked-eyebrow {
  margin-bottom: 10px;
  color: var(--accent);
  font-size: 15px;
  letter-spacing: 0.16em;
}

.locked-view h2 {
  margin-bottom: 24px;
}

.locked-view .muted {
  margin: 8px 0 0;
  color: var(--soft-ink);
  line-height: 1.8;
}

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

.mini-card {
  background: rgba(255, 255, 255, 0.54);
  border: 1px solid rgba(80, 54, 34, 0.11);
  border-radius: 22px;
  padding: 18px;
}

.settings-form {
  display: grid;
  gap: 14px;
}

.settings-form label {
  display: grid;
  gap: 8px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100% - 44px));
  background: rgba(37, 33, 29, 0.94);
  color: white;
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: 0 14px 40px rgba(30, 20, 13, 0.24);
  z-index: 10;
}

#letterInput {
  min-height: 300px;
}

@media (max-width: 980px) {
  .topbar,
  .auth-panel,
  .view-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .profile-box {
    margin-top: 0;
    width: 100%;
    justify-content: space-between;
  }

  body.auth-mode .topbar {
    flex-direction: row;
    align-items: flex-start;
  }

  body.auth-mode .profile-box {
    width: auto;
    margin-top: 26px;
    margin-left: auto;
    justify-content: center;
    padding: 6px 20px;
  }

  .compose-panel,
  .preview-panel {
    min-height: auto;
  }

  .preview-panel {
    position: static;
  }

  .letter-form {
    grid-template-columns: 1fr;
  }

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

  .paper {
    min-height: 500px;
    padding: 28px 22px 36px;
  }

  .letter-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100% - 32px, 1180px);
    padding-top: 30px;
    padding-bottom: 64px;
  }

  body.auth-mode .app-shell {
    padding-top: 38px;
  }

  body.auth-mode .topbar {
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 26px;
  }

  body.auth-mode main {
    padding-top: 10px;
  }

  body.auth-mode .profile-box {
    width: 100%;
    margin-top: 0;
    margin-left: 0;
    justify-content: center;
    padding: 8px 14px;
  }


  .topbar {
    gap: 16px;
    margin-bottom: 22px;
  }

  .panel {
    padding: 22px;
    border-radius: 24px;
  }

  .profile-box {
    min-height: 48px;
    gap: 10px;
    padding: 8px 10px 8px 14px;
    border-radius: 20px;
  }

  .profile-box span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.auth-mode .profile-box span {
    flex: 0 0 auto;
    overflow: visible;
    text-overflow: clip;
  }

  .profile-box .ghost-btn {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 8px 12px;
    border-radius: 14px;
  }

  .tabs {
    gap: 8px;
    margin: -8px -4px 16px;
    padding: 8px 4px 12px;
  }

  .tab {
    padding: 12px 14px;
    border-radius: 15px;
  }

  .section-title {
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 20px;
  }

  .status-pill {
    padding: 7px 10px;
    font-size: 14px;
  }

  .letter-form {
    gap: 17px;
  }

  .auth-actions,
  .delay-row,
  .template-picker {
    grid-template-columns: 1fr;
  }

  input,
  textarea,
  select {
    border-radius: 15px;
    padding: 12px 14px;
  }

  .letter-form input,
  .letter-form select {
    min-height: 54px;
  }

  .saved-recipients {
    min-height: 38px;
  }

  .reply-context {
    padding: 14px;
  }

  .reply-context-header {
    flex-direction: column;
  }

  .reader-reply-context {
    padding: 14px;
  }

  .source-paper {
    max-height: 280px;
    padding: 20px 18px 24px;
  }

  .reply-paper {
    max-height: 190px;
    padding: 18px;
  }

  .reply-handwriting {
    font-size: 25px;
  }

  .locked-view {
    padding: 54px 8px 62px;
  }

  .lock-icon {
    width: 76px;
    height: 62px;
    font-size: 48px;
    margin-bottom: 18px;
  }

  .handwriting {
    font-size: 27px;
  }

  h1 {
    font-size: 50px;
  }

  h2 {
    font-size: 28px;
  }
}
