:root {
  --bg-deep: #0b0907;
  --bg-surface: #171310;
  --text-ui: #dfd4c3;
  --text-muted: #8e806f;
  --border-subtle: rgba(245, 222, 190, 0.1);
  --fire-intensity: 0;

  --font-calligraphy: "Georgia", "Palatino Linotype", "Book Antiqua", "LXGW WenKai", "Kaiti SC", "STKaiti", "KaiTi", "Songti SC", "Noto Serif SC", serif;
  --font-serif: "Georgia", "Songti SC", "Noto Serif SC", "STSong", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;

  /* Iron-gall sepia ink on antique parchment */
  --parchment-ink: rgba(42, 24, 10, 0.90);
  --parchment-placeholder: rgba(74, 46, 22, 0.45);
  --parchment-meta: rgba(78, 48, 22, 0.58);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  overflow: hidden;
  background-color: var(--bg-deep);
  color: var(--text-ui);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  touch-action: none;
}

#hearth-glow {
  position: fixed;
  inset: -15%;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(
    circle at 50% 60%,
    rgba(255, 108, 24, 0.30) 0%,
    rgba(185, 58, 10, 0.13) 36%,
    rgba(11, 9, 7, 0) 70%
  );
  opacity: calc(0.16 + var(--fire-intensity) * 0.84);
  transition: opacity 100ms linear;
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(circle at 50% 46%, transparent 42%, rgba(4, 3, 2, 0.86) 100%);
}

#fx-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 30;
}

.app-shell {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;
  min-height: 100vh;
  height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top, 0px) + 12px)
    16px
    calc(env(safe-area-inset-bottom, 0px) + 12px);
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  color: var(--text-muted);
  text-decoration: none;
  border: 1px solid transparent;
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.home-link:hover {
  color: #f4e8d8;
  background: rgba(245, 228, 205, 0.06);
  border-color: var(--border-subtle);
}

.brand-ember {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffd180 0%, #ff6a00 70%, #b83300 100%);
  box-shadow: 0 0 10px rgba(255, 115, 20, 0.75);
}

.brand-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.08rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: #ede2d2;
}

.privacy-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(245, 224, 195, 0.05);
  border: 1px solid var(--border-subtle);
  font-size: 0.71rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 34px;
  min-width: 34px;
  padding: 0 9px;
  border-radius: 9px;
  border: 1px solid var(--border-subtle);
  background: rgba(245, 228, 205, 0.04);
  color: #cfc2b0;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.icon-btn:hover {
  background: rgba(245, 228, 205, 0.10);
  color: #fff6ea;
}

.icon-btn:active {
  transform: scale(0.95);
}

.lang-btn {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0 10px;
}

.install-btn {
  padding: 0 11px;
  font-size: 0.76rem;
  border-color: rgba(255, 145, 56, 0.28);
  color: #f3cba5;
}

.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: #c95214;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 17px;
  text-align: center;
}

/* Center Stage */
.stage {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 6px 0 8px;
}

.note-wrapper {
  position: relative;
  width: min(100%, 436px);
  height: min(100%, 484px);
  max-height: 57dvh;
  display: flex;
  align-items: stretch;
  justify-content: center;
  filter: drop-shadow(0 24px 42px rgba(0, 0, 0, 0.85)) drop-shadow(0 4px 10px rgba(0, 0, 0, 0.65));
}

.note-card {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: transparent;
  color: var(--parchment-ink);
  transform-origin: center bottom;
  transition:
    transform 0.45s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.25s ease;
}

.parchment-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.note-card.entering {
  animation: sheetDeal 0.52s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes sheetDeal {
  0% {
    opacity: 0;
    transform: translateY(20px) scale(0.975) rotate(-1.1deg);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0deg);
  }
}

.note-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 30px 6px;
  flex-shrink: 0;
}

.note-date {
  font-family: var(--font-calligraphy);
  font-size: 0.80rem;
  letter-spacing: 0.07em;
  color: var(--parchment-meta);
}

.note-body {
  position: relative;
  z-index: 2;
  flex: 1;
  min-height: 0;
  padding: 8px 30px 6px;
  display: flex;
}

.note-input {
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 0;
  margin: 0;
  background: transparent;
  color: var(--parchment-ink);
  font-family: var(--font-calligraphy);
  font-size: 1.12rem;
  line-height: 34px;
  letter-spacing: 0.02em;
  user-select: text;
  touch-action: pan-y;
  caret-color: #7c2a0c;
  overflow-y: auto;
  scrollbar-width: thin;
}

.note-input::placeholder {
  color: var(--parchment-placeholder);
}

.note-footer {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 30px 22px;
  min-height: 44px;
  flex-shrink: 0;
}

.char-info {
  font-family: var(--font-calligraphy);
  font-size: 0.76rem;
  color: var(--parchment-meta);
  letter-spacing: 0.03em;
}

