:root {
  --ink: #56443f;
  --charcoal: #56443f;
  --moss: #8b645a;
  --olive: #a47864;
  --sage: #bbaa91;
  --ivory: #f1f0e2;
  --stark: #e4c7b7;
  --khaki: #bbaa91;
  --gold: #a47864;
  --ginger: #8b645a;
  --peach: #e4c7b7;
  --petal: #c39d88;
  --paper: #fffaf0;
  --line: rgba(86, 68, 63, 0.16);
  --shadow: 0 18px 48px rgba(86, 68, 63, 0.16);
  color-scheme: light;
}

@font-face {
  font-family: "Sloop JE";
  src: url("./assets/sloop.ttf") format("truetype");
  font-display: swap;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  max-width: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 14% 8%, rgba(228, 199, 183, 0.44), transparent 30%),
    linear-gradient(180deg, rgba(241, 240, 226, 0.94), rgba(228, 199, 183, 0.32)),
    var(--ivory);
  color: var(--ink);
  font-family: ui-serif, "Songti TC", "Noto Serif TC", Georgia, serif;
}

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

.app-shell {
  width: 100%;
  max-width: 520px;
  min-height: 100vh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px max(22px, env(safe-area-inset-bottom));
  overflow: hidden;
}

.app-shell *,
.app-shell *::before,
.app-shell *::after {
  max-width: 100%;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 92px;
  padding: 18px 26px 20px;
  border: 1px solid rgba(241, 240, 226, 0.56);
  border-radius: 0 0 20px 20px;
  background: var(--moss);
  backdrop-filter: blur(14px);
  box-shadow: 0 16px 34px rgba(86, 68, 63, 0.2);
  overflow: hidden;
}

.brand-lockup {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
}

.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(255, 249, 238, 0.62);
  box-shadow: 0 10px 26px rgba(43, 38, 29, 0.28);
}

.kicker {
  margin: 0 0 2px;
  color: var(--ginger);
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
  line-height: 1.1;
}

h1 {
  font-size: 24px;
}

.topbar .kicker,
.topbar h1 {
  color: var(--paper);
}

.brand-title-wrap {
  display: flex;
  align-items: center;
  min-width: 0;
  transform: translateY(2px);
}

.app-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.app-title-row h1 {
  font-family: "Sloop JE", Georgia, "Times New Roman", serif;
  font-size: clamp(43px, 9vw, 68px);
  font-weight: 400;
  line-height: 0.8;
  white-space: nowrap;
}

.app-title-row span {
  display: inline-flex;
  align-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: rgba(255, 250, 240, 0.94);
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
  font-size: clamp(14px, 2.8vw, 20px);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

.brand-signature {
  display: grid;
  gap: 3px;
  min-width: 154px;
  color: rgba(255, 250, 240, 0.94);
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
  text-align: center;
  text-transform: uppercase;
}

.brand-signature strong {
  font-size: clamp(17px, 3.2vw, 26px);
  font-weight: 300;
  letter-spacing: 0.06em;
  line-height: 1;
}

.brand-signature span {
  font-size: clamp(10px, 1.5vw, 14px);
  font-weight: 300;
  letter-spacing: 0.22em;
  line-height: 1.1;
}

.brand-signature small {
  font-size: clamp(8px, 1.15vw, 11px);
  font-weight: 400;
  letter-spacing: 0.2em;
  line-height: 1.1;
}

h2 {
  font-size: 20px;
}

.ghost-icon {
  display: none;
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 30;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border: 1px solid rgba(255, 249, 238, 0.62);
  border-radius: 50%;
  background: rgba(139, 100, 90, 0.94);
  color: var(--paper);
  box-shadow: 0 14px 34px rgba(86, 68, 63, 0.22);
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
  font-size: 25px;
  line-height: 1;
  backdrop-filter: blur(12px);
}

.ghost-icon.is-visible {
  display: inline-flex;
}

.composer {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  width: 100%;
}

.photo-panel,
.form-panel,
.draft-card,
.learning-panel,
.access-panel {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.photo-panel {
  background: #e4c7b7;
}

.form-panel {
  background: var(--paper);
}

.access-panel {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding: 14px;
  background: rgba(255, 250, 240, 0.9);
}

.access-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.upload-zone {
  position: relative;
  display: grid;
  min-height: 220px;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background:
    radial-gradient(circle at 70% 20%, rgba(241, 240, 226, 0.54), transparent 26%),
    #e4c7b7;
}

.upload-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.gift-line {
  width: 72%;
  max-width: 280px;
  opacity: 0.26;
}

.preview-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upload-caption {
  position: absolute;
  bottom: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.upload-text {
  flex: 0 0 auto;
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(86, 68, 63, 0.92);
  color: var(--ivory);
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
  font-size: 13px;
  white-space: nowrap;
}

.image-note {
  flex: 1 1 auto;
  margin: 0;
  color: rgba(86, 68, 63, 0.78);
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
  font-size: 11px;
  line-height: 1.35;
}

.form-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span {
  color: rgba(33, 23, 19, 0.72);
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
  font-size: 12px;
  font-weight: 700;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
}

.compact-field {
  gap: 4px;
}

.compact-field span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.compact-field select {
  min-height: 40px;
  padding: 0 22px 0 8px;
  font-size: 13px;
  text-overflow: ellipsis;
}

.span-2 {
  grid-column: span 2;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(105, 104, 80, 0.26);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  outline: none;
}

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 12px;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(178, 144, 65, 0.16);
}

.split-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  min-width: 0;
}

.tone-row,
.feedback-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding-bottom: 2px;
}

