/* Companion-first mobile app. Navigation 10, toast 30, native dialog above. */
#settingsGuideShade {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.7);
}
.guide-target {
  position: relative;
  z-index: 101;
  grid-column: 1 / -1;
  background: var(--paper);
  border: 2px solid var(--accent);
  border-radius: 14px;
  padding: 18px;
  scroll-margin-block: 24px;
}
.onboarding-only {
  display: none;
}
.has-settings-guide .onboarding-only.guide-target {
  display: block;
}
.guide-choice-list {
  display: grid;
  gap: 10px;
  border: 0;
  padding: 0;
  margin: 0;
}
.guide-choice-list legend {
  font-weight: 700;
  margin-bottom: 10px;
}
.guide-choice {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.guide-choice:has(input:checked) {
  border-color: var(--accent);
  background: var(--soft);
}
.guide-choice input {
  margin-top: 4px;
}
.guide-choice strong,
.guide-choice small {
  display: block;
}
.guide-choice small {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.5;
}
.guide-callout {
  margin-bottom: 18px;
}
.guide-step {
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
  margin: 0 0 6px;
}
.guide-callout h3 {
  margin: 0 0 6px;
  font-size: 19px;
}
#guideNote {
  font-size: 14px;
  margin: 0;
}
#guideError {
  font-size: 14px;
  color: var(--danger);
}
.guide-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}
.guide-actions .primary {
  flex: 1;
}
#guidePortraitPreview {
  width: 80px;
  max-height: 110px;
  object-fit: contain;
  margin-top: 12px;
}
.has-settings-guide #toast {
  z-index: 102;
}
.has-settings-guide #guideAI .optional {
  display: none;
}
/* The API route of the guide always uses the API, so no switch there. */
.has-settings-guide #apiModeRow {
  display: none;
}
/* Preserve the existing rose/paper palette; simple first-use form (2/1/3). */
body.has-wide-guide {
  overflow: hidden;
}
#guideAI.guide-target {
  position: fixed;
  inset: auto;
  top: calc(var(--guide-top, 0px) + 12px);
  left: 50%;
  transform: translateX(-50%);
  width: min(720px, calc(100% - 24px));
  height: calc(var(--guide-height, 100dvh) - 24px);
  margin: 0;
  padding: 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 20px 120px;
}
#guideAI.guide-target > h2 {
  display: none;
}
#guideAI.guide-target .guide-actions {
  position: sticky;
  bottom: -24px;
  display: grid;
  grid-template-columns: auto 1fr;
  padding: 12px 0 max(12px, env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid var(--line);
  z-index: 1;
}
.guide-consent {
  grid-column: 1 / -1;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}
