:root {
  --navy: #2c2d44;
  --bg: #d9dee6;
  --accent: #d90429;
  --btn: #8d98ae;
  --ink: #ffffff;
  --soft: #e6e8ee;
  --panel: #c5ccd4;
  --scale: 1;
  --icon: 1;
  color-scheme: light;
}

html[data-size="sm"] { --scale: 0.88; --icon: 0.86; }
html[data-size="md"] { --scale: 1; --icon: 1; }
html[data-size="lg"] { --scale: 1.2; --icon: 1.22; }
html[data-color="rg"] { --accent: #0057b8; }
html[data-color="by"] { --accent: #d55e00; }
html[data-color="mono"] { --accent: #1c1c1c; }

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--navy);
  font-family: "Montserrat", "Noto Sans TC", "Noto Sans Devanagari", sans-serif;
  font-size: calc(16px * var(--scale));
  line-height: 1.35;
}

button, input, select, textarea { font: inherit; }

button { cursor: pointer; }

.app {
  width: min(480px, 100%);
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  container-type: inline-size;
}

.skip {
  position: absolute;
  left: 8px;
  top: -40px;
  background: white;
  color: var(--navy);
  padding: 8px 12px;
  z-index: 20;
  border-radius: 8px;
}

.skip:focus { top: 8px; }

.header {
  position: sticky;
  top: 0;
  z-index: 6;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 16px;
  background: var(--navy);
  color: white;
}

.logo {
  width: calc(62px * var(--icon));
  height: calc(62px * var(--icon));
  max-width: 78px;
  max-height: 78px;
  flex: 0 0 auto;
  color: var(--accent);
}

.logo svg, .mini-heart svg { width: 100%; height: 100%; display: block; }

.brand { flex: 1 1 160px; min-width: 0; }

.brand h1 {
  margin: 0;
  font-size: clamp(1.25rem, calc(1.55rem * var(--scale)), 2rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
}

.tagline {
  margin: 4px 0 0;
  font-size: calc(0.62rem * var(--scale));
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
}

html[data-size="lg"] .tagline {
  white-space: normal;
}

.tools {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex: 0 0 auto;
  max-width: 100%;
}

.lang, .gear {
  border: 0;
  background: transparent;
  color: var(--navy);
  padding: 0;
}

.lang { display: flex; align-items: center; gap: 4px; }

.lang-code {
  background: white;
  color: var(--navy);
  border-radius: 999px;
  min-height: 30px;
  padding: 4px 10px;
  font-weight: 800;
  font-size: calc(0.72rem * var(--scale));
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
}

.icon-pill, .gear {
  background: var(--soft);
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--navy);
}

.icon-pill {
  width: calc(38px * var(--icon));
  height: calc(32px * var(--icon));
  max-width: 52px;
  max-height: 44px;
}

.gear {
  width: calc(72px * var(--icon));
  height: calc(36px * var(--icon));
  max-width: 96px;
  max-height: 52px;
  border-radius: 16px;
}

.icon-pill svg, .gear svg {
  width: calc(22px * var(--icon));
  height: calc(18px * var(--icon));
  max-width: 30px;
  max-height: 26px;
}

.switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 12px 14px 8px;
  padding: 4px;
  background: white;
  border-radius: 999px;
}

.switch a {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  color: var(--navy);
  font-weight: 800;
  letter-spacing: 0.03em;
  font-size: calc(0.75rem * var(--scale));
  line-height: 1.15;
  border-radius: 999px;
  min-height: 42px;
  padding: 8px 10px;
  overflow-wrap: anywhere;
}

.switch a[aria-current="page"] { background: var(--navy); color: white; }

.view-band {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 148px);
}

.stack, .view-registry {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 14px 16px;
}

.view-registry { padding-bottom: 28px; }

.card {
  background: var(--navy);
  color: white;
  border: 4px solid white;
  border-radius: 26px;
  padding: 14px;
  min-width: 0;
}

.profile-top {
  display: grid;
  grid-template-columns: minmax(108px, 0.86fr) minmax(0, 1.2fr);
  grid-template-areas:
    "photo facts"
    "updated button";
  gap: 8px 12px;
  align-items: start;
}

.avatar { grid-area: photo; }
.facts { grid-area: facts; min-width: 0; }
.updated { grid-area: updated; }
.edit-btn { grid-area: button; }

html[data-size="lg"] .profile-top {
  grid-template-columns: 1fr;
  grid-template-areas:
    "photo"
    "facts"
    "updated"
    "button";
}

html[data-size="lg"] .edit-btn { justify-self: stretch; width: 100%; }

