:root {
  --scene-base: #1c211e;
  --deep-ink: #0b1311;
  --ivory: #f8f3e8;
  --gold: #e8c891;
  --writing-green: #6aeb91;
  --muted-copy: #c6c7b7;
  --control-surface: rgba(15, 27, 22, .62);
  --control-outline: rgba(243, 237, 216, .35);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ivory);
  background: var(--scene-base);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body, #app { width: 100%; height: 100%; margin: 0; overflow: hidden; }
button { font: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 2px solid #e9c685; outline-offset: 3px; }
.stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  touch-action: none;
  background: radial-gradient(ellipse at 50% 42%, #58625b 0%, #28342f 62%, #131c1a 100%);
}
.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: .28;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.7' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.16'/%3E%3C/svg%3E");
}
video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  opacity: 0;
  filter: saturate(.8) contrast(1.08);
  transition: opacity .6s ease;
}
.camera-on video { opacity: 1; }
.video-shade {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(7, 14, 13, .56), transparent 25%, transparent 70%, rgba(7, 14, 13, .66)),
    radial-gradient(ellipse at center, transparent 32%, rgba(7, 14, 13, .28) 100%);
}
.glyph-space {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  perspective: 1300px;
  transform-style: preserve-3d;
}
.glyph-depth, .glyph-face {
  grid-area: 1 / 1;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: clamp(270px, 57vmin, 790px);
  line-height: 1;
  font-weight: 600;
  user-select: none;
  transform: perspective(1300px) rotateX(8deg) rotateY(-7deg);
}
.glyph-depth {
  color: rgba(12, 21, 18, .16);
  -webkit-text-stroke: 12px rgba(10, 20, 18, .11);
  text-shadow: 7px 10px 1px rgba(4, 10, 8, .12), 14px 20px 16px rgba(4, 10, 8, .28);
  filter: blur(1.2px);
  translate: 8px 12px;
}
.glyph-face {
  color: rgba(244, 230, 194, .10);
  -webkit-text-stroke: 1.5px rgba(251, 237, 201, .39);
  text-shadow: -2px -3px 2px rgba(255, 248, 222, .25), 4px 6px 10px rgba(7, 16, 13, .42);
}
#ink, #live-ink, #overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
#live-ink { z-index: 4; }
#overlay { z-index: 5; }
.topbar, .side-rail, .bottom-bar {
  position: absolute;
  z-index: 6;
}
.topbar {
  top: 0;
  left: 0;
  right: 0;
  padding: max(24px, env(safe-area-inset-top)) 34px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  pointer-events: none;
}
.identity, .controls { display: flex; align-items: center; pointer-events: auto; }
.identity { gap: 12px; }
.brand-seal {
  width: 43px;
  height: 43px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(240, 207, 149, .65);
  color: #f0cf95;
  font: 25px "Noto Serif SC", serif;
  background: rgba(13, 23, 19, .47);
  box-shadow: inset 0 0 0 3px rgba(13, 23, 19, .4);
}
.identity h1 { margin: 0; font: 600 21px "Noto Serif SC", serif; letter-spacing: .16em; }
.identity p { margin: 3px 0 0; color: var(--muted-copy); font-size: 10px; letter-spacing: .19em; }
.controls { gap: 8px; }
.controls button, .bottom-actions button {
  min-height: 42px;
  padding: 0 17px;
  border: 1px solid var(--control-outline);
  border-radius: 100px;
  color: var(--ivory);
  background: var(--control-surface);
  backdrop-filter: blur(16px);
  transition: background .18s, border-color .18s, transform .18s;
}
.controls button:hover, .bottom-actions button:hover { background: rgba(45, 67, 53, .88); }
.controls button:active, .bottom-actions button:active { transform: scale(.97); }
.controls .primary, .intro .primary { color: var(--scene-base); background: var(--gold); border-color: var(--gold); font-weight: 700; }
.controls .primary:hover, .intro .primary:hover { background: #f2d8a9; }
.controls button:disabled { opacity: .6; cursor: wait; }
.side-rail { top: 50%; left: 34px; width: min(265px, 25vw); transform: translateY(-50%); pointer-events: none; }
.tool-guide { display: flex; flex-wrap: wrap; gap: 8px; }
.tool-guide span { padding: 9px 12px; border: 1px solid var(--control-outline); border-radius: 999px; background: var(--control-surface); font-size: 13px; font-weight: 600; }
.writing .tool-guide-brush { color: var(--writing-green); border-color: var(--writing-green); }
.erasing .tool-guide-eraser { color: #f4b9a8; border-color: #f4b9a8; }
.gesture-help { margin: 18px 2px 0; color: #f2ead8; font-size: 14px; line-height: 1.9; text-shadow: 0 2px 6px #07120d; }
.depth-meter { height: 3px; margin: 20px 2px 10px; background: rgba(255, 255, 255, .24); border-radius: 99px; overflow: hidden; }
.depth-meter span { display: block; width: 0; height: 100%; background: var(--gold); transition: width .1s linear; }
.live-state { color: var(--gold); font-size: 12px; letter-spacing: .05em; text-shadow: 0 2px 6px #07120d; }
.bottom-bar {
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 24px;
  padding: 0 34px max(26px, env(safe-area-inset-bottom));
  pointer-events: none;
}
.character-picker, .bottom-actions { display: flex; align-items: center; gap: 7px; pointer-events: auto; }
.character-picker button {
  width: 46px;
  height: 46px;
  border: 1px solid rgba(255, 244, 215, .3);
  border-radius: 9px;
  background: rgba(10, 21, 17, .6);
  color: #f1e9d5;
  font: 600 24px "Noto Serif SC", serif;
  backdrop-filter: blur(12px);
}
.character-picker button:hover, .character-picker button.selected { color: #1d281e; background: var(--gold); border-color: #f4d7a3; }
.bottom-actions button { min-height: 46px; font-size: 13px; }
.keepsake-button {
  flex: 0 0 auto;
  min-height: 68px;
  padding: 0 36px;
  border: 1px solid #f5d7a0;
  border-radius: 999px;
  background: var(--gold);
  color: #18271f;
  box-shadow: 0 10px 28px rgba(10, 19, 14, .42), inset 0 1px 0 rgba(255, 255, 255, .6);
  font: 700 20px "Noto Serif SC", "Songti SC", serif;
  letter-spacing: .08em;
  pointer-events: auto;
  transition: transform .18s ease, background .18s ease;
}
.keepsake-button:hover:not(:disabled) { background: #f2d8a9; transform: translateY(-2px); }
.keepsake-button:active:not(:disabled) { transform: translateY(1px); }
.keepsake-button:disabled { opacity: .55; cursor: not-allowed; }
[hidden] { display: none !important; }
.keepsake-dialog {
  width: min(980px, calc(100vw - 28px));
  height: min(860px, calc(100dvh - 28px));
  max-width: none;
  max-height: none;
  overflow: hidden;
  padding: 0;
  border: 1px solid rgba(243, 237, 216, .4);
  border-radius: 22px;
  background: #17251e;
  color: var(--ivory);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .58);
}
.keepsake-dialog::backdrop { background: rgba(4, 11, 8, .78); backdrop-filter: blur(10px); }
.keepsake-panel { display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto auto; gap: 12px; height: 100%; min-height: 0; padding: 20px; }
.keepsake-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.keepsake-heading h2 { margin: 0; font: 600 25px "Noto Serif SC", "Songti SC", serif; }
.keepsake-heading button, .keepsake-actions button, .keepsake-actions a {
  min-height: 44px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--control-outline);
  border-radius: 999px;
  background: var(--control-surface);
  color: var(--ivory);
  text-decoration: none;
}
.keepsake-heading button:hover, .keepsake-actions button:hover, .keepsake-actions a:hover { background: rgba(45, 67, 53, .88); }
.keepsake-actions a { background: var(--gold); color: var(--scene-base); font-weight: 700; }
.keepsake-actions a:hover { background: #f2d8a9; }
.keepsake-image { display: grid; place-items: center; min-height: 0; overflow: hidden; border-radius: 12px; background: #22352a; }
.keepsake-image canvas, .keepsake-image img { display: block; grid-area: 1 / 1; max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; aspect-ratio: 8 / 5; }
#keepsake-status { margin: 0; color: var(--muted-copy); font-size: 13px; line-height: 1.4; }
.keepsake-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.keepsake-actions .keepsake-capture { min-width: 180px; background: var(--gold); color: var(--scene-base); font-weight: 700; }
.keepsake-actions .keepsake-share-primary { background: var(--gold); color: var(--scene-base); font-weight: 700; }
.keepsake-actions .keepsake-share-primary:hover { background: #f2d8a9; }
.keepsake-social { min-height: 0; border-top: 1px solid var(--control-outline); padding-top: 10px; }
.keepsake-social h3 { margin: 0; font-size: 15px; }
.keepsake-social p { margin: 5px 0 8px; color: var(--muted-copy); font-size: 12px; line-height: 1.35; }
.keepsake-links { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.keepsake-links button {
  min-height: 44px;
  padding: 4px 5px;
  border: 1px solid var(--control-outline);
  border-radius: 10px;
  background: rgba(239, 231, 213, .08);
  color: var(--ivory);
  font-size: 13px;
  text-align: center;
}
.keepsake-links button:hover { background: rgba(232, 200, 145, .19); border-color: var(--gold); }
.keepsake-links button:disabled { opacity: .6; cursor: wait; }
.intro {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: 8vw 0 8vw max(9vw, 32px);
  background: linear-gradient(90deg, rgba(8, 19, 15, .92) 0%, rgba(8, 19, 15, .78) 40%, rgba(8, 19, 15, .08) 100%);
}
#intro-content, .camera-question { max-width: min(680px, 100%); }
.intro .eyebrow { margin: 0 0 20px; font-size: 13px; letter-spacing: .32em; color: var(--gold); }
.intro h2 { margin: 0; font: 600 clamp(48px, 6vw, 100px)/1.32 "Noto Serif SC", serif; letter-spacing: .07em; }
#intro-content > p:not(.eyebrow), .camera-question > p:not(.eyebrow) { max-width: 470px; margin: 25px 0 29px; color: #e5e3d8; font-size: 17px; line-height: 1.8; }
.intro .primary { min-height: 54px; padding: 0 25px; border-radius: 999px; font-size: 15px; }
.intro small { display: block; margin-top: 17px; color: #c5c6b8; font-size: 12px; }
.camera-question h2 { font-size: clamp(36px, 4.8vw, 66px); }
.question-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.question-actions button:not(.primary) {
  min-height: 54px;
  padding: 0 25px;
  border: 1px solid var(--control-outline);
  border-radius: 999px;
  color: var(--ivory);
  background: var(--control-surface);
}
.question-actions button:not(.primary):hover { background: rgba(45, 67, 53, .88); }
@media (min-width: 761px) and (max-width: 1050px) {
  .bottom-bar { gap: 10px; padding-inline: 18px; }
  .character-picker button { width: 40px; height: 40px; font-size: 21px; }
  .bottom-actions { flex-direction: column; gap: 4px; }
  .bottom-actions button { min-height: 34px; padding-inline: 9px; font-size: 11px; }
  .keepsake-button { min-height: 58px; padding-inline: 20px; font-size: 16px; }
}
@media (max-width: 760px) {
  .topbar { padding: max(15px, env(safe-area-inset-top)) 15px 0; }
  .brand-seal { width: 36px; height: 36px; font-size: 21px; }
  .identity h1 { font-size: 16px; }
  .identity p { display: none; }
  .controls button { padding: 0 12px; min-height: 38px; font-size: 12px; }
  .side-rail { top: auto; bottom: 175px; left: 15px; right: 15px; width: auto; transform: none; }
  .tool-guide span { padding: 6px 9px; font-size: 11px; }
  .gesture-help { max-width: 320px; margin-top: 8px; font-size: 11px; line-height: 1.5; }
  .depth-meter { max-width: 290px; margin: 10px 0 5px; }
  .live-state { font-size: 11px; }
  .bottom-bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "keepsake keepsake" "picker actions"; align-items: end; padding: 0 12px max(13px, env(safe-area-inset-bottom)); gap: 8px; }
  .character-picker { grid-area: picker; gap: 3px; flex-wrap: wrap; max-width: none; }
  .character-picker button { width: 37px; height: 37px; font-size: 20px; }
  .keepsake-button { grid-area: keepsake; width: 100%; min-height: 54px; font-size: 17px; }
  .bottom-actions { grid-area: actions; flex-direction: column; gap: 4px; }
  .bottom-actions button { min-height: 34px; padding: 0 9px; font-size: 11px; }
  .keepsake-dialog { width: 100vw; height: 100dvh; border: 0; border-radius: 0; }
  .keepsake-panel { padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom)); gap: 7px; }
  .keepsake-heading h2 { font-size: 20px; }
  .keepsake-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .keepsake-actions button, .keepsake-actions a { padding-inline: 6px; font-size: 12px; }
  .keepsake-actions .keepsake-capture { grid-column: 1 / -1; min-width: 0; }
  .keepsake-actions .keepsake-share-primary { grid-column: 1 / -1; }
  .keepsake-social p { font-size: 11px; }
  .keepsake-links button { font-size: 11px; padding-inline: 2px; }
  .intro { padding: 110px 28px 70px; justify-content: center; }
  .intro h2 { font-size: clamp(42px, 10vw, 66px); }
  #intro-content > p:not(.eyebrow), .camera-question > p:not(.eyebrow) { font-size: 14px; }
  .intro small { max-width: 270px; line-height: 1.7; }
}
@media (max-height: 620px) and (min-width: 761px) {
  .side-rail { top: 48%; }
  .bottom-bar { padding-bottom: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}
