@font-face { font-family: "Spectral"; src: url("/lifecalendar/fonts/Spectral-Regular.ttf") format("truetype"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Spectral"; src: url("/lifecalendar/fonts/Spectral-Italic.ttf") format("truetype"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Spectral"; src: url("/lifecalendar/fonts/Spectral-SemiBold.ttf") format("truetype"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "BeVietnamPro"; src: url("/lifecalendar/fonts/BeVietnamPro-Medium.ttf") format("truetype"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "GreatVibes"; src: url("/lifecalendar/fonts/GreatVibes-Regular.ttf") format("truetype"); font-weight: 400; font-style: normal; font-display: swap; }

:root {
  --bg: #f5f3ee;
  --card: #ffffff;
  --line: #ebe6dc;
  --line-strong: #dcd5c8;
  --text: #1c1917;
  --muted: #8a827a;
  --soft: #f3f0ea;
  --accent: #1c1917;
  --focus: #c2410c;
  --radius: 8px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --serif: "Spectral", Georgia, "Times New Roman", serif;
  --top: 56px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
button, input, select, textarea { font: inherit; color: inherit; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--top);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-right));
  background: rgba(245, 243, 238, .9);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand img { border-radius: 7px; }
.brand strong { font: 600 18px/1 var(--serif); letter-spacing: .01em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--card); cursor: pointer; font-weight: 600; font-size: 13.5px;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #3a3530; }
.btn-wide { width: 100%; min-height: 46px; }
.link-btn { background: none; border: 0; padding: 2px 0; color: var(--muted); cursor: pointer; font-size: 12px; text-decoration: underline; text-underline-offset: 2px; }
.link-btn:hover { color: var(--text); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 32px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 12px 24px 40px;
  align-items: start;
}

/* Preview */
.stage { position: sticky; top: calc(var(--top) + 12px); }
.viewport {
  position: relative;
  height: calc(100vh - var(--top) - 54px);
  min-height: 360px;
  overflow: auto;
  display: flex;
  border-radius: 12px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.viewport.zoomed { cursor: grab; background: rgba(0, 0, 0, .025); }
.paper {
  margin: auto; flex: none;
  background: #fff;
  box-shadow: 0 1px 2px rgba(28, 25, 23, .06), 0 14px 36px -10px rgba(28, 25, 23, .22);
  opacity: 0; transition: opacity .25s;
}
body.ready .paper { opacity: 1; }
.paper svg { display: block; width: 100%; height: 100%; }
.paper .editable { cursor: text; }
.paper .editable:hover { opacity: .7; }

.zoom {
  position: absolute; right: 12px; bottom: 44px; z-index: 2;
  display: flex; align-items: center;
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  box-shadow: 0 4px 14px -6px rgba(28, 25, 23, .25);
  overflow: hidden;
}
.zoom button { border: 0; background: none; cursor: pointer; height: 32px; min-width: 34px; padding: 0 8px; font-size: 16px; color: var(--text); }
.zoom button:hover { background: var(--soft); }
.zoom #zoomPct { font-size: 11px; min-width: 46px; color: var(--muted); font-variant-numeric: tabular-nums; }

.meta {
  margin: 10px 0 0; text-align: center;
  color: var(--muted); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase;
}
.meta .dot { margin: 0 8px; }
.hint { margin: 4px 0 0; text-align: center; color: var(--focus); font-size: 11px; }

/* Editor */
.editor { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.card h2 { margin: 0 0 -2px; font: 600 15px/1.2 var(--serif); letter-spacing: .01em; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 11px; font-weight: 500; color: var(--muted); display: flex; justify-content: space-between; letter-spacing: .02em; }
.field output { font-variant-numeric: tabular-nums; }
input[type=text], input[type=date], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 11px;
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: #fff;
  font-size: 16px; /* 16px stops iOS zooming into the field */
}
input[type=date] { min-width: 0; -webkit-appearance: none; appearance: none; }
textarea { resize: vertical; line-height: 1.4; }
input::placeholder, textarea::placeholder { color: #b6aea4; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, summary:focus-visible,
.seg input:focus-visible + b, .swatch:focus-visible, .chip:focus-visible, .zoom button:focus-visible, .link-btn:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 2px;
}
.flash { animation: flash 1s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 4px rgba(194, 65, 12, .3); } 100% { box-shadow: 0 0 0 0 rgba(194, 65, 12, 0); } }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.note { margin: -4px 0 0; font-size: 11px; color: var(--muted); line-height: 1.4; }
code { font: 10.5px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--soft); padding: 1px 4px; border-radius: 4px; }

input[type=range] { width: 100%; accent-color: var(--accent); height: 40px; margin: 0; }

/* Collapsible extras */
.more { margin-top: -2px; }
.more > summary {
  list-style: none; cursor: pointer; user-select: none; width: max-content;
  font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px;
}
.more > summary::-webkit-details-marker { display: none; }
.more > summary::after { content: ""; width: 5px; height: 5px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg) translateY(-2px); transition: transform .15s; }
.more[open] > summary::after { transform: rotate(-135deg) translateY(-1px); }
.more > summary:hover { color: var(--text); }
.more-body { display: flex; flex-direction: column; gap: 12px; padding-top: 12px; }