.rewrite-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding-bottom: 2px;
}

.tone-pill,
.feedback-row button,
.rewrite-row button,
.text-button,
.copy-button {
  min-height: 38px;
  border: 1px solid rgba(105, 104, 80, 0.24);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.66);
  color: var(--moss);
  white-space: nowrap;
}

.tone-pill {
  min-width: 0;
}

.tone-pill.active,
.feedback-row button.selected {
  border-color: var(--olive);
  background: var(--olive);
  color: var(--paper);
}

.primary-action {
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  background: var(--charcoal, #303635);
  color: var(--paper);
  box-shadow: 0 12px 26px rgba(35, 38, 36, 0.24);
  font-weight: 700;
}

.secondary-action {
  min-height: 46px;
  border: 1px solid rgba(164, 120, 100, 0.34);
  border-radius: 8px;
  background: rgba(196, 157, 136, 0.14);
  color: var(--olive);
  font-weight: 700;
}

.analysis-panel {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid rgba(164, 120, 100, 0.28);
  border-radius: 8px;
  background: #e4c7b7;
  box-shadow: 0 12px 28px rgba(66, 57, 38, 0.11);
}

.analysis-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

#analysisSource,
#analysisProduct,
#analysisPlatform,
.analysis-columns strong,
.analysis-columns li {
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
}

#analysisSource {
  color: rgba(43, 38, 29, 0.58);
  font-size: 12px;
}

#analysisProduct,
#analysisPlatform {
  margin: 10px 0 0;
  color: rgba(43, 38, 29, 0.76);
  font-size: 13px;
  line-height: 1.55;
}

.analysis-columns {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.analysis-columns strong {
  color: var(--moss);
  font-size: 12px;
}

.analysis-columns ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.analysis-columns li {
  color: rgba(43, 38, 29, 0.74);
  font-size: 12px;
  line-height: 1.5;
}

.output-header,
.learning-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
  width: 100%;
}

.output-header {
  padding: 13px 14px;
  border: 1px solid rgba(164, 120, 100, 0.28);
  border-radius: 8px;
  background: #bbaa91;
  box-shadow: 0 12px 28px rgba(66, 57, 38, 0.11);
}

.ai-status {
  margin: 6px 0 0;
  color: rgba(43, 38, 29, 0.72);
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
  font-size: 12px;
  line-height: 1.45;
}

.ai-setup-panel {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 14px;
  border: 1px solid rgba(164, 120, 100, 0.24);
  border-radius: 8px;
  background: #f1f0e2;
  box-shadow: var(--shadow);
}

.text-button,
.copy-button {
  padding: 0 12px;
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
  font-size: 13px;
}

.draft-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
  width: 100%;
}

.draft-card {
  padding: 14px;
}

.draft-card:nth-child(3n + 1) {
  background: #f1f0e2;
}

.draft-card:nth-child(3n + 2) {
  background: #e4c7b7;
}

.draft-card:nth-child(3n + 3) {
  background: #bbaa91;
}

