/* ---------- Tokens: an all-white, quiet palette ---------- */
:root {
  --bg: #FFFFFF;
  --ink: #1B2029;
  --muted: #8B929C;
  --soft: #B9BFC7;
  --faint: #F4F5F7;
  --line: #E9ECEF;
  --accent: #2E7D6F;
  --danger: #C0392B;
  --backdrop: rgba(20, 24, 30, 0.22);
  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: inherit; }
html { height: 100%; background: var(--bg); scroll-padding-top: env(safe-area-inset-top, 0px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Figtree", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body.locked { overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 max(20px, env(safe-area-inset-right, 0px)) 120px max(20px, env(safe-area-inset-left, 0px));
}

/* ---------- Header ---------- */
.top {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 5;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  padding: 12px 0 4px;
  background: rgba(255, 255, 255, 0.9);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
h1 { margin: 0; text-align: center; font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  display: grid; place-items: center;
  background: none; color: var(--ink);
}
.icon-btn:active { background: var(--faint); }
.icon-btn svg { width: 22px; height: 22px; }
.hint { margin: 2px 0 12px; text-align: center; font-size: 13px; color: var(--muted); }

/* ---------- Install hint ---------- */
.banner {
  position: relative;
  margin: 8px 0 18px;
  padding: 20px;
  border: 1px solid #DDE9E6;
  border-radius: 22px;
  background: #F2F8F6;
  text-align: left;
}
.banner[hidden] { display: none; }
.banner-head { display: flex; align-items: center; gap: 12px; padding-right: 24px; }
.banner-icon { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 13px; background: var(--accent); color: #fff; }
.banner-icon svg { width: 21px; height: 21px; }
.banner-title { margin: 0; font-size: 16px; font-weight: 600; color: var(--ink); }
.banner-copy { margin: 4px 0 0; font-size: 13px; line-height: 1.45; color: var(--muted); }
.install-steps { margin: 16px 0 0; padding: 0; list-style: none; counter-reset: install-step; }
.install-steps li { counter-increment: install-step; position: relative; min-height: 21px; padding: 1px 0 0 31px; font-size: 13px; line-height: 1.45; color: var(--ink); }
.install-steps li + li { margin-top: 9px; }
.install-steps li::before { content: counter(install-step); position: absolute; top: 0; left: 0; width: 21px; height: 21px; border-radius: 50%; display: grid; place-items: center; background: #DDECE8; color: var(--accent); font-size: 11px; font-weight: 600; }
.banner-qr { display: flex; align-items: center; gap: 16px; margin-top: 16px; }
.banner-qr[hidden] { display: none; }
.banner-qr img { flex: none; width: 112px; height: 112px; padding: 8px; border-radius: 14px; background: #fff; }
.banner-qr p { margin: 0; font-size: 13px; line-height: 1.5; color: var(--muted); }
.banner-qr strong { color: var(--ink); font-weight: 600; }
.banner .install { width: 100%; margin-top: 16px; border: 0; border-radius: 999px; padding: 11px 16px; font-weight: 600; font-size: 14px; background: var(--ink); color: #fff; }
.banner .install[hidden] { display: none; }
.banner .install:active { transform: scale(0.98); }
.banner .close { position: absolute; top: 8px; right: 8px; width: 36px; height: 36px; border: 0; background: none; font-size: 20px; color: var(--muted); }

/* ---------- List: centered emoji, name, value ---------- */
#list { list-style: none; margin: 0; padding: 0; }
#list li + li::before {
  content: "";
  display: block;
  width: 28px; height: 1px;
  margin: 0 auto;
  background: var(--line);
}
.row {
  display: flex; flex-direction: column; align-items: center;
  width: 100%;
  padding: 28px 12px;
  border: 0; border-radius: 22px;
  background: none;
  text-align: center;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  transition: background-color 0.2s;
}
.row:active { background: var(--faint); }
@media (hover: hover) { .row:hover { background: var(--faint); } }
.emoji { font-size: 32px; line-height: 1; }
.title { margin-top: 12px; font-size: 13px; font-weight: 500; color: var(--muted); transition: color 0.2s; }
.value {
  margin-top: 6px; max-width: 32ch;
  font-size: 18px; line-height: 1.45; font-weight: 500;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.value.empty { font-size: 15px; font-weight: 400; color: var(--soft); }
.value.masked { letter-spacing: 0.22em; color: var(--ink); }
.row.copied .title { color: var(--accent); }
.empty-state { margin: 80px 24px; text-align: center; color: var(--muted); line-height: 1.6; }
.empty-state[hidden] { display: none; }

/* ---------- Toast ---------- */
.toast-layer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 0 16px calc(28px + env(safe-area-inset-bottom, 0px));
  display: flex; justify-content: center;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 16px;
  padding: 11px 20px; border-radius: 999px;
  background: var(--ink); color: #fff;
  font-size: 14px; font-weight: 500;
  opacity: 0; transform: translateY(8px); visibility: hidden;
  transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
}
.toast.show { opacity: 1; transform: none; visibility: visible; pointer-events: auto; }
.toast button { border: 0; background: none; padding: 4px 0; font-weight: 600; color: #9FD6CC; }
.toast button[hidden] { display: none; }

/* ---------- Sheets ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: var(--backdrop);
  display: none; align-items: flex-end; justify-content: center;
}
.overlay.open { display: flex; }
.sheet {
  width: 100%; max-width: 480px; max-height: 92%;
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg);
  border-radius: 28px 28px 0 0;
  padding: 10px 22px calc(22px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 40px rgba(20, 24, 30, 0.08);
  animation: sheet-up 0.24s ease-out;
}
.sheet::before {
  content: ""; display: block;
  width: 36px; height: 4px; border-radius: 2px;
  margin: 0 auto 16px;
  background: var(--line);
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0.6; } }
@media (min-width: 600px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 28px; max-height: 85%; }
  .sheet::before { display: none; }
  .sheet { padding-top: 24px; }
}
.sheet h2 { margin: 0; text-align: center; font-size: 17px; font-weight: 600; }
.field-label { display: block; margin: 20px 0 8px; font-size: 13px; color: var(--muted); }
.section[hidden] { display: none; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 0; border-radius: 999px; padding: 8px 14px; font-size: 14px; background: var(--faint); }
.chip:active { background: var(--line); }

.input {
  width: 100%;
  border: 0; border-radius: 14px;
  padding: 13px 14px;
  background: var(--faint);
  font-size: 16px;
}
.input::placeholder { color: var(--soft); }
.emoji-input::placeholder { opacity: 0.35; }
.input:focus { outline: none; box-shadow: inset 0 0 0 1.5px var(--ink); }
.emoji-row { display: flex; gap: 10px; }
.emoji-row .emoji-input { width: 58px; flex: none; text-align: center; font-size: 24px; padding: 8px; }
textarea.input { min-height: 96px; resize: vertical; line-height: 1.45; }

.preset-group { border-bottom: 1px solid var(--line); }
.preset-group summary {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 2px;
  list-style: none;
  font-size: 15px; font-weight: 500;
  cursor: pointer;
  -webkit-user-select: none; user-select: none;
}
.preset-group summary::-webkit-details-marker { display: none; }
.preset-group summary .count { margin-left: auto; font-size: 13px; color: var(--soft); }
.preset-group summary::after {
  content: "";
  width: 7px; height: 7px; margin: 0 4px 3px 6px;
  border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.2s;
}
.preset-group[open] summary::after { transform: rotate(-135deg); margin-bottom: -3px; }
.preset-group .chips { padding: 0 0 16px; }

/* Hide-in-list switch */
.toggle {
  display: flex; align-items: center; gap: 14px;
  margin-top: 16px; padding: 14px 16px;
  border-radius: 16px; background: var(--faint);
  cursor: pointer;
}
.toggle-text { flex: 1; }
.toggle-text strong { display: block; font-size: 15px; font-weight: 600; }
.toggle-text small { display: block; margin-top: 2px; font-size: 13px; line-height: 1.4; color: var(--muted); }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch {
  position: relative; flex: none;
  width: 46px; height: 28px; border-radius: 14px;
  background: #D5D9DE;
  transition: background-color 0.2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(20, 24, 30, 0.2);
  transition: transform 0.2s;
}
.toggle input:checked + .switch { background: var(--ink); }
.toggle input:checked + .switch::after { transform: translateX(18px); }
.toggle input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 3px; }

.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 2px; }
.emoji-grid button { height: 44px; border: 0; border-radius: 12px; background: none; font-size: 22px; }
.emoji-grid button.selected { background: var(--faint); box-shadow: inset 0 0 0 1.5px var(--ink); }

.sheet-actions { display: flex; align-items: center; gap: 6px; margin-top: 26px; }
.spacer { flex: 1; }
.btn { border: 0; border-radius: 999px; padding: 12px 20px; font-size: 15px; font-weight: 600; background: none; }
.btn[hidden] { display: none; }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:disabled { opacity: 0.25; cursor: default; }
.btn.danger { color: var(--danger); padding-left: 4px; }
.btn.quiet { color: var(--muted); }

.menu-text { margin: 14px 0 6px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.55; }
.menu-item {
  display: block; width: 100%;
  margin-top: 10px; padding: 16px;
  border: 0; border-radius: 18px;
  background: var(--faint);
  text-align: center;
}
.menu-item:active { background: var(--line); }
.menu-item strong { display: block; font-size: 15px; font-weight: 600; }
.menu-item span { display: block; margin-top: 3px; font-size: 13px; color: var(--muted); }
.menu-text + .menu-item { margin-top: 14px; }

/* About */
.about-card { margin-top: 10px; padding: 16px; border-radius: 18px; background: var(--faint); }
.about-card h3 { margin: 0; font-size: 15px; font-weight: 600; }
.about-card p { margin: 6px 0 0; font-size: 13px; line-height: 1.55; color: var(--muted); }
.about-card .install-steps { margin-top: 12px; }
.about-card .install-steps li::before { background: var(--bg); }
.about-list { margin: 10px 0 0; padding-left: 18px; font-size: 13px; line-height: 1.55; color: var(--ink); }
.about-list li + li { margin-top: 6px; }
.about-install { width: 100%; margin-top: 14px; border: 0; border-radius: 999px; padding: 11px 16px; font-size: 14px; font-weight: 600; background: var(--ink); color: #fff; }
.about-install[hidden] { display: none; }
.about-links { display: flex; gap: 16px; }
.about-links a { font-weight: 600; color: var(--accent); text-decoration: none; }

/* Language switch */
.segmented { display: flex; gap: 4px; padding: 4px; border-radius: 16px; background: var(--faint); }
.segmented button { flex: 1; border: 0; border-radius: 12px; padding: 10px 12px; font-size: 15px; font-weight: 500; background: none; color: var(--muted); }
.segmented button[aria-checked="true"] { background: var(--bg); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(20, 24, 30, 0.1); }

@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; }
  .toast, .row, .title, .switch, .switch::after, .preset-group summary::after { transition: none; }
}
