:root {
  color-scheme: light;
  --paper: #faf7f2;
  --surface: #fffdfa;
  --ink: #302722;
  --muted: #74695f;
  --line: #e4d9cc;
  --accent: #9a481e;
  --accent-hover: #7f3716;
  --tint: #f5e8da;
  --serif: 'Songti SC', 'Noto Serif SC', STSong, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font: 16px/1.5 var(--sans);
  background: #f0e9df;
  color: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; }
body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  padding: 16px;
}
.device-frame {
  position: relative;
  width: min(100%, 414px);
  height: min(891px, calc(100vh - 32px));
  height: min(891px, calc(100dvh - 32px));
  padding: 17px 11px 28px;
  border: 1px solid #685f57;
  border-radius: 42px;
  background: #312b27;
  box-shadow: inset 0 0 0 2px #403833, 0 16px 40px #4d38262e;
}
.device-frame::before,
.device-frame::after {
  position: absolute;
  left: 50%;
  display: block;
  border-radius: 999px;
  transform: translateX(-50%);
  pointer-events: none;
  content: '';
}
.device-frame::before { top: 7px; width: 46px; height: 4px; background: #7d7168; }
.device-frame::after { bottom: 11px; width: 100px; height: 4px; background: #c9beb2; }
.device-screen {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  scroll-padding-top: calc(max(1rem, env(safe-area-inset-top)) + 3.5rem);
  scrollbar-width: none;
  border-radius: 30px;
  background: var(--paper);
}
.device-screen::-webkit-scrollbar { display: none; }
button, textarea, input { font: inherit; }
button { color: inherit; cursor: pointer; }
button:focus-visible, textarea:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.device-screen:focus-visible { outline-offset: -2px; }
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
h1, h2 { font-family: var(--serif); }
h1 { font-size: 1.76rem; line-height: 1.22; }
h2 { font-size: 1.35rem; line-height: 1.3; }
.muted { color: var(--muted); }

.app-header {
  position: sticky;
  top: 0;
  z-index: 2;
  flex: none;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0 max(1rem, env(safe-area-inset-left));
  background: #f5f3ee;
}
.header-inner {
  min-height: 3.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  border-bottom: 1px solid #d7d1c5;
}
.brand { display: inline-flex; align-items: center; gap: .65rem; min-height: 2.75rem; padding: 0; border: 0; background: transparent; color: #242722; font-weight: 700; text-align: left; }
.brand-mark {
  position: relative;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: var(--tint);
}
.brand-mark::before, .brand-mark::after { content: ''; position: absolute; }
.brand-mark::before { inset: 7px 11px auto; height: 12px; border-radius: 50%; background: #d5874d; }
.brand-mark::after {
  inset: 15px 6px auto;
  height: 12px;
  border: 1px solid #83442e;
  border-radius: 3px 3px 5px 5px;
  background: linear-gradient(#fae9d8, #fae9d8) center 4px / 7px 2px no-repeat #985432;
}
.brand-name { white-space: nowrap; }
.header-leading { display: flex; align-items: center; gap: .2rem; }
.header-leading .header-leading-back { width: 44px; margin-inline-start: -.55rem; padding: 0; color: var(--muted); }
.header-leading-back span { width: .56rem; height: .56rem; border: solid currentColor; border-width: 0 0 2px 2px; transform: rotate(45deg); }
.header-actions { display: flex; align-items: center; gap: .25rem; }
.header-actions .button { padding-inline: .7rem; font-size: .875rem; }
.header-actions .header-tool { border: 0; color: var(--muted); }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 44px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-weight: 650;
  font-size: .9375rem;
  text-align: center;
  white-space: nowrap;
}
.button-primary { color: #fffdf8; background: var(--accent); }
.button-primary:hover { background: var(--accent-hover); }
.button-outline { color: var(--ink); border-color: var(--line); background: var(--surface); }
.button-outline:hover { border-color: #ba8d6e; background: #fbf0e4; }
.button-quiet { color: var(--accent); background: transparent; }
.button-quiet:hover { background: var(--tint); }

.screen { flex: 1 0 auto; padding: 22px max(16px, env(safe-area-inset-right)) max(30px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.screen:focus { outline: none; }
.compose-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
body:is([data-screen='templates'], [data-screen='editor']) .screen { background: #f5f3ee; }

.screen-top { margin-bottom: 17px; }
.screen-top .muted { margin-top: 3px; font-size: .875rem; }
.step-label { margin-bottom: 4px; color: var(--accent); font-size: .8125rem; font-weight: 650; }
.form-panel { display: grid; gap: 20px; min-width: 0; }
.sign-in-panel { max-width: 24rem; }
.sign-in-panel input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: var(--surface);
}
.save-button:disabled, .sign-in-panel button:disabled { opacity: .65; cursor: wait; }
.form-section { display: grid; gap: 8px; min-width: 0; border: 0; padding: 0; margin: 0; }
.form-section legend, .field-label { font-weight: 650; font-size: .9375rem; }
.form-section legend { padding: 0; margin-bottom: 7px; }
.form-section legend span, .field-label span { font-weight: 400; font-size: .875rem; margin-left: 5px; }
.field-note { color: var(--muted); font-size: .8125rem; }
.template-picker {
  display: grid;
  gap: 14px;
}
body[data-screen='templates'] .device-screen {
  scroll-padding-top: calc(max(1rem, env(safe-area-inset-top)) + 6.875rem);
}
.template-tabs {
  position: sticky;
  top: calc(max(1rem, env(safe-area-inset-top)) + 3.25rem);
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #efe9e0;
}
.template-tab {
  min-height: 44px;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: .875rem;
  font-weight: 650;
}
.template-tab[aria-selected="true"] {
  border-color: var(--line);
  background: var(--surface);
  color: var(--accent-hover);
}
.template-tab:focus-visible { outline-offset: 1px; }
.template-panel { min-width: 0; }
body[data-screen='templates'] .header-actions .button-primary:disabled { opacity: .45; cursor: default; }
.template-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.template-option {
  display: grid;
  align-content: start;
  justify-items: center;
  gap: 8px;
  min-width: 0;
  padding: 8px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  text-align: center;
}
.template-option:hover { background: var(--paper); }
.template-option[aria-disabled="true"] { cursor: not-allowed; }
.template-option[aria-pressed="true"] { border-color: #ac7657; background: var(--tint); color: var(--accent-hover); }
.template-option:focus-visible { outline-offset: 2px; }
.template-thumbnail { width: 100%; aspect-ratio: 3 / 4; border-radius: 4.8% / 3.6%; background: #efe9e0; }
.template-option .memory-card { pointer-events: none; box-shadow: 0 2px 6px #382a1c14; }
.template-option > span { font-size: .875rem; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.template-option[aria-pressed="true"] > span { font-weight: 700; }
.template-vip {
  display: inline-block;
  margin-inline-start: .35em;
  padding: .08em .34em;
  border-radius: 4px;
  background: #f4e5c9;
  color: #69451b;
  font-size: .7rem;
  font-weight: 700;
  vertical-align: .08em;
}
.media-picker { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.media-picker label { cursor: pointer; }
.compose-layout .media-picker .button-outline { color: var(--muted); background: transparent; }
.media-picker input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 4px; }
textarea { display: block; width: 100%; min-height: 110px; resize: vertical; padding: 12px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: var(--surface); }
textarea::placeholder { color: #82766b; }
.tag-options { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { color: var(--muted); background: #fbf6ed; border: 1px solid var(--line); padding: 7px 12px; min-height: 39px; border-radius: 999px; font-size: .875rem; }
.chip:hover { border-color: #ba8d6e; }
.chip[aria-pressed="true"] { color: #fffdf7; background: var(--accent); border-color: var(--accent); }
.form-error { color: #a32828; font-size: .9rem; }
.demo-note { color: var(--muted); font-size: .8125rem; text-align: center; }
.editor-preview {
  width: min(100%, 260px);
  width: min(100%, 260px, 42svh);
  justify-self: center;
}

.drawer-grid { display: grid; gap: 10px; }
.drawer-tile {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  text-align: left;
}
.drawer-tile:hover { border-color: #aa785b; background: #fff9f0; }
.drawer-tile .memory-card { pointer-events: none; box-shadow: 0 2px 9px #382a1c14; }
.drawer-summary { display: grid; gap: 6px; }
.drawer-summary strong { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; font-weight: 650; }
.drawer-metadata { color: var(--muted); font-size: .8125rem; }
.detail-card { width: min(100%, 340px); margin-inline: auto; }

.toast { position: absolute; z-index: 3; width: max-content; max-width: calc(100% - 52px); left: 50%; bottom: 43px; transform: translateX(-50%); border-radius: 999px; padding: 10px 16px; color: #fff8ec; background: #352a23; font-size: .9rem; text-align: center; box-shadow: 0 8px 28px #382a1c2b; pointer-events: none; }
.visually-hidden { width: 1px; height: 1px; position: absolute; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
.noscript { margin: 16px; }

@media (max-width: 450px) {
  body { padding: 8px; }
  .device-frame {
    height: min(880px, calc(100vh - 16px));
    height: min(880px, calc(100dvh - 16px));
    padding: 12px 6px 23px;
    border-radius: 34px;
  }
  .device-frame::before { top: 4px; height: 3px; }
  .device-frame::after { bottom: 8px; height: 3px; }
  .device-screen { border-radius: 26px; }
  .toast { max-width: calc(100% - 42px); bottom: 34px; }
}

@media (display-mode: standalone), (display-mode: fullscreen),
  (max-width: 358px), (max-width: 450px) and (hover: none) and (pointer: coarse) {
  body { padding: 0; }
  .device-frame {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .device-frame::before, .device-frame::after { display: none; }
  .device-screen { border-radius: 0; }
  .toast { max-width: calc(100% - 30px); bottom: max(16px, env(safe-area-inset-bottom)); }
}

@media (max-width: 355px) {
  .button { padding-inline: 10px; }
  .header-inner { gap: 6px; }
}