.draft-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.angle-label {
  color: var(--ginger);
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
  font-size: 12px;
  font-weight: 800;
}

.draft-copy {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-width: 100%;
  color: #2b1d17;
  color: var(--ink);
  font-family: ui-serif, "Songti TC", "Noto Serif TC", Georgia, serif;
  font-size: 15px;
  line-height: 1.72;
}

.feedback-row {
  margin-top: 14px;
}

.feedback-row button,
.rewrite-row button {
  padding: 0 12px;
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
  font-size: 12px;
}

.rewrite-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 8px;
}

.rewrite-row button {
  min-height: 34px;
  background: rgba(178, 144, 65, 0.12);
}

.revision-box {
  margin-top: 12px;
  border-top: 1px solid rgba(105, 104, 80, 0.18);
  padding-top: 10px;
}

.revision-box summary {
  cursor: pointer;
  color: rgba(43, 38, 29, 0.72);
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
  font-size: 12px;
  font-weight: 700;
}

.revision-input {
  margin-top: 10px;
  background: rgba(255, 255, 255, 0.76);
}

.save-revision-button {
  margin-top: 8px;
}

.learning-panel {
  display: block;
  padding: 14px;
  background: var(--charcoal, #303635);
  color: var(--paper);
}

.learning-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.learning-panel .kicker,
.learning-panel h2 {
  color: var(--paper);
}

#learningSummary {
  margin: 10px 0 0;
  color: rgba(255, 249, 238, 0.78);
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
  font-size: 13px;
  line-height: 1.55;
}

.learning-backstage {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

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

.learning-stat,
.learning-record {
  border: 1px solid rgba(255, 249, 238, 0.18);
  border-radius: 8px;
  background: rgba(255, 249, 238, 0.08);
}

.learning-stat {
  padding: 10px;
}

.learning-stat strong {
  display: block;
  color: var(--paper);
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
  font-size: 18px;
}

.learning-stat span,
.learning-record-meta,
.learning-record-copy {
  color: rgba(255, 249, 238, 0.72);
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
  font-size: 12px;
  line-height: 1.45;
}

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

.light-button {
  border-color: rgba(255, 249, 238, 0.34);
  background: rgba(255, 249, 238, 0.12);
  color: var(--paper);
}

.danger-button {
  border-color: rgba(246, 169, 173, 0.48);
  background: rgba(246, 169, 173, 0.14);
  color: #ffe7e8;
}

.learning-records {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  padding-right: 2px;
}

.learning-record {
  padding: 10px;
}

.learning-record-title {
  margin: 0 0 5px;
  color: var(--paper);
  font-family: ui-sans-serif, "Avenir Next", "PingFang TC", sans-serif;
  font-size: 13px;
  font-weight: 800;
}

.learning-record-copy {
  margin: 7px 0 0;
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

@media (max-width: 520px) {
  .topbar {
    gap: 8px;
    min-height: 82px;
    padding: 15px 14px 16px;
  }

  .app-title-row {
    gap: 5px;
  }

  .app-title-row h1 {
    font-size: clamp(31px, 9vw, 35px);
  }

  .app-title-row span {
    font-size: 10px;
  }

  .upload-caption {
    align-items: flex-end;
    gap: 7px;
  }

  .image-note {
    font-size: 10px;
    line-height: 1.3;
  }

  .brand-signature {
    gap: 2px;
    min-width: 98px;
  }

  .brand-signature strong {
    font-size: clamp(11px, 3.2vw, 13px);
    letter-spacing: 0.03em;
  }

  .brand-signature span {
    font-size: 9px;
    letter-spacing: 0.1em;
  }

  .brand-signature small {
    font-size: 8px;
    letter-spacing: 0.09em;
  }
}

@media (min-width: 760px) {
  .app-shell {
    max-width: 1180px;
  }

  .composer {
    grid-template-columns: minmax(320px, 0.86fr) 1fr;
    align-items: stretch;
  }

  .split-fields {
    grid-template-columns: 1fr 1fr;
  }

  .upload-zone {
    height: 100%;
    min-height: 514px;
  }

  .draft-list {
    grid-template-columns: repeat(3, 1fr);
  }

  .tone-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .feedback-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .rewrite-row {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .analysis-columns {
    grid-template-columns: 1fr 1fr;
  }

  .learning-stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