@container (max-width: 360px) {
  .profile-top {
    grid-template-columns: 1fr;
    grid-template-areas:
      "photo"
      "facts"
      "updated"
      "button";
  }
  .edit-btn { justify-self: stretch; width: 100%; }
}

.avatar {
  background: white;
  border-radius: 22px;
  aspect-ratio: 4 / 4.6;
  display: grid;
  place-items: center;
  overflow: hidden;
  width: 100%;
  max-height: 250px;
}

.avatar svg { width: 72%; height: auto; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.facts h2 {
  margin: 0 0 6px;
  font-size: calc(1.28rem * var(--scale));
  font-weight: 800;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.facts ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1px;
}

.facts li {
  font-weight: 700;
  font-size: calc(0.82rem * var(--scale));
  line-height: 1.32;
  overflow-wrap: anywhere;
}

.updated {
  margin: 4px 0 0;
  font-size: calc(0.58rem * var(--scale));
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.25;
}

.edit-btn, .pill-btn, .composer button, .retry, .primary, .ghost {
  border: 0;
  background: var(--btn);
  color: var(--navy);
  font-weight: 800;
  letter-spacing: 0.04em;
  border-radius: 14px;
  padding: 12px 16px;
  min-height: 48px;
  line-height: 1.2;
  text-align: center;
  max-width: 100%;
}

.edit-btn { justify-self: end; align-self: end; }

.section-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--navy);
  color: white;
  border-radius: 999px;
  padding: 6px 16px 6px 6px;
  min-width: 0;
}

.section-bar h2 {
  margin: 0;
  font-size: calc(0.98rem * var(--scale));
  font-weight: 800;
  letter-spacing: 0.03em;
  line-height: 1.2;
  min-width: 0;
  overflow-wrap: anywhere;
}

.cloud {
  flex: 0 0 auto;
  width: calc(54px * var(--icon));
  height: calc(36px * var(--icon));
  max-width: 72px;
  max-height: 48px;
  background: white;
  border-radius: 999px;
  display: grid;
  place-items: center;
}

.cloud svg {
  width: calc(30px * var(--icon));
  height: calc(20px * var(--icon));
  max-width: 40px;
  max-height: 28px;
}

.drop {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  background: white;
  color: var(--navy);
  border-radius: 26px;
  padding: 16px;
  border: 3px solid transparent;
  min-width: 0;
  cursor: pointer;
}

.drop.hot { border-color: var(--navy); }

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.doc-icon {
  flex: 0 0 auto;
  width: calc(64px * var(--icon));
  height: calc(64px * var(--icon));
  max-width: 84px;
  max-height: 84px;
  color: var(--navy);
}

.doc-icon svg { width: 100%; height: 100%; }