/* Segmented controls */
.seg { display: flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; background: #fff; }
.seg label { flex: 1; position: relative; min-width: 0; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg b { display: grid; place-items: center; min-height: 38px; padding: 0 6px; font-weight: 500; font-size: 13px; border-left: 1px solid var(--line); text-align: center; }
.seg label:first-child b { border-left: 0; }
.seg input:checked + b { background: var(--accent); color: #fff; }
.seg .caps { letter-spacing: .1em; font-size: 11px; text-transform: uppercase; }
.ic { display: block; width: 12px; height: 12px; background: currentColor; }
.ic.rounded { border-radius: 3px; }
.ic.circle { border-radius: 50%; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -4px; }
.chip { border: 1px solid var(--line); background: var(--soft); border-radius: 999px; padding: 3px 10px; font-size: 11.5px; color: #57514b; cursor: pointer; }
.chip:hover { border-color: var(--line-strong); color: var(--text); }

.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.swatch { border: 0; background: none; padding: 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.sw-paper { width: 100%; aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--line-strong); display: flex; align-items: center; justify-content: center; gap: 3px; }
.sw-paper i { width: 7px; height: 7px; border-radius: 2px; display: block; }
.sw-label { font-size: 10px; color: var(--muted); }
.swatch[aria-pressed=true] .sw-paper { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch[aria-pressed=true] .sw-label { color: var(--text); }

.colors { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.colors label { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10px; color: var(--muted); cursor: pointer; }
input[type=color] { width: 100%; height: 32px; padding: 2px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: #fff; cursor: pointer; }

.toggles { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.toggles label { display: flex; align-items: center; gap: 8px; cursor: pointer; min-height: 26px; }
.toggles input { width: 16px; height: 16px; accent-color: var(--accent); flex: none; margin: 0; }

.actions { display: flex; flex-direction: column; gap: 8px; padding: 4px 0 0; }
.status { margin: 0; font-size: 12px; color: #b91c1c; text-align: center; }
.status:empty { display: none; }
.sublinks { margin: 2px 0 0; display: flex; justify-content: center; align-items: center; gap: 8px; color: var(--line-strong); font-size: 12px; }

.foot { color: var(--muted); font-size: 10.5px; text-align: center; padding: 6px 0 24px; }
.foot p { margin: 3px 0; }
.foot a { color: inherit; }

/* Tablet and phone: preview on top, editor below */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 12px 16px 32px; }
  .stage { position: relative; top: 0; }
  .viewport { height: min(72vh, calc((100vw - 32px) * 1.414 + 40px)); min-height: 0; }
}
@media (max-width: 480px) {
  .topbar .btn span { display: none; }
  .topbar .btn { padding: 0 12px; }
  .swatches { gap: 6px; }
  .sw-label { font-size: 9px; }
}

/* Advanced options card */
.advanced { padding: 0; gap: 0; }
.advanced > summary { list-style: none; cursor: pointer; user-select: none; padding: 16px; display: flex; align-items: center; }
.advanced > summary::-webkit-details-marker { display: none; }
.advanced > summary h2 { margin: 0; font: 600 15px/1.2 var(--serif); color: var(--muted); }
.advanced > summary::after { content: ""; margin-left: auto; width: 6px; height: 6px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg) translateY(-2px); transition: transform .15s; }
.advanced[open] > summary::after { transform: rotate(-135deg); }
.advanced[open] > summary h2, .advanced > summary:hover h2 { color: var(--text); }
.adv-body { display: flex; flex-direction: column; gap: 12px; padding: 0 16px 16px; }
.adv-body h3.first { border-top: 0; padding-top: 0; margin-top: 0; }
.adv-body h3 { margin: 8px 0 -4px; font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); border-top: 1px solid var(--line); padding-top: 14px; }

/* Page footer */
.site-foot { border-top: 1px solid var(--line); margin-top: 8px; padding: 28px 16px 36px; color: var(--muted); font-size: 11px; }
.site-foot-inner { max-width: 1320px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.site-foot p { margin: 0; }
.foot-brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font: 600 13px/1 var(--serif); margin-bottom: 6px; }
.foot-brand img { border-radius: 5px; }
.site-foot .copy { margin-top: 6px; }
.print-tip { margin: 0; text-align: center; font-size: 11px; color: var(--muted); }
.print-tip b { color: var(--text); font-weight: 600; }

/* Phones: keep a smaller preview pinned at the top while editing below it */
@media (max-width: 900px) {
  .stage { position: sticky; top: var(--top); z-index: 10; background: var(--bg); padding: 8px 0 6px; margin: -12px -16px 0; padding-left: 16px; padding-right: 16px; border-bottom: 1px solid var(--line); }
  .viewport { height: 40vh; min-height: 0; }
  .zoom { bottom: 34px; right: 22px; }
  .meta { margin-top: 6px; }
  .hint { display: none; }
}

/* Optional tip card, shown after a download */
.tip {
  position: fixed; z-index: 50; right: 20px; bottom: 20px; width: min(340px, calc(100vw - 32px));
  background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 18px 18px 16px;
  box-shadow: 0 20px 50px -12px rgba(28, 25, 23, .35);
  opacity: 0; transform: translateY(12px); transition: opacity .25s, transform .25s;
}
.tip.show { opacity: 1; transform: none; }
.tip-title { margin: 0 24px 4px 0; font: 600 15px/1.3 var(--serif); }
.tip-text { margin: 0 0 14px; font-size: 13px; color: #57514b; line-height: 1.45; }
.tip-actions { display: flex; gap: 8px; }
.tip-actions .btn { flex: 1; text-decoration: none; }
.tip-close { position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border: 0; background: none; font-size: 20px; color: var(--muted); cursor: pointer; border-radius: 6px; }
.tip-close:hover { background: var(--soft); }
@media (max-width: 480px) { .tip { right: 16px; left: 16px; bottom: 16px; width: auto; } }
