:root {
  --ink: #102b24;
  --ink-soft: #49635b;
  --green: #0c5c49;
  --green-dark: #073e32;
  --mint: #dff4e9;
  --mint-strong: #bfe8d5;
  --cream: #f8f6ef;
  --paper: #fffef9;
  --line: #dce5df;
  --danger: #a63c31;
  --warning: #805d12;
  --shadow: 0 18px 55px rgb(16 43 36 / 10%);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--cream);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 8%, rgb(191 232 213 / 44%), transparent 25rem),
    linear-gradient(180deg, #fbfaf5 0%, var(--cream) 100%);
}

.app-loading {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 13px;
  color: var(--green);
  background: var(--cream);
  text-align: center;
}

.app-loading img { width: 92px; height: 92px; margin: auto; object-fit: contain; }
.app-loading strong { font-size: clamp(24px, 5vw, 32px); letter-spacing: -.03em; }
.app-loading span { color: var(--ink-soft); font-size: 15px; font-weight: 500; }

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

button, a { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid #ebaf32;
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.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;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 10px;
  left: 10px;
  transform: translateY(-150%);
  padding: 10px 14px;
  border-radius: 10px;
  color: #fff;
  background: var(--green-dark);
}

.skip-link:focus { transform: none; }

.site-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 74px;
  padding: 12px clamp(20px, 4vw, 64px);
  border-bottom: 1px solid rgb(16 43 36 / 8%);
  background: rgb(248 246 239 / 88%);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  gap: 11px;
  align-items: center;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark-surface {
  display: grid;
  width: 42px;
  height: 42px;
  padding: 3px;
  place-items: center;
  border-radius: 13px 13px 13px 4px;
  background: #fff8e8;
  box-shadow: 0 7px 20px rgb(12 92 73 / 25%);
}

.brand-mark { display: block; width: 100%; height: 100%; object-fit: contain; }