#guideAI.guide-target input,
#guideAI.guide-target textarea,
#guideAI.guide-target select {
  scroll-margin-block: 24px 120px;
}
#guideAI details {
  margin: 16px 0;
}
#guideAI details summary {
  min-height: 44px;
  padding-block: 10px;
  cursor: pointer;
}
#aiSaveConsent {
  flex-basis: 100%;
  margin: 0;
}
.save-row:has(#aiSaveConsent) {
  flex-wrap: wrap;
}
@media (max-width: 600px) {
  #guideAI.guide-target {
    top: calc(var(--guide-top, 0px) + 6px);
    width: calc(100% - 12px);
    height: calc(var(--guide-height, 100dvh) - 12px);
    padding: 18px 14px;
    border-radius: 12px;
  }
  #guideAI.guide-target .guide-actions {
    bottom: -18px;
  }
}
.welcome-actions {
  margin-top: 28px;
  max-width: 430px;
}
.auth-layout:has(#authPanel) {
  display: block;
  max-width: 560px;
}
.is-onboarding.app-layout {
  display: block;
  max-width: 650px;
}
.is-onboarding .sidebar,
.is-onboarding .topbar {
  display: none;
}
.is-onboarding main {
  padding: 30px 24px 40px;
  min-height: 100dvh;
}
.onboarding {
  max-width: 540px;
  margin: auto;
}
.onboarding-brand {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  margin-bottom: 44px;
  font-weight: 700;
}
.onboarding-brand span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}
.onboarding h1 {
  font-size: clamp(24px, 6vw, 32px);
  line-height: 1.5;
  letter-spacing: -1px;
  margin: 0 0 24px;
}
.onboarding h1:focus {
  outline: none;
}
.onboarding-example {
  padding: 18px 22px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  margin: 25px 0;
}
.onboarding-example p {
  margin: 8px 0;
}
.onboarding-list {
  padding-left: 22px;
}
.onboarding-list li {
  margin: 14px 0;
}
.onboarding-actions {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 32px;
  padding-bottom: env(safe-area-inset-bottom);
}
.onboarding-actions .primary {
  flex: 1;
}
.onboarding .form-section {
  padding: 0;
  border: 0;
  box-shadow: none;
  background: none;
}
.together-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.together-heart {
  color: var(--accent);
  font-weight: 700;
}
.chat-page {
  max-width: 600px;
  margin: auto;
}
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin: 28px 0;
}
.chat-message {
  max-width: 90%;
  align-self: flex-start;
  padding: 14px 18px;
  border-radius: 4px 18px 18px 18px;
  background: var(--paper);
  border: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.chat-message.me {
  align-self: flex-end;
  background: var(--soft);
  border-radius: 18px 4px 18px 18px;
}
.chat-message span {
  font-size: 12px;
  color: var(--muted);
}
.chat-message p {
  white-space: pre-wrap;
  margin: 5px 0 0;
}
:root {
  --bgveil: rgba(251, 247, 243, 0.9);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bgveil: rgba(26, 36, 31, 0.93);
  }
}
:root {
  color-scheme: light dark;
  --bg: #fbf7f3;
  --paper: #fffdfb;
  --ink: #493b3e;
  --muted: #79676b;
  --line: #e9dedd;
  --accent: #915461;
  --accent-ink: #fff;
  --soft: #f4e6e6;
  --danger: #a23136;
  --shadow: 0 10px 35px #263c3010;
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.65;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}
.policy-page {
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 22px 80px;
  line-height: 1.75;
}
.policy-page h1 {
  margin-top: 32px;
}
.policy-page h2 {
  margin-top: 34px;
}
.policy-page .notice {
  padding: 16px;
  border-radius: 14px;
  background: var(--paper, #fff8f3);
}
.recovery-code {
  display: block;
  margin: 18px 0;
  padding: 18px;
  border-radius: 12px;
  background: #f5eee8;
  font:
    700 1.25rem/1.4 ui-monospace,
    SFMono-Regular,
    Consolas,
    monospace;
  letter-spacing: 0.08em;
  text-align: center;
  user-select: all;
}
button,
input,
textarea,
select {
  font: inherit;
}
button,
a,
input,
textarea,
select,
summary {
  -webkit-tap-highlight-color: transparent;
}
button {
  cursor: pointer;
}
button:disabled {
  cursor: wait;
  opacity: 0.58;
}
button:active:not(:disabled) {
  transform: translateY(1px);
}
button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 4px;
}
input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
a {
  color: inherit;
  text-decoration: none;
}
button {
  border: 0;
  color: inherit;
  background: none;
}
input,
select,
textarea {
  font-size: 16px;
  min-width: 0;
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
}
input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.85;
}
input[type="checkbox"],
input[type="radio"] {
  width: 19px;
  height: 19px;
  accent-color: var(--accent);
}
input[type="file"] {
  font-size: 13px;
}
textarea {
  resize: vertical;
}
label {
  display: grid;
  gap: 7px;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 18px;
}
label .fine {
  font-weight: 400;
}
h1,
h2,
h3,
p {
  margin: 0;
}
h1 {
  font-size: 32px;
  letter-spacing: -1.3px;
  line-height: 1.4;
}
h2 {
  font-size: 21px;
  letter-spacing: -0.6px;
  margin-bottom: 20px;
}
h3 {
  font-size: 17px;
  margin-bottom: 12px;
}
p {
  overflow-wrap: anywhere;
}
hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 24px 0;
}
[hidden] {
  display: none !important;
}
.muted,
.fine {
  color: var(--muted);
}
.fine {
  font-size: 13px;
  line-height: 1.8;
  margin: 10px 0 18px;
}
.error {
  color: var(--danger);
  font-size: 14px;
  min-height: 25px;
  margin: 8px 0;
}
.primary,
.secondary,
.danger {
  padding: 12px 20px;
  border-radius: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
}
.primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.secondary {
  background: var(--soft);
  color: var(--ink);
}
.danger {
  background: var(--danger);
  color: #fff;
}
.text-button {
  padding: 10px 0;
  text-decoration: underline;
  text-underline-offset: 4px;
  font-size: 14px;
}
.wide {
  width: 100%;
}
.wordmark {
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -1.8px;
}
.auth-layout {
  min-height: 100dvh;
  max-width: 1050px;
  margin: auto;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  align-items: center;
  gap: 90px;
  padding: 60px 35px;
}
.welcome h1 {
  font-size: 44px;
  line-height: 1.45;
  margin: 28px 0 22px;
  letter-spacing: -2px;
}
.welcome > p {
  color: var(--muted);
  line-height: 1.9;
}
.sample-letter {
  background: var(--paper);
  padding: 22px;
  margin-top: 24px;
  border: 1px solid var(--line);
  border-radius: 4px 18px 18px 18px;
  box-shadow: var(--shadow);
}
.sample-letter p {
  font-size: 15px;
  line-height: 1.8;
  margin: 8px 0;
}
.sample-letter p:first-child {
  margin-top: 0;
}
.sample-letter p:last-child {
  margin-bottom: 0;
}
dialog.auth-panel {
  width: min(420px, calc(100% - 32px));
  padding: 24px;
  overflow-y: auto;
}
body:has(#authPanel[open]) {
  overflow: hidden;
}
#authPanel .dialog-close {
  margin-bottom: 12px;
}
.auth-panel h2 {
  margin-bottom: 6px;
}
.auth-panel form {
  margin-top: 30px;
}
.auth-panel > .text-button {
  margin: 15px 0;
}
.app-layout {
  max-width: 850px;
  margin: auto;
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  min-height: 100dvh;
}
.sidebar {
  padding: 38px 26px 24px 20px;
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.tagline {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}
.sidebar nav {
  display: grid;
  gap: 8px;
  margin-top: 65px;
}
.sidebar nav button {
  text-align: left;
  padding: 12px 17px;
  border-radius: 10px;
  font-weight: 600;
  color: var(--muted);
  min-height: 48px;
}
.sidebar nav button[aria-current="page"] {
  background: var(--soft);
  color: var(--ink);
}
.sidebar-bottom {
  margin-top: auto;
  display: grid;
  font-size: 12px;
  color: var(--muted);
}
.sidebar-bottom button {
  text-align: left;
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 13px;
  color: var(--muted);
  padding-bottom: 32px;
}
main {
  min-width: 0;
  padding: 30px 28px 70px;
  background-size: cover;
  background-attachment: scroll;
}
.page-heading {
  margin: 5px 0 32px;
}
.page-heading p {
  color: var(--muted);
  margin-top: 10px;
}
.today-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 22px;
}
.goal-panel {
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 28px;
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.goal-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}
.portrait {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 50%;
}
.goal-amount {
  font-size: 42px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: -1.8px;
  margin: 22px 0 4px;
}
.goal-amount small {
  font-size: 15px;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0;
}
.record-fields {
  margin-top: 24px;
}
.record-fields label {
  margin-bottom: 12px;
}
.record-fields .amount-row {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 12px;
}
.record-fields .primary {
  margin-top: 8px;
}
.letter-preview {
  width: 100%;
  height: 100%;
  text-align: left;
  padding: 30px 25px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-height: 300px;
}
.letter-preview .seal {
  font-size: 34px;
  font-weight: 800;
  border: 1px solid var(--accent);
  border-radius: 50%;
  width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  margin-bottom: 27px;
}
.letter-preview h2 {
  margin-bottom: 12px;
}
.letter-preview .preview {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.9;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-line;
}
.letter-preview .link {
  margin-top: 24px;
  font-weight: 700;
  font-size: 14px;
}
.section {
  margin-top: 35px;
}
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}
.section-title h2 {
  margin: 0;
}
.section-title button {
  min-width: 42px;
  min-height: 42px;
  background: var(--soft);
  border-radius: 10px;
}
.calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}
.dow {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 6px;
}
.cal-day {
  background: var(--paper);
  min-height: 74px;
  border-radius: 10px;
  padding: 9px 5px;
  text-align: center;
  border: 1px solid transparent;
  font-size: 12px;
  min-width: 0;
}
.cal-day.current {
  border-color: var(--accent);
}
.cal-day.complete {
  background: var(--soft);
}
.cal-day .count {
  display: block;
  font-size: 11px;
  margin-top: 8px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-day.rest {
  background: transparent;
  color: var(--muted);
}
.cal-day.future {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
  border-style: dashed;
}
.streak-line {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.suggestion {
  padding: 24px 0;
  border-top: 1px solid var(--line);
  margin-top: 30px;
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: space-between;
}
.suggestion h3 {
  margin: 0 0 5px;
}
.suggestion p {
  font-size: 14px;
  color: var(--muted);
}
.suggestion button {
  flex-shrink: 0;
}
.empty {
  padding: 42px 25px;
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: 18px;
  color: var(--muted);
  line-height: 1.9;
}
.letter-row {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  text-align: left;
  padding: 23px 0;
  border-bottom: 1px solid var(--line);
  gap: 7px 20px;
}
.letter-row strong {
  font-size: 17px;
}
.letter-row small {
  font-size: 12px;
  color: var(--muted);
}
.letter-row p {
  grid-column: 1/-1;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.album-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.photo {
  padding: 0;
  text-align: left;
  min-width: 0;
}
.photo img {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  border-radius: 12px;
  display: block;
  background: var(--soft);
}
.photo small {
  display: block;
  color: var(--muted);
  margin-top: 7px;
  overflow-wrap: anywhere;
}
.album-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 22px 0;
  flex-wrap: wrap;
}
.file-button {
  position: relative;
  cursor: pointer;
  font-size: 14px;
  margin: 0;
}
.file-button:focus-within {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.form-section {
  padding: 28px 0;
  border-top: 1px solid var(--line);
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 20px;
}
.form-section > label {
  max-width: 100%;
}
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 400;
}
.check input {
  flex-shrink: 0;
}
.optional {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  margin-left: 8px;
}
.day-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}
.day-choices label {
  display: flex;
  flex-direction: row;
  align-items: center;
  font-weight: 400;
  gap: 5px;
  margin: 5px 0;
}
.day-choices input {
  width: 17px;
  height: 17px;
}
fieldset {
  min-width: 0;
  border: 0;
  padding: 0;
  margin: 0 0 22px;
}
legend {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}
.save-row {
  position: sticky;
  bottom: 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  z-index: 10;
}
.save-row p {
  font-size: 13px;
  color: var(--muted);
}
.save-row button {
  flex-shrink: 0;
}
details {
  margin-top: 22px;
}
summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  padding: 10px 0;
}
.notice {
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--soft);
  font-size: 13px;
  margin-bottom: 20px;
}
dialog {
  width: min(540px, calc(100% - 30px));
  max-height: 90dvh;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  color: var(--ink);
  padding: 28px;
}
dialog::backdrop {
  background: #172a22aa;
}
.dialog-close {
  display: block;
  margin: 0 0 20px auto;
  min-height: 44px;
  padding: 4px 12px;
  border-radius: 8px;
  background: var(--soft);
  font-size: 13px;
}
.letter-body {
  white-space: pre-wrap;
  line-height: 2.1;
  font-size: 17px;
  margin: 25px 0;
}
.letter-from {
  text-align: right;
  color: var(--muted);
  margin: 25px 0 10px;
}
.reveal-image {
  max-height: 55dvh;
  width: 100%;
  object-fit: contain;
  border-radius: 12px;
}
.detail-meta {
  font-size: 12px;
  color: var(--muted);
}
#toast {
  pointer-events: none;
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  padding: 13px 22px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  max-width: calc(100% - 30px);
  box-shadow: var(--shadow);
}
.initial-loading {
  text-align: center;
  padding: 30vh 20px;
  color: var(--muted);
}
.log-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.log-row small {
  color: var(--muted);
}
.upload-status {
  font-size: 13px;
  color: var(--muted);
  min-height: 20px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #251f23;
    --paper: #30282c;
    --ink: #f4e6e6;
    --muted: #c6adb5;
    --line: #5c454e;
    --accent: #e4a5b5;
    --accent-ink: #352028;
    --soft: #49333d;
    --bgveil: rgba(37, 31, 35, 0.92);
    --danger: #e7a09e;
    --shadow: none;
  }
  .danger {
    color: #281316;
  }
  .sample-letter {
    box-shadow: none;
  }
}
@media (max-width: 900px) {
  main {
    padding: 28px 26px 60px;
  }
  .app-layout {
    grid-template-columns: 170px minmax(0, 1fr);
  }
  .sidebar {
    padding-left: 15px;
    padding-right: 15px;
  }
  .today-grid {
    grid-template-columns: 1fr;
  }
  .letter-preview {
    min-height: 180px;
    display: block;
  }
  .letter-preview .seal {
    display: none;
  }
  .letter-preview .link {
    display: block;
    margin-top: 14px;
  }
  .auth-layout {
    gap: 45px;
  }
}
@media (max-width: 760px) {
  h1 {
    font-size: 28px;
  }
  .app-layout {
    display: block;
  }
  .sidebar {
    height: auto;
    position: static;
    display: block;
    border: 0;
    padding: calc(14px + env(safe-area-inset-top))
      max(18px, env(safe-area-inset-left)) 0;
  }
  .sidebar .wordmark {
    font-size: 23px;
  }
  .sidebar .tagline {
    display: none;
  }
  .sidebar nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    margin: 0;
    background: var(--paper);
    border-top: 1px solid var(--line);
    padding: 7px 10px calc(7px + env(safe-area-inset-bottom));
  }
  .sidebar nav button {
    text-align: center;
    padding: 10px 4px;
    min-height: 52px;
    font-size: 14px;
  }
  .sidebar-bottom {
    position: absolute;
    right: 20px;
    top: calc(18px + env(safe-area-inset-top));
    display: flex;
    gap: 12px;
    align-items: center;
  }
  .sidebar-bottom .text-button {
    font-size: 12px;
    padding: 2px 0;
  }
  main {
    padding: 12px max(18px, env(safe-area-inset-left))
      calc(100px + env(safe-area-inset-bottom))
      max(18px, env(safe-area-inset-right));
  }
  .topbar {
    padding-bottom: 14px;
    font-size: 12px;
  }
  .page-heading {
    margin-bottom: 24px;
  }
  .goal-panel {
    padding: 23px;
  }
  .calendar {
    gap: 4px;
  }
  .cal-day {
    min-height: 66px;
    padding: 7px 2px;
  }
  .cal-day .count {
    font-size: 10px;
  }
  .album-grid {
    gap: 10px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .save-row {
    bottom: calc(82px + env(safe-area-inset-bottom));
    padding: 12px;
  }
  .save-row p:empty {
    display: none;
  }
  .save-row button {
    margin-left: auto;
  }
  .auth-layout {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 32px 26px;
  }
  .welcome h1 {
    font-size: 30px;
    margin-top: 26px;
  }
  .welcome > p {
    font-size: 14px;
  }
  .sample-letter {
    display: block;
    padding: 18px;
  }
  .streak-line {
    flex-wrap: wrap;
  }
  .suggestion {
    align-items: flex-start;
  }
  .suggestion button {
    padding: 8px 11px;
    font-size: 13px;
  }
  .letter-row {
    gap: 6px 10px;
  }
  #toast {
    bottom: calc(90px + env(safe-area-inset-bottom));
  }
  dialog {
    padding: 22px;
    max-height: calc(
      100dvh - 30px - env(safe-area-inset-top) - env(safe-area-inset-bottom)
    );
    overscroll-behavior: contain;
  }
  .letter-body {
    font-size: 16px;
  }
}

