:root {
  --ink: #3a3040;
  --soft: #8d8494;
  --line: rgba(58, 48, 64, 0.1);
  --accent: #ff7f97;
  --font: ui-rounded, "SF Pro Rounded", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #fff; color: var(--ink); font-family: var(--font); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
[hidden] { display: none !important; }

#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.chrome { transition: opacity 0.35s, transform 0.35s; }
body.reading .chrome, body.gated .chrome { opacity: 0; pointer-events: none; }

#top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(14px + env(safe-area-inset-top)) 18px 0;
  pointer-events: none;
}
#top > * { pointer-events: auto; }
.brand { font-size: 19px; font-weight: 700; letter-spacing: 0.18em; }
.top-right { display: flex; gap: 8px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 18px; font-size: 14px;
  background: rgba(255, 255, 255, 0.86); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 1px 2px rgba(58, 48, 64, 0.08), 0 6px 20px rgba(58, 48, 64, 0.08);
}
.pill b { font-weight: 600; color: var(--soft); font-size: 13px; }
.pill:active { transform: scale(0.96); }

.menu {
  position: fixed; top: calc(58px + env(safe-area-inset-top)); right: 18px; z-index: 30;
  display: flex; flex-direction: column; min-width: 150px; padding: 6px; border-radius: 16px;
  background: #fff; box-shadow: 0 2px 6px rgba(58, 48, 64, 0.1), 0 16px 40px rgba(58, 48, 64, 0.16);
}
.menu button { text-align: left; padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.menu button:hover { background: #f6f3f7; }

#fab {
  position: fixed; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom)); z-index: 5;
  transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 8px;
  height: 50px; padding: 0 24px 0 20px; border-radius: 25px;
  background: var(--ink); color: #fff; font-size: 16px; font-weight: 600; letter-spacing: 0.04em;
  box-shadow: 0 10px 30px rgba(58, 48, 64, 0.28);
}
#fab:active { transform: translateX(-50%) scale(0.96); }
#hint {
  position: fixed; left: 0; right: 0; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 4;
  text-align: center; font-size: 13px; color: var(--soft); pointer-events: none;
  opacity: 0; transition: opacity 0.4s;
}
#hint.show { opacity: 1; }

/* ------------------------------------------------ open note */
#noteUI { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#noteUI > * { pointer-events: auto; }
#noteMeta {
  position: absolute; top: calc(18px + env(safe-area-inset-top)); left: 0; right: 0;
  text-align: center; font-size: 13px; color: var(--soft); pointer-events: none;
  opacity: 0; transition: opacity 0.4s;
}
#noteCancel {
  position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 14px;
  width: 38px; height: 38px; border-radius: 19px; display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.9); box-shadow: 0 1px 2px rgba(58, 48, 64, 0.08), 0 6px 20px rgba(58, 48, 64, 0.1);
  opacity: 0; transition: opacity 0.4s;
}
#noteUI.on #noteMeta, #noteUI.on #noteCancel { opacity: 1; }

#textWrap {
  position: absolute; display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden;
}
#textWrap.on { opacity: 1; visibility: visible; }
#text {
  width: 100%; max-height: 100%; padding: 0; margin: 0; border: 0; outline: 0; resize: none;
  background: transparent; color: rgb(58, 48, 64); caret-color: var(--accent);
  text-align: center; line-height: 1.5; overflow-y: auto; font-family: var(--font);
  scrollbar-width: none;
}
#text::-webkit-scrollbar { display: none; }
#text::placeholder { color: rgba(58, 48, 64, 0.32); }

#tools {
  position: absolute; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom));
  width: min(560px, calc(100vw - 20px));
  transform: translate(-50%, 130%); transition: transform 0.5s cubic-bezier(0.2, 0.9, 0.25, 1);
  background: rgba(255, 255, 255, 0.94); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-radius: 24px; padding: 10px 12px 12px;
  box-shadow: 0 2px 6px rgba(58, 48, 64, 0.08), 0 18px 50px rgba(58, 48, 64, 0.16);
}
#noteUI.on #tools { transform: translate(-50%, 0); }
.tabs { display: flex; gap: 4px; padding: 3px; border-radius: 14px; background: #f4f1f5; }
.tabs button { flex: 1; height: 32px; border-radius: 11px; font-size: 14px; color: var(--soft); white-space: nowrap; }
.tabs button.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(58, 48, 64, 0.12); }
.panel {
  display: flex; gap: 8px; align-items: center; height: 92px; padding: 8px 2px;
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
}
.panel::-webkit-scrollbar { display: none; }