.brand > span:last-child { display: flex; align-items: baseline; gap: 8px; }
.brand strong { font-size: 21px; letter-spacing: -.03em; }
.brand small { color: var(--ink-soft); font-size: 10px; font-weight: 800; letter-spacing: .16em; }
.official-origin { display: inline-flex; gap: 7px; align-items: center; margin: 0 auto 0 18px; padding: 7px 10px; border: 1px solid #b8d5c5; border-radius: 999px; color: var(--green-dark); background: #effaf4; font-size: 11px; }
.official-origin > span { display: grid; width: 18px; height: 18px; place-items: center; border-radius: 50%; color: #fff; background: var(--green); font-weight: 900; }
.official-origin code { color: inherit; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; }
.untrusted-origin .official-origin { border-color: #e0aaa3; color: #72251d; background: #fff1ef; }
.untrusted-origin-alert { max-width: 1180px; margin: 18px auto 0; padding: 14px 18px; border: 2px solid #b93425; border-radius: 12px; color: #72251d; background: #fff1ef; box-shadow: 0 10px 28px rgba(114, 37, 29, .12); }
.untrusted-origin-alert strong, .untrusted-origin-alert span, .untrusted-origin-alert code { display: block; }
.untrusted-origin-alert span { margin-top: 4px; }
.untrusted-origin-alert code { margin-top: 8px; color: inherit; font-weight: 800; overflow-wrap: anywhere; }
.untrusted-origin .pairing-card { border-color: #e0aaa3; }
.header-actions { display: flex; align-items: center; gap: 12px; }

.status-badge {
  padding: 7px 10px;
  border: 1px solid #bddbcc;
  border-radius: 999px;
  color: var(--green-dark);
  background: #eef9f3;
  font-size: 12px;
  font-weight: 700;
}

.status-badge::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #16976e; }

.landing {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, .75fr);
  gap: clamp(34px, 7vw, 100px);
  align-items: center;
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: clamp(58px, 9vw, 120px) 0 80px;
}

.hero-copy h1 {
  max-width: 760px;
  margin: 14px 0 24px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(42px, 6vw, 78px);
  font-weight: 500;
  line-height: .98;
  letter-spacing: -.045em;
}

.eyebrow {
  margin: 0;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.hero-lead {
  max-width: 660px;
  margin: 0;
  color: var(--ink-soft);
  font-size: clamp(17px, 2vw, 21px);
  line-height: 1.65;
}

.trust-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 30px; }
.trust-row span { padding: 8px 12px; border-radius: 999px; color: var(--green-dark); background: var(--mint); font-size: 12px; font-weight: 700; }

.pairing-card {
  position: relative;
  min-height: 490px;
  padding: clamp(28px, 4vw, 46px);
  overflow: hidden;
  border: 1px solid rgb(16 43 36 / 9%);
  border-radius: var(--radius-lg);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.step-number {
  position: absolute;
  top: -18px;
  right: 18px;
  color: rgb(12 92 73 / 8%);
  font-family: Georgia, serif;
  font-size: 112px;
  line-height: 1;
}

.pairing-card h2 { position: relative; margin: 8px 0 24px; max-width: 330px; font-family: Georgia, serif; font-size: 29px; font-weight: 500; line-height: 1.15; }
.official-address-note { position: relative; margin: -10px 0 22px; padding: 11px 13px; border-left: 3px solid var(--green); border-radius: 0 9px 9px 0; color: var(--ink-soft); background: #effaf4; font-size: 12px; line-height: 1.5; }
.pairing-steps { position: relative; display: grid; gap: 17px; margin: 0 0 32px; padding-left: 24px; color: var(--ink-soft); line-height: 1.48; }
.pairing-steps li::marker { color: var(--green); font-weight: 800; }
.automatic-qr-note { position: relative; margin: -16px 0 18px; color: var(--ink-soft); font-size: 12px; line-height: 1.5; }

.button {
  min-height: 46px;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: 13px;
  cursor: pointer;
  font-weight: 750;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}

.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: .55; }
.button-primary { color: #fff; background: var(--green); box-shadow: 0 9px 24px rgb(12 92 73 / 20%); }
.button-primary:hover:not(:disabled) { background: var(--green-dark); }
.button-install { border-color: var(--green); color: var(--green); background: #fff; }
.button-install:hover:not(:disabled) { color: #fff; background: var(--green); }
.button-quiet { border-color: var(--line); color: var(--ink); background: transparent; }
.button-quiet:hover:not(:disabled) { background: #eef3ef; }

.pairing-active { position: relative; text-align: center; }
.pairing-active h2 { max-width: none; margin: 4px auto 9px; font-family: inherit; font-size: 25px; font-weight: 800; letter-spacing: -.03em; }
.pairing-brand-logo { display: block; width: 76px; height: auto; margin: 0 auto; object-fit: contain; }
.pairing-instruction { max-width: 330px; margin: 0 auto 18px; color: var(--ink-soft); font-size: 14px; line-height: 1.5; }
.qr-shell { position: relative; display: grid; width: 260px; height: 260px; margin: 0 auto 13px; padding: 0; place-items: center; border: 0; border-radius: 0; background: #fff; box-shadow: none; }
.qr-shell > #pairing-qr { display: block; width: 260px; height: 260px; }
.qr-logo-halo { position: absolute; z-index: 2; top: 50%; left: 50%; display: grid; width: 24%; aspect-ratio: 1; padding: 0; transform: translate(-50%, -50%); place-items: center; border: 0; border-radius: 50%; background: #fff; box-shadow: none; pointer-events: none; }
.qr-logo-halo > .qr-logo { display: block; width: 84.375%; height: auto; padding: 0; border: 0; background: transparent; box-shadow: none; object-fit: contain; }
.qr-placeholder { width: 260px; height: 260px; border-radius: 0; background: repeating-linear-gradient(45deg, #eef3ef 0 9px, #f8faf8 9px 18px); animation: shimmer 1.2s linear infinite; }
.qr-refresh-note { margin: 0 0 8px; color: var(--ink-soft); font-size: 13px; }
.qr-refresh-note button { padding: 0; border: 0; color: var(--green); background: transparent; cursor: pointer; font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }
.qr-refresh-note button:hover:not(:disabled) { color: var(--green-dark); }
.pairing-status { min-height: 42px; margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 1.45; }
.expiry-track { display: block; width: 100%; height: 4px; margin: 12px 0 18px; overflow: hidden; border: 0; border-radius: 999px; appearance: none; background: #e9eee9; }
.expiry-track::-webkit-progress-bar { border-radius: 999px; background: #e9eee9; }
.expiry-track::-webkit-progress-value { border-radius: 999px; background: #dea62b; }
.expiry-track::-moz-progress-bar { border-radius: 999px; background: #dea62b; }

@keyframes shimmer { to { background-position: 26px 0; } }

.web-boundaries { grid-column: 1 / -1; display: grid; grid-template-columns: .7fr 1.3fr; gap: 44px; align-items: start; margin-top: 40px; padding-top: 52px; border-top: 1px solid var(--line); }
.web-boundaries h2 { margin: 10px 0 0; font-family: Georgia, serif; font-size: clamp(28px, 3vw, 42px); font-weight: 500; line-height: 1.15; }
.boundary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.boundary-grid article { min-height: 190px; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius-md); background: rgb(255 254 249 / 70%); }
.boundary-icon { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 11px; color: var(--green); background: var(--mint); font-size: 12px; font-weight: 900; }
.boundary-grid h3 { margin: 22px 0 8px; font-size: 16px; }
.boundary-grid p { margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.55; }

.safe-rules { grid-column: 1 / -1; display: grid; grid-template-columns: .8fr 1.2fr; gap: 44px; padding: 34px; border-radius: var(--radius-lg); color: #f6fff9; background: var(--green-dark); }
.safe-rules h2 { margin: 10px 0 0; font-family: Georgia, serif; font-size: clamp(27px, 3vw, 39px); font-weight: 500; line-height: 1.15; }
.safe-rules .eyebrow { color: #9edbc1; }
.safe-rules ul { display: grid; gap: 14px; margin: 0; padding-left: 20px; color: #d8eee5; line-height: 1.55; }
.safe-rules li::marker { color: #f4bf49; }
.safe-rules strong { color: #fff; }

.web-app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: calc(100vh - 74px); }
.app-sidebar { display: flex; flex-direction: column; gap: 25px; padding: 28px 20px; border-right: 1px solid var(--line); background: rgb(255 254 249 / 78%); }
.user-card { display: flex; gap: 12px; align-items: center; padding: 0 8px; }
.user-card > div { min-width: 0; display: grid; gap: 3px; }
.user-card strong, .user-card small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-card small { color: var(--ink-soft); }
.avatar { display: grid; width: 42px; height: 42px; flex: 0 0 auto; place-items: center; border-radius: 50%; color: #fff; background: var(--green); font-weight: 850; }
.app-nav { display: grid; gap: 6px; }
.nav-item { display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: center; width: 100%; min-height: 48px; padding: 8px 10px; border: 0; border-radius: 12px; color: var(--ink-soft); background: transparent; cursor: pointer; text-align: left; font-weight: 700; }
.nav-item > span { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 9px; background: #edf1ed; font-size: 12px; }
.nav-item small { color: #789087; font-size: 10px; font-weight: 650; }
.nav-item:hover { background: #f0f4f0; }
.nav-item.active { color: #fff; background: var(--green); box-shadow: 0 7px 20px rgb(12 92 73 / 18%); }
.nav-item.active > span { color: var(--green-dark); background: var(--mint); }
.nav-item.active small { color: #d8eee5; }
.mobile-only-note { display: grid; gap: 5px; margin-top: auto; padding: 14px; border-radius: 13px; color: #624a12; background: #fff6d8; font-size: 12px; }
.mobile-only-note span { line-height: 1.45; }

.app-content { min-width: 0; padding: clamp(18px, 3vw, 38px); }
.app-panel { width: min(1180px, 100%); margin: 0 auto; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; min-height: 70px; margin-bottom: 18px; }
.panel-heading h2 { margin: 5px 0 0; font-family: Georgia, serif; font-size: 32px; font-weight: 500; }
.icon-button { display: grid; width: 42px; height: 42px; place-items: center; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: var(--paper); cursor: pointer; font-size: 20px; }

.chat-layout { display: grid; grid-template-columns: minmax(210px, 320px) minmax(0, 1fr); height: calc(100vh - 200px); min-height: 510px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--paper); box-shadow: 0 10px 36px rgb(16 43 36 / 6%); }
.chat-rooms { overflow-y: auto; border-right: 1px solid var(--line); }
.room-button { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; gap: 10px; width: 100%; padding: 15px; border: 0; border-bottom: 1px solid #edf0ed; color: var(--ink); background: transparent; cursor: pointer; text-align: left; }
.room-button:hover, .room-button.active { background: #eff7f2; }
.room-avatar { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 50%; color: var(--green-dark); background: var(--mint); font-weight: 850; }
.room-copy { min-width: 0; display: grid; gap: 4px; }
.room-copy strong, .room-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-copy span { color: var(--ink-soft); font-size: 12px; }
.unread { min-width: 22px; padding: 3px 7px; border-radius: 999px; color: #fff; background: var(--green); font-size: 11px; font-weight: 800; text-align: center; }
.conversation { display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; min-width: 0; }
.conversation-header { display: flex; min-height: 66px; padding: 14px 18px; align-items: center; border-bottom: 1px solid var(--line); }
.conversation-header div { display: grid; gap: 3px; }
.conversation-header small { color: var(--ink-soft); }
.messages { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; padding: 22px; background: radial-gradient(circle at 10px 10px, rgb(12 92 73 / 3%) 1px, transparent 1px); background-size: 18px 18px; }
.message { align-self: flex-start; max-width: min(78%, 620px); padding: 10px 13px 7px; border: 1px solid var(--line); border-radius: 5px 15px 15px; background: #fff; }
.message.mine { align-self: flex-end; border-color: #c4e4d3; border-radius: 15px 5px 15px 15px; background: #ddf2e7; }
.message p { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; line-height: 1.45; }
.message small { display: block; margin-top: 4px; color: #6e817a; font-size: 10px; text-align: right; }
.unsupported-message { color: var(--ink-soft); font-style: italic; }
.empty-state, .loading-state { display: grid; min-height: 220px; padding: 32px; place-items: center; align-content: center; color: var(--ink-soft); text-align: center; }
.empty-state span { display: grid; width: 50px; height: 50px; place-items: center; border-radius: 16px; color: var(--green); background: var(--mint); font-weight: 900; }
.message-form { display: grid; grid-template-columns: minmax(0, 1fr) 42px; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
.message-form textarea { width: 100%; max-height: 130px; padding: 11px 13px; resize: vertical; border: 1px solid #cfdad3; border-radius: 12px; color: var(--ink); background: #fff; }
.send-button { width: 42px; height: 42px; border: 0; border-radius: 12px; color: #fff; background: var(--green); cursor: pointer; font-size: 20px; font-weight: 800; }
.text-only-warning { margin: 0; padding: 7px 14px 10px; color: #78601f; background: #fff9e7; font-size: 10px; text-align: center; }

.read-only-banner { margin-bottom: 18px; padding: 13px 16px; border: 1px solid #ead89d; border-radius: 12px; color: #6e5314; background: #fff8df; font-size: 13px; }
.content-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.listing-card, .feed-card { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--paper); }
.listing-card { display: grid; min-height: 205px; align-content: space-between; }
.listing-card .category { color: var(--green); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.listing-card h3 { margin: 12px 0 7px; font-size: 18px; }
.listing-card p, .feed-card p { color: var(--ink-soft); line-height: 1.5; }
.listing-footer { display: flex; align-items: end; justify-content: space-between; gap: 12px; }
.listing-price { font-family: Georgia, serif; font-size: 22px; }
.listing-seller { color: var(--ink-soft); font-size: 11px; text-align: right; }
.feed-list { display: grid; gap: 12px; }
.feed-card { max-width: 800px; }
.feed-head { display: flex; justify-content: space-between; gap: 15px; color: var(--ink-soft); font-size: 12px; }
.feed-likes { color: var(--green); font-weight: 800; }

.toast-region { position: fixed; z-index: 80; right: 18px; bottom: 18px; display: grid; gap: 8px; width: min(390px, calc(100% - 36px)); }
.toast { padding: 14px 16px; border: 1px solid #b8d5c5; border-radius: 13px; color: var(--green-dark); background: #effaf4; box-shadow: var(--shadow); font-size: 13px; line-height: 1.45; }
.toast.error { border-color: #e0aaa3; color: #72251d; background: #fff1ef; }

@media (max-width: 950px) {
  .landing { grid-template-columns: 1fr; }
  .pairing-card { min-height: auto; }
  .web-boundaries { grid-template-columns: 1fr; }
  .safe-rules { grid-template-columns: 1fr; }
  .web-app { grid-template-columns: 88px minmax(0, 1fr); }
  .app-sidebar { padding: 22px 12px; }
  .user-card { justify-content: center; padding: 0; }
  .user-card > div, .nav-item:not(.active) small, .nav-item > :not(span), .mobile-only-note { display: none; }
  .nav-item { display: grid; grid-template-columns: 1fr; justify-items: center; padding: 8px; }
  .nav-item.active { color: var(--ink); background: transparent; box-shadow: none; }
  .nav-item.active > span { color: #fff; background: var(--green); }
  .content-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .untrusted-origin-alert { margin: 12px 14px 0; }
  .site-header { min-height: 64px; padding: 10px 16px; }
  .status-badge { display: none; }
  .official-origin { margin-left: 10px; }
  .official-origin strong { display: none; }
  .landing { width: min(100% - 28px, 600px); padding-top: 45px; }
  .hero-copy h1 { font-size: clamp(39px, 13vw, 58px); }
  .boundary-grid { grid-template-columns: 1fr; }
  .boundary-grid article { min-height: auto; }
  .web-app { display: block; padding-bottom: 74px; }
  .app-sidebar { position: fixed; z-index: 30; right: 0; bottom: 0; left: 0; display: block; padding: 8px max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); border-top: 1px solid var(--line); border-right: 0; background: rgb(255 254 249 / 96%); backdrop-filter: blur(14px); }
  .user-card, .mobile-only-note { display: none; }
  .app-nav { grid-template-columns: repeat(3, 1fr); gap: 2px; }
  .nav-item { min-height: 48px; }
  .nav-item > span { width: 34px; height: 34px; }
  .app-content { padding: 14px; }
  .panel-heading { min-height: 58px; }
  .chat-layout { display: block; height: auto; min-height: 0; }
  .chat-rooms { max-height: 260px; border-right: 0; border-bottom: 1px solid var(--line); }
  .conversation { min-height: 490px; }
  .content-grid { grid-template-columns: 1fr; }
  .message { max-width: 88%; }
}

@media (max-width: 520px) {
  .official-origin { display: none; }
  .header-actions { gap: 7px; }
  .button-install { max-width: 132px; padding: 9px 10px; font-size: 12px; line-height: 1.15; }
}

@media (max-width: 360px) {
  .qr-shell,
  .qr-shell > #pairing-qr,
  .qr-placeholder { width: 195px; height: 195px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

#scan-video { max-width: 32rem; width: 100%; }
#scan-input { display:block; width:100%; max-width:44rem; margin:0.5rem 0; padding:0.75rem; border:1px solid #9ab6ac; border-radius:0.5rem; }
#scan-purpose { margin:0.5rem; padding:0.5rem; }

.media-message { display: grid; gap: .35rem; min-width: 0; overflow-wrap: anywhere; }
.media-message strong { font-size: .95rem; }
.media-filename { white-space: pre-wrap; unicode-bidi: plaintext; }
.media-metadata { font-size: .8rem; opacity: .8; }
.media-message .unsupported-message { display: block; font-size: .8rem; }