@media (max-width: 380px) {
  .auth-layout {
    padding: 24px 20px;
  }
  .welcome h1 {
    font-size: 28px;
    margin: 20px 0 14px;
  }
  .welcome > p {
    font-size: 13px;
  }
  .sample-letter {
    padding: 16px;
    margin-top: 18px;
  }
  .sample-letter p {
    font-size: 14px;
    line-height: 1.65;
  }
  .welcome-actions {
    margin-top: 20px;
  }
}

/* Home is a meeting with the character, not a dashboard. */
.companion-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.companion-heading h1 {
  font-size: 27px;
  overflow-wrap: anywhere;
}
.companion-heading .text-button {
  flex-shrink: 0;
  min-height: 44px;
}
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}
.character-scene {
  height: clamp(180px, 30svh, 330px);
  overflow: hidden;
  background: var(--soft);
  border-radius: 24px 24px 6px 6px;
  display: grid;
  place-items: center;
}
.character-art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  min-height: 0;
}
.imageless-scene {
  text-align: center;
  padding: 10px;
}
.imageless-scene p {
  font-size: 20px;
  line-height: 1.6;
}
.imageless-scene .text-button {
  font-size: 13px;
  min-height: 44px;
}
.heart-mark {
  display: block;
  font-size: 40px;
  line-height: 1.2;
  color: var(--accent);
  margin-bottom: 8px;
}
.companion-speech {
  position: relative;
  margin: -12px 10px 0;
  padding: 18px 20px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 6px 18px #493b3e08;
}
.speech-name {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: baseline;
  margin-bottom: 8px;
}
.speech-name strong {
  font-size: 14px;
  overflow-wrap: anywhere;
}
.speech-name span {
  color: var(--muted);
  font-size: 11px;
}
.companion-speech > p {
  white-space: pre-wrap;
  font-size: 16px;
  line-height: 1.85;
  max-height: 26svh;
  overflow-y: auto;
}
.companion-action {
  margin-top: 22px;
}
.activity-status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}
.activity-status span {
  color: var(--muted);
  flex-shrink: 0;
}
.companion-action progress {
  width: 100%;
  display: block;
  height: 4px;
  margin: 10px 0 14px;
  accent-color: var(--accent);
  border: 0;
  border-radius: 3px;
  overflow: hidden;
  background: var(--line);
}
.companion-action progress::-webkit-progress-bar {
  background: var(--line);
}
.companion-action progress::-webkit-progress-value {
  background: var(--accent);
}
.companion-action progress::-moz-progress-bar {
  background: var(--accent);
}
.amount-picker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.amount-picker label {
  margin: 0;
  font-size: 14px;
}
.amount-picker > div {
  display: flex;
  align-items: center;
  gap: 10px;
}
.amount-picker input {
  width: 92px;
  padding: 8px 12px;
  min-height: 44px;
  text-align: center;
}
.companion-action .primary {
  min-height: 54px;
  border-radius: 16px;
  font-size: 17px;
}
.action-hint {
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  margin: 8px 0 0;
}
.record-note {
  margin-top: 2px;
}
.record-note summary {
  min-height: 44px;
  font-size: 12px;
}
.quiet-letter {
  width: 100%;
  display: flex;
  gap: 14px;
  text-align: left;
  align-items: center;
  border-top: 1px solid var(--line);
  padding: 20px 0 8px;
  margin-top: 16px;
  font-size: 14px;
}
.quiet-letter > span:first-child {
  font-size: 25px;
}
.quiet-letter > span:nth-child(2) {
  flex: 1;
}
.quiet-letter small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}
.photo > button[data-photo] {
  padding: 0;
  width: 100%;
}
.photo .text-button {
  min-height: 44px;
}
.sidebar nav button > span[aria-hidden] {
  margin-right: 8px;
}
.sidebar nav #letterBadge {
  font-size: 11px;
}
.response-speech {
  margin-top: 14px;
}
#backToCompanion {
  margin-top: 16px;
}
@media (max-width: 760px) {
  .sidebar nav {
    max-width: none;
  }
  .sidebar nav button {
    font-size: 12px;
    line-height: 1.4;
    padding: 6px 2px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  .sidebar nav button > span[aria-hidden] {
    display: block;
    font-size: 21px;
    line-height: 1.2;
    margin: 0 0 4px;
  }
  .sidebar nav button[data-page="letters"]::before {
    content: "✉";
    font-size: 21px;
    line-height: 1.2;
    margin-bottom: 4px;
  }
  #letterBadge {
    display: none;
  }
  #accountLabel {
    display: none;
  }
  .companion-heading {
    margin-bottom: 12px;
  }
  .companion-heading h1 {
    font-size: 24px;
  }
  .companion-speech {
    margin-inline: 8px;
    padding: 15px 16px;
  }
  .companion-action {
    margin-top: 18px;
  }
  .day-choices label {
    min-height: 44px;
    min-width: 44px;
  }
}
@media (max-height: 700px) and (max-width: 760px) {
  .character-scene {
    height: 180px;
  }
}
@media (prefers-reduced-motion: no-preference) {
  button,
  input {
    transition:
      background-color 0.16s,
      transform 0.16s;
  }
  dialog[open] {
    animation: appear 0.18s ease-out;
  }
  @keyframes appear {
    from {
      opacity: 0;
      transform: translateY(8px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}
/* Quiet, persistent application notices stay separate from character speech. */
.ai-notice {
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--border, #a8a8a8);
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
  text-align: left;
}
.ai-notice > strong {
  font-size: 0.75rem;
}
.ai-notice p {
  margin: 6px 0;
}
.ai-notice-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
}
.ai-notice button,
.ai-notice a,
.ai-notice summary {
  min-height: 44px;
  scroll-margin-block: 100px;
}
.ai-notice input {
  scroll-margin-block: 120px;
}
.ai-notice a {
  display: inline-flex;
  align-items: center;
}
.ai-notice details {
  margin-top: 6px;
}
.ai-notice .check {
  margin-top: 10px;
  align-items: flex-start;
}
.ai-notice input[type="checkbox"] {
  flex-shrink: 0;
}
.ai-field-focus {
  outline: 3px solid var(--accent, #ab5366) !important;
  outline-offset: 4px;
}