.shape-btn {
  flex: 0 0 auto; width: 66px; height: 76px; border-radius: 16px; padding: 2px 0 0;
  display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--soft);
  border: 2px solid transparent;
}
.shape-btn img { width: 52px; height: 52px; display: block; }
.shape-btn.on { border-color: var(--ink); color: var(--ink); background: #faf8fb; }

.swatch {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(58, 48, 64, 0.1); position: relative;
}
.swatch.on::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2px solid var(--ink); }
.swatch.custom { background: conic-gradient(#ff8fa3, #ffe08a, #b8e0a5, #9cc9f5, #e0aaff, #ff8fa3); overflow: hidden; }
.swatch.custom.on { overflow: visible; }
.swatch.custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

#p-emoji { display: grid; grid-auto-flow: column; grid-template-rows: 38px 38px; gap: 0 2px; align-content: center; justify-content: start; }
.emo {
  width: 38px; height: 38px; border-radius: 12px; font-size: 24px; line-height: 38px; text-align: center;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}
.emo.on { background: #f1edf3; box-shadow: inset 0 0 0 2px var(--ink); }
#emojiCustom {
  grid-row: span 2; width: 76px; height: 72px; margin-right: 6px; border-radius: 14px; border: 1.5px dashed rgba(58, 48, 64, 0.25);
  text-align: center; font-size: 22px; outline: 0; background: transparent;
}
#emojiCustom::placeholder { font-size: 12px; color: var(--soft); }
#emojiNow { font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }

.actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding-top: 2px; }
.primary {
  height: 44px; padding: 0 28px; border-radius: 22px; background: var(--ink); color: #fff;
  font-weight: 600; font-size: 15px; letter-spacing: 0.06em;
}
.primary:active { transform: scale(0.97); }
.primary:disabled { opacity: 0.5; }
.ghost { height: 44px; padding: 0 16px; border-radius: 22px; font-size: 14px; color: var(--soft); }
.ghost.danger:hover { color: #e5484d; background: #fff0f0; }
.actions #noteDone { margin-left: auto; }

/* ------------------------------------------------ drawer */
#drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 20; width: min(380px, 100vw);
  background: rgba(255, 255, 255, 0.97); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: -10px 0 50px rgba(58, 48, 64, 0.14);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  animation: slideIn 0.35s cubic-bezier(0.2, 0.9, 0.25, 1);
}
@keyframes slideIn { from { transform: translateX(100%); } }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 18px 10px 22px; font-size: 17px; }
.drawer-head button { width: 36px; height: 36px; border-radius: 18px; display: grid; place-items: center; }
.drawer-head button:hover { background: #f4f1f5; }
#drawerList { flex: 1; overflow-y: auto; padding: 4px 12px calc(20px + env(safe-area-inset-bottom)); }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px; border-radius: 16px; text-align: left;
}
.row:hover { background: #f7f5f8; }
.row .dot { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; font-size: 20px;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }
.row .body { min-width: 0; flex: 1; }
.row .line { font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .line.empty { color: var(--soft); }
.row .sub { font-size: 12px; color: var(--soft); margin-top: 2px; }
.row .new { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 4px; background: var(--accent); }
.drawer-empty { padding: 40px 20px; text-align: center; color: var(--soft); font-size: 14px; }
.drawer-sep { padding: 14px 10px 4px; font-size: 12px; color: var(--soft); }

/* ------------------------------------------------ gate */
#gate {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px;
  background: rgba(255, 255, 255, 0.72); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  transition: opacity 0.6s;
}
#gate.bye { opacity: 0; pointer-events: none; }
.card { width: min(320px, 100%); text-align: center; }
.logo { font-size: 34px; font-weight: 700; letter-spacing: 0.3em; margin-right: -0.3em; }
.sub { color: var(--soft); font-size: 14px; margin: 10px 0 22px; line-height: 1.6; }
.card form, #whoPick { display: flex; flex-direction: column; gap: 10px; }
.card input {
  height: 48px; border-radius: 24px; border: 1.5px solid var(--line); padding: 0 20px; text-align: center; font-size: 16px;
  outline: 0; background: #fff;
}
.card input:focus { border-color: var(--ink); }
.card .primary { height: 48px; border-radius: 24px; font-size: 16px; }
.err { min-height: 20px; color: #e5484d; font-size: 13px; margin: 12px 0 0; }

@media (max-width: 520px) {
  .pill span { display: none; }
  .panel { height: 88px; }
}
