:root {
  --paper: #f7efe6;
  --card: rgba(255, 253, 249, 0.9);
  --ink: #352b27;
  --muted: #786b63;
  --line: rgba(74, 54, 45, 0.13);
  --accent: #b64e42;
  --accent-soft: #f1dcd3;
  --good: #537c63;
  --warn: #9b6728;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  background: radial-gradient(circle at 15% -5%, rgba(255,255,255,.92), transparent 38%), var(--paper);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid #2b67c0; outline-offset: 3px; }

main { width: min(100%, 620px); margin: 0 auto; }
.page {
  min-height: 100dvh;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(108px + env(safe-area-inset-bottom));
}
.page[hidden] { display: none; }
.page.active { animation: appear .2s ease-out; }
@keyframes appear { from { opacity: 0; transform: translateY(5px); } }
@media (prefers-reduced-motion: reduce) { .page.active { animation: none; } }

.topline { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; margin-bottom: 20px; }
.eyebrow { margin: 0 0 5px; color: var(--muted); font-size: 12px; font-weight: 750; letter-spacing: .13em; }
h1 { margin: 0; font-size: 30px; letter-spacing: -.03em; }
h2 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.connection { padding: 8px 11px; border-radius: 99px; color: var(--warn); background: #fff3df; font-size: 12px; font-weight: 750; }
.connection.online { color: var(--good); background: #e6f1e9; }

.presence-card, .home-section, .remote-dock, .device-details, .panel, .record {
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: 0 14px 36px rgba(77,49,36,.07);
}
.presence-card {
  display: grid;
  grid-template-columns: 42% 1fr;
  gap: 16px;
  align-items: center;
  min-height: 136px;
  padding: 12px;
  border-radius: 24px;
  overflow: hidden;
}
.presence-card img { width: 100%; aspect-ratio: 4 / 3; display: block; object-fit: cover; border-radius: 17px; }
.presence-card h2 { font-size: 21px; }
.presence-card p:last-child { margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }

.home-section, .remote-dock { margin-top: 14px; padding: 17px; border-radius: 21px; }
.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 13px; }
.compact-heading { margin-bottom: 12px; }
.text-button { min-height: 40px; border: 0; padding: 7px 2px 7px 10px; color: var(--accent); background: transparent; font-size: 13px; font-weight: 750; }

.recent-list { display: grid; gap: 9px; }
.recent-item { padding: 12px 13px; border-radius: 15px; background: #fffaf5; border: 1px solid var(--line); }
.recent-item div { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 11px; }
.recent-item div strong { color: var(--ink); }
.recent-item p { margin: 6px 0 0; font-size: 14px; line-height: 1.55; }
.empty { color: var(--muted); text-align: center; padding: 54px 0; }
.empty.compact { padding: 15px 0 3px; font-size: 13px; }

.relationship-card { background: linear-gradient(145deg, rgba(255,253,249,.96), rgba(243,226,215,.8)); }
.relationship-state { padding: 6px 9px; border-radius: 99px; color: var(--accent); background: var(--accent-soft); font-size: 11px; font-weight: 750; }
.relationship-layout { display: grid; grid-template-columns: minmax(135px, 46%) 1fr; align-items: center; gap: 10px; }
.trait-chart { width: 100%; height: auto; overflow: visible; }
.trait-chart line, .trait-grid { fill: none; stroke: rgba(89,66,55,.2); stroke-width: 1.3; }
.trait-grid.inner { stroke-dasharray: 3 4; }
.trait-shape { fill: rgba(182,78,66,.25); stroke: var(--accent); stroke-width: 2.4; }
.personality-labels { display: flex; flex-wrap: wrap; gap: 6px; }
.personality-labels span { padding: 6px 8px; border-radius: 99px; color: #7d3d35; background: #fff2ea; font-size: 12px; font-weight: 750; }
.relationship-note { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.trait-values { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 11px 0 0; }
.trait-values div { min-width: 0; padding: 8px; border-radius: 12px; background: rgba(255,255,255,.55); }
.trait-values dt { overflow: hidden; color: var(--muted); font-size: 10px; white-space: nowrap; text-overflow: ellipsis; }
.trait-values dd { margin: 3px 0 0; }
.trait-values dd strong { font-size: 17px; }
.trait-values dd span { margin-left: 2px; color: var(--muted); font-size: 10px; }

.remote-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.remote-action { min-height: 66px; padding: 11px 13px; text-align: left; border: 1px solid var(--line); border-radius: 15px; color: var(--ink); background: #fffaf6; }
.remote-action span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.remote-action strong { font-size: 15px; }
.remote-action.active { color: #fff; border-color: var(--accent); background: var(--accent); }
.remote-action.active span { color: rgba(255,255,255,.78); }
.volume-control { display: flex; justify-content: space-between; margin-top: 14px; font-size: 13px; }
.remote-dock input[type="range"] { width: 100%; min-height: 34px; accent-color: var(--accent); }

.device-details { margin-top: 14px; border-radius: 17px; overflow: hidden; }
.device-details summary { min-height: 48px; padding: 14px 16px; cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 700; }
.device-details dl { display: grid; gap: 0; margin: 0; padding: 0 16px 14px; }
.device-details dl div { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-top: 1px solid var(--line); }
.device-details dt { color: var(--muted); font-size: 12px; }
.device-details dd { margin: 0; text-align: right; font-size: 12px; font-weight: 700; }

.quiet-button { min-height: 42px; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 12px; padding: 9px 14px; font-weight: 700; }
.section-note { margin: -5px 0 22px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.record-list { display: grid; gap: 11px; }
.record { padding: 15px; border-radius: 18px; }
.record-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-bottom: 7px; }
.record p { margin: 0; line-height: 1.65; font-size: 14px; }

.settings-section { margin: 0 0 18px; }
.panel { border-radius: 18px; padding: 0 16px; }
.setting-row { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.setting-row small { display: block; margin-top: 4px; color: var(--muted); }
.setting-row.stacked { align-items: stretch; flex-direction: column; padding: 16px 0; }
.setting-note { margin: -8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.switch { width: 48px; height: 28px; padding: 3px; border: 0; border-radius: 99px; background: #cfc5be; }
.switch span { display: block; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .18s; box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.switch[aria-pressed="true"] { background: var(--good); }
.switch[aria-pressed="true"] span { transform: translateX(20px); }
.primary-button { width: 100%; min-height: 48px; border: 0; border-radius: 14px; padding: 13px 16px; color: #fff; background: var(--ink); font-weight: 750; }
.logout-button { width: 100%; min-height: 48px; border: 0; padding: 14px; color: var(--muted); background: transparent; }

.tabbar { position: fixed; z-index: 20; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 620px); display: grid; grid-template-columns: repeat(3, 1fr); padding: 9px 18px calc(9px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(247,239,230,.94); backdrop-filter: blur(20px); }
.tab { min-height: 44px; border: 0; padding: 10px; color: var(--muted); background: transparent; font-size: 13px; font-weight: 750; }
.tab.active { color: var(--accent); }

.auth-layer { position: fixed; z-index: 50; inset: 0; padding: 22px; display: grid; place-items: center; background: rgba(53,43,39,.38); backdrop-filter: blur(8px); }
.auth-layer[hidden] { display: none; }
.auth-card { width: min(100%, 380px); padding: 26px; border-radius: 24px; background: var(--paper); box-shadow: 0 24px 80px rgba(0,0,0,.22); }
.auth-card h2 { font-size: 24px; }
.auth-card p:not(.eyebrow) { color: var(--muted); font-size: 13px; line-height: 1.6; }
.auth-card input { width: 100%; margin: 10px 0 12px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.auth-error { min-height: 20px; color: var(--accent) !important; }
.toast { position: fixed; z-index: 70; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 12px); opacity: 0; pointer-events: none; padding: 11px 16px; color: #fff; background: var(--ink); border-radius: 99px; font-size: 13px; transition: .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) { .page { padding-left: 34px; padding-right: 34px; } }
@media (max-width: 360px) {
  .relationship-layout { grid-template-columns: 1fr; }
  .trait-chart { max-width: 190px; margin: 0 auto; }
}