.tuck-btn {
  padding: 2px 9px;
  border-radius: 3px;
  border: 1px solid rgba(92, 56, 24, 0.28);
  background: rgba(82, 48, 18, 0.06);
  color: var(--parchment-meta);
  font-family: var(--font-calligraphy);
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

.tuck-btn:hover {
  background: rgba(82, 48, 18, 0.14);
  color: var(--parchment-ink);
}

.burn-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 15;
  pointer-events: none;
}

/* Post-Burn Quiet Release View */
.after-burn {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  animation: fadeInSlow 0.9s ease forwards;
}

@keyframes fadeInSlow {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ash-emblem {
  width: 38px;
  height: 38px;
  margin-bottom: 18px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 132, 42, 0.25) 0%, rgba(255, 132, 42, 0) 70%);
  position: relative;
}

.ash-emblem::after {
  content: "";
  position: absolute;
  inset: 15px;
  border-radius: 50%;
  background: #d87a38;
  opacity: 0.65;
  box-shadow: 0 0 14px rgba(255, 120, 35, 0.6);
}

.release-quote {
  margin: 0 0 8px;
  font-family: var(--font-serif);
  font-size: 1.22rem;
  color: #ede2d2;
  letter-spacing: 0.03em;
}

.release-sub {
  margin: 0 0 26px;
  font-size: 0.81rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.new-note-btn {
  padding: 11px 26px;
  border-radius: 999px;
  border: 1px solid rgba(226, 188, 138, 0.26);
  background: rgba(226, 188, 138, 0.07);
  color: #f0e3d0;
  font-size: 0.90rem;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background 0.22s ease, border-color 0.22s ease, transform 0.15s ease;
}

.new-note-btn:hover {
  background: rgba(226, 188, 138, 0.14);
  border-color: rgba(255, 175, 105, 0.48);
}

.new-note-btn:active {
  transform: scale(0.97);
}

/* Bottom Matchbox + Striker Bench */
.bottom-dock {
  position: relative;
  z-index: 20;
  min-height: 112px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  flex-shrink: 0;
}

.match-station {
  width: min(100%, 436px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 11px;
}

.match-bench {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

/* Left: Half-open Vintage Matchbox */
.matchbox {
  position: relative;
  display: flex;
  align-items: center;
  width: 204px;
  height: 70px;
  cursor: grab;
  flex-shrink: 0;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.75));
  transition: transform 0.2s ease;
}

.matchbox.pulse-nudge {
  animation: boxNudge 0.36s ease;
}

@keyframes boxNudge {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  65% { transform: translateX(4px); }
}

.matchbox-sleeve {
  position: relative;
  z-index: 3;
  width: 66px;
  height: 70px;
  border-radius: 4px 2px 2px 4px;
  background: linear-gradient(160deg, #873221 0%, #632114 60%, #4a170d 100%);
  border: 1px solid rgba(218, 168, 112, 0.38);
  box-shadow:
    3px 0 10px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(255, 220, 175, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}

.sleeve-label {
  width: 100%;
  height: 100%;
  border: 1px solid rgba(230, 188, 128, 0.55);
  border-radius: 2px;
  background: radial-gradient(circle, #c8a472 0%, #a5804f 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 6px rgba(62, 32, 10, 0.45);
}

.sleeve-text {
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-family: var(--font-serif);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #461c0f;
}

.matchbox-tray {
  position: relative;
  z-index: 2;
  flex: 1;
  height: 62px;
  margin-left: -4px;
  border-radius: 0 4px 4px 0;
  background: linear-gradient(180deg, #9f784c 0%, #7c5934 100%);
  padding: 4px 5px 4px 0;
  box-shadow: inset 0 1px 0 rgba(255, 228, 190, 0.22);
}

.tray-inner {
  width: 100%;
  height: 100%;
  border-radius: 0 2px 2px 0;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.65) 0%, rgba(28, 18, 11, 0.92) 18%, #1d130c 100%);
  box-shadow:
    inset 0 3px 8px rgba(0, 0, 0, 0.82),
    inset -2px 0 5px rgba(0, 0, 0, 0.6);
}

/* Right: Dedicated Red-Phosphorus Striker Block */
.striker-box {
  position: relative;
  flex: 1;
  max-width: 196px;
  height: 62px;
  border-radius: 5px;
  background: #2b1c13;
  border: 1px solid rgba(196, 148, 94, 0.28);
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.72),
    inset 0 1px 0 rgba(255, 220, 175, 0.12);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 4px 6px;
  overflow: hidden;
}

.striker-wood-trim {
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, #6e4e30 0%, #a87e51 50%, #68492c 100%);
  opacity: 0.75;
}

.striker-strip {
  position: relative;
  flex: 1;
  margin: 2px 0;
  border-radius: 3px;
  background-color: #5b2118;
  background-image:
    radial-gradient(rgba(22, 6, 4, 0.72) 1px, transparent 0),
    radial-gradient(rgba(165, 72, 52, 0.42) 1px, transparent 0),
    repeating-linear-gradient(
      60deg,
      rgba(18, 5, 3, 0.22) 0px,
      rgba(18, 5, 3, 0.22) 2px,
      transparent 2px,
      transparent 6px
    ),
    repeating-linear-gradient(
      -60deg,
      rgba(18, 5, 3, 0.22) 0px,
      rgba(18, 5, 3, 0.22) 2px,
      transparent 2px,
      transparent 6px
    );
  background-size: 5px 5px, 7px 7px, 9px 9px, 9px 9px;
  background-position: 0 0, 2px 3px, 0 0, 0 0;
  box-shadow: inset 0 2px 7px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}

.striker-marks {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.striker-guide {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.striker-label-watermark {
  font-size: 0.64rem;
  letter-spacing: 0.18em;
  color: rgba(245, 198, 168, 0.26);
  font-weight: 600;
}

.match-hint {
  margin: 0;
  font-size: 0.77rem;
  color: #a99680;
  letter-spacing: 0.02em;
  text-align: center;
  min-height: 1.2em;
  transition: color 0.25s ease;
}

.match-hint.lit {
  color: #f0b27a;
}

/* Settings Modal */
.settings-backdrop {
  position: fixed;
  inset: 0;
  z-index: 46;
  background: rgba(5, 4, 3, 0.74);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.settings-card {
  width: min(100%, 380px);
  background: #181410;
  border: 1px solid rgba(235, 206, 170, 0.14);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.75);
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: fadeScaleIn 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes fadeScaleIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}

.setting-block {
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}

.setting-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.setting-label {
  font-size: 0.90rem;
  font-weight: 600;
  color: #ede2d2;
}

.setting-desc {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.switch-btn {
  position: relative;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid rgba(245, 214, 180, 0.18);
  background: rgba(255, 245, 230, 0.08);
  padding: 2px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.22s ease, border-color 0.22s ease;
}

.switch-btn[aria-checked="true"] {
  background: #c85619;
  border-color: rgba(255, 168, 96, 0.55);
}

.switch-thumb {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #f6ede2;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.switch-btn[aria-checked="true"] .switch-thumb {
  transform: translateX(20px);
}

.speed-segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  padding: 4px;
  border-radius: 11px;
  background: rgba(255, 244, 228, 0.04);
  border: 1px solid var(--border-subtle);
}

.speed-opt {
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #a99885;
  font-family: var(--font-sans);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

.speed-opt:hover {
  color: #ede2d2;
}

.speed-opt.active {
  background: rgba(210, 92, 26, 0.28);
  color: #ffdcb8;
  box-shadow: inset 0 0 0 1px rgba(255, 148, 66, 0.42);
}

/* Saved Unburned Slips Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(5, 4, 3, 0.76);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.drawer-sheet {
  width: min(100%, 500px);
  max-height: 74dvh;
  background: #181410;
  border: 1px solid rgba(235, 206, 170, 0.12);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(env(safe-area-inset-bottom, 0px) + 20px);
  display: flex;
  flex-direction: column;
  animation: slideUp 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.drawer-title {
  margin: 0 0 4px;
  font-family: var(--font-serif);
  font-size: 1.08rem;
  font-weight: 600;
  color: #efe3d2;
}

.drawer-subtitle {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.drawer-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0;
}

.drawer-empty {
  padding: 36px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.6;
}

.saved-slip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(235, 206, 168, 0.05);
  border: 1px solid var(--border-subtle);
}

.saved-slip-preview {
  flex: 1;
  min-width: 0;
}

.saved-slip-text {
  margin: 0 0 4px;
  font-family: var(--font-calligraphy);
  font-size: 0.94rem;
  color: #e4d6c3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.saved-slip-time {
  font-size: 0.71rem;
  color: var(--text-muted);
}

.saved-slip-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.slip-action-btn {
  padding: 5px 11px;
  border-radius: 6px;
  border: 1px solid rgba(255, 155, 75, 0.3);
  background: rgba(255, 120, 30, 0.1);
  color: #f6caa2;
  font-size: 0.76rem;
  cursor: pointer;
}

.slip-action-btn:hover {
  background: rgba(255, 120, 30, 0.2);
}

.drawer-footer {
  padding-top: 12px;
  margin-top: 8px;
  border-top: 1px solid var(--border-subtle);
  text-align: center;
}

.danger-text-btn {
  background: none;
  border: none;
  color: #d66838;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 6px 12px;
}

.danger-text-btn:hover {
  text-decoration: underline;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 128px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(28, 22, 18, 0.94);
  border: 1px solid rgba(245, 200, 150, 0.18);
  color: #eadcc9;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  white-space: nowrap;
}

@media (max-width: 440px) {
  .privacy-pill {
    display: none;
  }
  .match-bench {
    gap: 10px;
  }
  .matchbox {
    width: 178px;
    height: 64px;
  }
  .matchbox-sleeve {
    width: 56px;
    height: 64px;
  }
  .matchbox-tray {
    height: 56px;
  }
  .striker-box {
    height: 56px;
  }
}

@media (max-height: 700px) {
  .note-wrapper {
    max-height: 53dvh;
  }
  .bottom-dock {
    min-height: 98px;
  }
}
