@font-face {
  font-family: "Card Title Serif";
  src: url("./fonts/SourceHanSerifTW-Heavy.otf") format("opentype");
  font-weight: 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "GenWan Serif TW";
  src: url("./fonts/GenWanMin2TW-SB-base.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F, U+3000-303F, U+3100-312F, U+31A0-31BF, U+FF00-FFEF;
}
@font-face {
  font-family: "GenWan Serif TW";
  src: url("./fonts/GenWanMin2TW-SB-exta.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+3400-4DBF;
}
@font-face {
  font-family: "GenWan Serif TW";
  src: url("./fonts/GenWanMin2TW-SB-cjk-1.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+4E00-5FFF;
}
@font-face {
  font-family: "GenWan Serif TW";
  src: url("./fonts/GenWanMin2TW-SB-cjk-2.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+6000-7FFF;
}
@font-face {
  font-family: "GenWan Serif TW";
  src: url("./fonts/GenWanMin2TW-SB-cjk-3.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+8000-9FFF;
}
@font-face {
  font-family: "GenWan Serif TW";
  src: url("./fonts/GenWanMin2TW-SB-compat.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+F900-FAFF;
}

:root {
  --background: #f4efe7;
  --foreground: #35271e;
  --card: #fffdf8;
  --primary: #7b3f28;
  --primary-foreground: #fffaf3;
  --muted: #7d6a5c;
  --border: #ded0c1;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  color-scheme: light;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--foreground);
  background:
    radial-gradient(circle at 12% 8%, rgba(255,255,255,.72), transparent 31%),
    linear-gradient(125deg, rgba(123,63,40,.025), transparent 42%),
    var(--background);
}

button, input, textarea { font: inherit; }

.page-shell { min-height: 100vh; overflow: hidden; }

.page-inner {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 32px;
  display: flex;
  flex-direction: column;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(222,208,193,.75);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--primary-foreground);
  background: var(--primary);
  box-shadow: 0 2px 8px rgba(72,37,24,.16);
}
.brand-name, .brand-note, .eyebrow, .panel-kicker { margin: 0; }
.brand-name { font-size: 14px; font-weight: 700; letter-spacing: .08em; }
.brand-note { margin-top: 2px; color: var(--muted); font-size: 12px; }
.prototype-badge {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: var(--card);
  font-size: 12px;
}

.line-browser-notice[hidden] { display: none; }
.line-browser-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 20px;
  padding: 14px 16px;
  border: 1px solid rgba(123,63,40,.2);
  border-radius: 16px;
  color: #5c4032;
  background: #fff7ed;
  box-shadow: 0 8px 28px rgba(74,40,22,.07);
}
.line-browser-notice strong { font-size: 14px; }
.line-browser-notice p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.external-browser-button {
  flex: 0 0 auto;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 15px;
  border-radius: 11px;
  color: var(--primary-foreground);
  background: var(--primary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  transition: transform 140ms var(--ease-out), background-color 160ms ease;
}
.external-browser-button:active { transform: scale(.97); }

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0,1fr) 300px;
  align-items: center;
  gap: 40px;
  padding: 32px 0;
}

.headline { margin-bottom: 20px; }
.eyebrow { margin-bottom: 8px; color: #9a5838; font-size: 12px; font-weight: 700; letter-spacing: .18em; }
h1 {
  margin: 0;
  font-family: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  font-size: clamp(30px, 4vw, 40px);
  line-height: 1.15;
  letter-spacing: -.035em;
}

.stage-shell {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border: 1px solid rgba(222,208,193,.75);
  border-radius: 0;
  background: var(--card);
  box-shadow: 0 22px 65px rgba(74,40,22,.13);
}
.stage-shell::after {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  background: linear-gradient(180deg, rgba(255,255,255,.08), transparent 28%);
  mix-blend-mode: screen;
}
#stone-canvas { display: block; width: 100%; height: auto; }
.stage-status {
  position: absolute;
  right: 18px;
  bottom: 16px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border: 1px solid rgba(112,78,59,.15);
  border-radius: 999px;
  color: #6f5749;
  background: rgba(255,252,247,.82);
  backdrop-filter: blur(10px);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
}
.status-dot { width: 6px; height: 6px; border-radius: 999px; background: #8c7568; }
.status-dot.is-playing { background: #b45f3c; animation: status-pulse 1s linear infinite; }
@keyframes status-pulse { 0%,100% { opacity: .38; } 50% { opacity: 1; } }

.control-panel {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--card);
  box-shadow: 0 16px 45px rgba(74,40,22,.08);
}
.panel-kicker { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .16em; }
.control-panel h2 { margin: 8px 0 0; font-size: 20px; }
.panel-description { margin: 8px 0 0; color: var(--muted); font-size: 14px; line-height: 1.7; }
#message-form { margin-top: 24px; }
label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 600; }
input, textarea {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  border: 1px solid #d8c6b5;
  border-radius: 12px;
  outline: none;
  color: var(--foreground);
  background: var(--background);
  font-size: 18px;
  letter-spacing: .28em;
  transition: border-color 180ms var(--ease-out), box-shadow 180ms var(--ease-out);
}
input:focus, textarea:focus { border-color: #a86545; box-shadow: 0 0 0 3px rgba(168,101,69,.14); }
.input-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 8px; color: var(--muted); font-size: 12px; }
#input-feedback { margin: 6px 0 0; color: #a13f2b; font-size: 12px; line-height: 1.5; }
#input-feedback:empty { display: none; }
#facebook-steps { margin-top: 16px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; font-size: 13px; line-height: 1.6; }
#facebook-steps[hidden] { display: none; }
.save-image-options { margin-top: 14px; }
.save-image-options p { margin: 8px 2px 0; font-size: 12px; color: var(--muted); line-height: 1.6; }
#save-share-image[aria-disabled="true"] { pointer-events: none; opacity: .52; }
.font-switcher { min-width: 0; margin: 18px 0 0; padding: 0; border: 0; }
.font-switcher legend { margin-bottom: 8px; padding: 0; font-size: 13px; font-weight: 650; }
.font-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid #dac9b9;
  border-radius: 13px;
  background: #f3e9df;
}
.font-option { position: relative; margin: 0; cursor: pointer; }
.font-option input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.font-option span {
  min-height: 40px;
  display: grid;
  place-items: center;
  padding: 7px 10px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  transition: color 160ms ease, background-color 160ms ease, box-shadow 160ms ease, transform 120ms var(--ease-out);
}
.font-option input:checked + span { color: var(--primary); background: #fffaf4; box-shadow: 0 1px 4px rgba(74,40,22,.12); }
.font-option input:focus-visible + span { outline: 3px solid rgba(168,101,69,.2); outline-offset: 1px; }
.font-option:active span { transform: scale(.97); }
#font-description { margin: 7px 2px 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.button {
  width: 100%;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background-color 180ms var(--ease-out), color 180ms var(--ease-out), opacity 180ms var(--ease-out), transform 120ms var(--ease-out);
}
.button:active:not(:disabled) { transform: translateY(1px); }
.button:disabled { cursor: default; opacity: .52; }
.button-primary { height: 44px; margin-top: 20px; color: var(--primary-foreground); background: var(--primary); }
.button-ghost { height: 36px; margin-top: 8px; color: var(--muted); background: transparent; }
.button-share {
  height: 44px;
  margin-top: 8px;
  border: 1px solid rgba(123,63,40,.28);
  color: var(--primary);
  background: #fbf2e9;
}
.privacy-note { margin: 20px 0 0; padding-top: 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; line-height: 1.7; }

.share-dialog[hidden] { display: none; }
.share-dialog { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; }
.share-backdrop { position: absolute; inset: 0; border: 0; background: rgba(47,31,22,.46); backdrop-filter: blur(5px); }
.share-sheet {
  position: relative;
  width: min(620px,100%);
  max-height: min(760px,calc(100dvh - 48px));
  overflow: auto;
  padding: 24px;
  border: 1px solid rgba(222,208,193,.9);
  border-radius: 26px;
  outline: none;
  background: var(--card);
  box-shadow: 0 30px 90px rgba(44,25,14,.28);
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity 180ms var(--ease-out), transform 220ms var(--ease-out);
}
.share-dialog.is-entering .share-sheet { opacity: 0; transform: translateY(8px) scale(.98); }
.share-handle { display: none; }
.share-sheet-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.share-sheet-header h2 { margin: 7px 0 0; font-size: 22px; }
.icon-button {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  background: #f4ece3;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}
.share-preview { position: relative; overflow: hidden; min-height: 190px; margin-top: 20px; border-radius: 0; background: #efe5da; }
.share-preview img { display: block; width: 100%; height: auto; max-height: 55vh; object-fit: contain; }
.share-preview img:not([src]) { visibility: hidden; }
.share-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.share-loading[hidden] { display: none; }
.share-copy { margin: 15px 2px; color: #624a3c; font-size: 14px; line-height: 1.65; white-space: pre-line; }
.share-step { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border); }
.share-step-title { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font-size: 16px; }
.share-step-number { display: grid; place-items: center; flex: 0 0 28px; height: 28px; border-radius: 50%; background: #7b3f28; color: white; font-size: 14px; }
.copy-caption-action { width: 100%; justify-content: center; }
.share-step-note { margin: 10px 2px 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.share-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.share-option { position: relative; display: grid; grid-template-columns: minmax(0,1fr); }
.share-action {
  min-width: 0;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--foreground);
  background: #fffaf4;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  font-size: 13px;
  font-weight: 650;
  transition: transform 140ms var(--ease-out), border-color 160ms ease, background-color 160ms ease;
}
.share-action:active:not(:disabled), .icon-button:active { transform: scale(.97); }
.share-action:disabled { cursor: wait; opacity: .52; }
.platform-mark { flex: 0 0 auto; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 8px; color: white; background: #8a624d; font-size: 14px; font-weight: 800; }
.share-line .platform-mark { background: #06c755; }
.share-facebook .platform-mark { background: #1877f2; font-family: Arial,sans-serif; }
.share-threads .platform-mark { background: #171717; font-family: Arial,sans-serif; }
.share-threads[aria-disabled="true"] { pointer-events: none; opacity: .52; }
.share-instagram .platform-mark { background: linear-gradient(135deg,#833ab4,#fd1d1d,#fcb045); }
.share-copy-link .platform-mark { background: #8f7768; }
.mention-share-note { margin-top: 16px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.mention-share-note p { margin: 8px 0; }
#share-caption-status.is-error { color: #a12727; }
.share-feedback { min-height: 20px; margin: 12px 2px 0; color: var(--muted); font-size: 12px; }
.share-feedback.is-error { color: #a13f2b; }
body.has-dialog { overflow: hidden; }

@media (hover:hover) and (pointer:fine) {
  .button-primary:hover:not(:disabled) { background: #663420; }
  .button-ghost:hover:not(:disabled) { color: var(--foreground); background: #f1e7dc; }
  .button-share:hover:not(:disabled) { border-color: rgba(123,63,40,.55); background: #f6e6d8; }
  .external-browser-button:hover { background: #663420; }
  .share-action:hover:not(:disabled) { border-color: rgba(123,63,40,.38); background: #f9efe5; }
  .font-option:hover input:not(:checked) + span { color: var(--foreground); }
}

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; gap: 28px; }
  .control-panel { width: min(520px,100%); margin: 0 auto; }
}

@media (max-width: 640px) {
  .page-inner { padding: 24px 20px; }
  .prototype-badge { display: none; }
  .workspace { padding: 28px 0; }
  .stage-shell { border-radius: 0; }
  .stage-status { right: 10px; bottom: 10px; }
  .control-panel { padding: 20px; }
  .input-meta span:first-child { max-width: 75%; }
  .line-browser-notice { align-items: stretch; flex-direction: column; margin-top: 14px; }
  .external-browser-button { width: 100%; }
  .share-dialog { align-items: end; padding: 0; }
  .share-sheet {
    width: 100%;
    max-height: calc(100dvh - 18px);
    padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
    border-radius: 24px 24px 0 0;
  }
  .share-dialog.is-entering .share-sheet { transform: translateY(100%); }
  .share-handle { width: 38px; height: 4px; display: block; margin: 0 auto 14px; border-radius: 99px; background: #d7c8ba; }
  .share-preview { min-height: 150px; margin-top: 16px; }
  .share-options { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .status-dot.is-playing { animation: none; }
  .button, input, .font-option span, .share-sheet, .share-action, .icon-button, .external-browser-button { transition-duration: 0ms; }
}

.layout-tabs { display:flex; flex-wrap:wrap; gap:8px; margin-top:26px; }
.layout-tabs button { border:1px solid #d8c7b8; border-radius:999px; padding:12px 22px; background:#fff8ef; color:#674332; font:inherit; cursor:pointer; }
.layout-tabs button[aria-selected="true"] { background:#5a3526; border-color:#5a3526; color:#fff; }
.layout-tabs button:focus-visible { outline:3px solid #b4774e; outline-offset:3px; }
#portrait-options { margin-bottom:22px; }
#portrait-options[hidden] { display:none; }
#portrait-format { width:100%; padding:12px; border:1px solid #d8c7b8; border-radius:10px; background:#fffaf4; color:#543627; font:inherit; }


.platform-share-options { grid-template-columns: minmax(0,1fr) minmax(0,1fr); }
.share-option[hidden] { display: none; }
.facebook-share-option { grid-column: 1 / -1; }
.platform-share-action { justify-content: center; border: 0; border-radius: 999px; background: #171717; color: #fff; font-size: 16px; }
.platform-share-action[aria-disabled="true"] { opacity: .52; pointer-events: none; }
.share-utility-options { margin-top: 14px; }
@media (hover:hover) and (pointer:fine) { .share-action.platform-share-action:hover { background: #383838; } }

#message-input { min-height: 100px; height: auto; resize: vertical; line-height: 1.6; }

#recipient-feedback { color: #a13f2b; font-size: 12px; margin: 6px 0 16px; }
#recipient-input { letter-spacing: .06em; }

/* Input -> fullscreen snow scene -> finished card. */
body[data-flow="input"] .workspace { display: flex; flex-direction: column; align-items: center; }
body[data-flow="input"] .stage-shell,
body[data-flow="input"] #replay-button,
body[data-flow="input"] #share-button,
body[data-flow="input"] #edit-card { display: none; }
body[data-flow="input"] .control-panel { width: min(100%, 520px); }
body[data-flow="input"] .preview-column { width: min(100%, 640px); text-align: center; }
body.is-chocolate-animating { overflow: hidden; }
body[data-flow="result"] .stage-shell { animation: card-appear .55s ease-out; }
@keyframes card-appear { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { body[data-flow="result"] .stage-shell { animation: none; } }