.drop-copy { min-width: 0; }
.drop-copy p { margin: 0; }
.formats {
  font-weight: 800;
  font-size: calc(1.02rem * var(--scale));
  letter-spacing: 0.01em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.drop-hint {
  margin-top: 4px !important;
  font-weight: 700;
  font-size: calc(0.92rem * var(--scale));
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.error {
  margin: 0;
  background: white;
  color: var(--navy);
  border-radius: 14px;
  padding: 10px 12px;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.retry { min-height: 40px; padding: 8px 12px; }

.summary { display: flex; flex-direction: column; min-width: 0; }
html[data-size="sm"] .summary,
html[data-size="md"] .summary { min-height: 250px; }

.summary-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.summary-head h2 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: calc(1.12rem * var(--scale));
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.mini-heart {
  width: calc(28px * var(--icon));
  height: calc(28px * var(--icon));
  max-width: 40px;
  max-height: 40px;
  flex: 0 0 auto;
  color: var(--accent);
}

.recent {
  margin: 8px 0 4px;
  font-weight: 800;
  font-size: calc(0.78rem * var(--scale));
  line-height: 1.3;
}

.summary h3 {
  margin: 12px 0 2px;
  font-size: calc(0.95rem * var(--scale));
  font-weight: 800;
}

.summary ol, .none {
  margin: 0;
  font-weight: 700;
  font-size: calc(0.92rem * var(--scale));
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.summary ol { padding-left: 1.15em; }
.none { margin: 0 0 4px; }

.disclaimer, .fine {
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.disclaimer {
  margin: 16px 0 0;
  font-size: calc(0.62rem * var(--scale));
}

.consultant {
  position: relative;
  margin-top: auto;
  background: var(--navy);
  color: white;
  border-radius: 42px 42px 0 0;
  padding: 26px 16px calc(22px + env(safe-area-inset-bottom));
}

.consultant h2 {
  margin: 0 0 14px;
  padding: 0 46px;
  text-align: center;
  font-size: calc(1.55rem * var(--scale));
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.expand {
  position: absolute;
  top: 18px;
  right: 14px;
  width: calc(36px * var(--icon));
  height: calc(36px * var(--icon));
  max-width: 48px;
  max-height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--soft);
  color: var(--navy);
  display: grid;
  place-items: center;
}

.expand svg {
  width: calc(16px * var(--icon));
  height: calc(16px * var(--icon));
  max-width: 22px;
  max-height: 22px;
  transition: transform 0.2s ease;
}

.expand[aria-expanded="true"] svg { transform: rotate(180deg); }

.chat-panel {
  background: var(--panel);
  border-radius: 18px;
  padding: 12px;
  color: var(--navy);
  min-width: 0;
}

.msg { display: flex; gap: 8px; align-items: flex-start; min-width: 0; }
.msg.user { justify-content: flex-end; }

.bubble-logo {
  width: calc(36px * var(--icon));
  height: calc(36px * var(--icon));
  max-width: 48px;
  max-height: 48px;
  flex: 0 0 auto;
  background: white;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--accent);
}

.bubble-logo svg { width: 74%; height: 74%; }

.speech {
  position: relative;
  flex: 1;
  min-width: 0;
  background: white;
  color: var(--navy);
  border-radius: 16px;
  padding: 12px 14px;
  font-weight: 650;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.msg.assistant .speech::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 14px;
  border-width: 7px 8px 7px 0;
  border-style: solid;
  border-color: transparent white transparent transparent;
}

.msg.user .speech {
  flex: 0 1 auto;
  max-width: min(85%, 100%);
  background: #e7ebf1;
}

.fine { margin: 8px 2px 0; font-size: calc(0.62rem * var(--scale)); }

.thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: min(52vh, 24rem);
  overflow: auto;
  margin-top: 10px;
  padding-right: 2px;
}

.composer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.composer input {
  flex: 1 1 12rem;
  min-width: 0;
  border: 0;
  border-radius: 12px;
  background: white;
  color: var(--navy);
  padding: 12px;
  min-height: 48px;
}

.composer button { flex: 1 1 auto; }
.composer button:disabled, .pill-btn:disabled { opacity: 0.6; cursor: wait; }

.intro {
  margin: 0;
  font-weight: 650;
  font-weight: 600;
  font-size: calc(0.92rem * var(--scale));
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: white;
  border-radius: 22px;
  padding: 14px 8px;
  text-align: center;
}

.stats b {
  display: block;
  font-size: clamp(1.4rem, calc(2rem * var(--scale)), 2.5rem);
  line-height: 1;
}

.stats span {
  display: block;
  margin-top: 4px;
  font-size: calc(0.68rem * var(--scale));
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.sync {
  margin: 0;
  text-align: center;
  font-size: calc(0.75rem * var(--scale));
  font-weight: 700;
  line-height: 1.35;
}

.card h2, .panel h2 {
  margin: 0 0 10px;
  font-size: calc(1rem * var(--scale));
  letter-spacing: 0.03em;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.panel {
  background: white;
  color: var(--navy);
  border-radius: 26px;
  padding: 16px;
  min-width: 0;
}

.this-band, .nfc-status, .hint, .form-error {
  margin: 0;
  font-size: calc(0.75rem * var(--scale));
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.this-band { margin-bottom: 8px; }
.band-code { font-weight: 800; user-select: all; }
.hint { display: block; opacity: 0.75; margin-top: 3px; font-weight: 600; }
.form-error { margin: 0 0 8px; }
.nfc-status { min-height: 1em; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; margin-bottom: 8px; }
.field > span:first-child {
  font-size: calc(0.7rem * var(--scale));
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.field input, .field select, .text-btn {
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 12px;
  min-height: 46px;
  padding: 10px 12px;
  color: var(--navy);
}

.card .field input, .card .field select { background: white; }
.panel .field input, .panel .field select { background: #eef1f6; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
html[data-size="lg"] .pair { grid-template-columns: 1fr; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.actions .pill-btn, .actions .primary, .actions .ghost { flex: 1 1 140px; }

.text-btn {
  background: transparent;
  color: inherit;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-align: left;
  min-height: 36px;
  padding: 6px 0;
  font-size: calc(0.75rem * var(--scale));
}

.results { display: flex; flex-direction: column; gap: 8px; }
.results h3 {
  margin: 4px 0 0;
  font-size: calc(0.78rem * var(--scale));
  letter-spacing: 0.04em;
}

.result {
  background: white;
  color: var(--navy);
  border-radius: 18px;
  padding: 12px 14px;
  min-width: 0;
}

.result .who {
  margin: 0 0 4px;
  font-weight: 800;
  font-size: calc(1.02rem * var(--scale));
  overflow-wrap: anywhere;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.traits, .where {
  margin: 0;
  font-weight: 650;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.where { margin-top: 4px; font-weight: 800; }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: calc(0.64rem * var(--scale));
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.badge.found { background: var(--navy); color: white; }
.badge.missing { background: transparent; color: var(--navy); box-shadow: inset 0 0 0 2px var(--navy); }

.empty {
  margin: 0;
  background: white;
  border-radius: 16px;
  padding: 12px 14px;
  font-weight: 700;
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 5;
  background: rgba(217, 222, 230, 0.62);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 124px 16px 24px;
  overflow: auto;
}

.modal {
  width: min(440px, 100%);
  background: var(--navy);
  color: white;
  border: 5px solid white;
  border-radius: 28px;
  padding: 16px 16px 18px;
  max-height: calc(100vh - 116px);
  overflow: auto;
}

.set-row, .set-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
}

.set-row h2, .set-label p {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: calc(1rem * var(--scale));
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.aa-mark {
  font-weight: 700;
  font-size: calc(1.35rem * var(--scale));
  line-height: 1;
  flex: 0 0 auto;
}

.close {
  width: calc(36px * var(--icon));
  height: calc(36px * var(--icon));
  max-width: 48px;
  max-height: 48px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 50%;
  background: #d5d8e0;
  color: var(--navy);
  font-size: 1.35rem;
  line-height: 1;
  display: grid;
  place-items: center;
}

.sizes {
  display: flex;
  gap: 8px;
  margin: 16px 0 20px;
}

.sizes button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 4.4rem;
  border: 0;
  border-radius: 18px;
  background: transparent;
  color: #b7bdcb;
  font-weight: 700;
  line-height: 1;
  overflow: hidden;
}

.sizes .sm { font-size: 1.15rem; }
.sizes .md { font-size: 1.85rem; }
.sizes .lg { font-size: 2.5rem; }
.sizes button[aria-pressed="true"] { background: rgba(255, 255, 255, 0.12); color: white; }

.wheel {
  width: calc(28px * var(--icon));
  height: calc(28px * var(--icon));
  max-width: 36px;
  max-height: 36px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: conic-gradient(#d90429, #e0a100, #1f8f2a, #2f6fed, #9b2fae, #d90429);
}

.chat-icon {
  width: calc(32px * var(--icon));
  height: calc(28px * var(--icon));
  max-width: 40px;
  max-height: 36px;
  flex: 0 0 auto;
  color: white;
}

.tts-note {
  margin: 2px 0 10px 40px;
  font-size: calc(0.6rem * var(--scale));
  font-weight: 800;
  letter-spacing: 0.03em;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

html[data-size="lg"] .tts-note { margin-left: 0; }

.pills { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }

.pills button {
  border: 0;
  background: white;
  color: var(--navy);
  border-radius: 999px;
  padding: 8px 14px;
  max-width: 100%;
  font-weight: 800;
  font-size: calc(0.92rem * var(--scale));
  line-height: 1.2;
  box-shadow: inset 0 0 0 0 transparent;
}

.pills button[aria-pressed="true"] { box-shadow: inset 0 0 0 3px var(--navy); }

.c-red { color: #d90429; }
.c-green { color: #1b7f32; }
.c-blue { color: #1d4fbf; }
.c-yellow { color: #8a6200; }

.tts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  background: #d5d8e0;
  border-radius: 999px;
  padding: 4px;
}

.tts button {
  border: 0;
  border-radius: 999px;
  min-height: 48px;
  background: transparent;
  color: var(--navy);
  font-weight: 800;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  padding: 8px;
}

.tts button[aria-pressed="true"] { background: var(--btn); }
.tts svg { width: calc(22px * var(--icon)); height: calc(22px * var(--icon)); max-width: 28px; max-height: 28px; flex: 0 0 auto; }

.photo-field { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 12px; }
.photo-field .avatar { width: min(150px, 70%); }

.modal .field input, .modal .field select { background: white; color: var(--navy); }
.ghost { background: white; }

:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; }
.header :focus-visible,
.card :focus-visible,
.consultant :focus-visible,
.switch a[aria-current="page"]:focus-visible,
.section-bar :focus-visible { outline-color: white; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html.modal-open { overflow: hidden; }

html[data-color="mono"] .header,
html[data-color="mono"] .switch,
html[data-color="mono"] .view-band,
html[data-color="mono"] .view-registry {
  filter: grayscale(1) contrast(1.08);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@container (max-width: 360px) {
  .pair { grid-template-columns: 1fr; }
  .consultant h2 { font-size: calc(1.3rem * var(--scale)); }
}
