:root {
  --paper: #f6efe3;
  --cream: #fdfaf3;
  --card: rgba(253, 250, 243, 0.92);
  --ink: #453128;
  --muted: #8a7160;
  --line: rgba(96, 68, 50, 0.16);
  --stitch: rgba(146, 105, 72, 0.38);
  --amber: #c07f2e;
  --amber-deep: #9c6118;
  --amber-soft: #f5e3c4;
  --rose: #cf7a5f;
  --rose-soft: #f6ded4;
  --good: #4e8266;
  --shadow: 0 14px 36px rgba(96, 60, 30, 0.1);
  --display: "Yusei Magic", "Zen Maru Gothic", sans-serif;
  --body: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #251c15;
    --cream: #2e241b;
    --card: rgba(48, 38, 28, 0.92);
    --ink: #f2e7d8;
    --muted: #b39d8a;
    --line: rgba(242, 222, 195, 0.14);
    --stitch: rgba(226, 196, 158, 0.32);
    --amber: #e0a054;
    --amber-deep: #f0bc74;
    --amber-soft: #4a3820;
    --rose: #e0967d;
    --rose-soft: #4a2f27;
    --good: #8fd0a4;
    --shadow: 0 14px 36px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--paper); }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% -5%, rgba(255, 255, 255, 0.6), transparent 38%),
    var(--paper);
  font-family: var(--body);
  font-weight: 500;
  line-height: 1.7;
}
@media (prefers-color-scheme: dark) {
  body {
    background:
      radial-gradient(circle at 15% -5%, rgba(224, 160, 84, 0.08), transparent 40%),
      var(--paper);
  }
}
img { max-width: 100%; }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; border-radius: 6px; }
h1, h2, h3 { font-family: var(--display); font-weight: 400; }
h1 { margin: 0; font-size: 26px; }
h2 { margin: 0 0 12px; font-size: 18px; }
.eyebrow { margin: 0 0 4px; color: var(--amber-deep); font-size: 11px; font-weight: 700; letter-spacing: 0.2em; }

.stitch { position: relative; }
.stitch::after {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1.5px dashed var(--stitch);
  border-radius: inherit;
  pointer-events: none;
  transform: scale(0.985);
}

.card {
  padding: 18px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
}

/* ---------- shell ---------- */
.app-shell { max-width: 640px; margin: 0 auto; }
.page {
  min-height: 100dvh;
  padding: calc(20px + env(safe-area-inset-top)) 18px calc(104px + env(safe-area-inset-bottom));
  display: grid;
  gap: 14px;
  align-content: start;
}
.page[hidden] { display: none; }
.page.active { animation: appear 0.2s ease-out; }
@keyframes appear { from { opacity: 0; transform: translateY(5px); } }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.page-note { margin: -6px 0 4px; color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 48px 0; font-size: 14px; }
.empty.compact { padding: 16px 0 4px; font-size: 13px; }

/* ---------- presence ---------- */
.presence {
  padding: 14px;
  border-radius: 26px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.presence img.js-face {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 18px;
}
.presence-inline { display: grid; grid-template-columns: 42% 1fr; gap: 14px; align-items: center; }
.presence-inline img.js-face { aspect-ratio: 4 / 3; }
.mood-label { margin: 0; font-family: var(--display); font-size: 19px; }
.mood-sentence { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.conn-pill {
  display: inline-block;
  margin: 10px 0 0;
  padding: 4px 12px;
  border-radius: 99px;
  color: #96621f;
  background: var(--amber-soft);
  font-size: 11px;
  font-weight: 700;
}
.conn-pill.online { color: var(--good); background: rgba(78, 130, 102, 0.16); }
@media (prefers-color-scheme: dark) { .conn-pill { color: #f0bc74; } }

/* ---------- side (PC) ---------- */
.side { display: none; }

/* ---------- outing ---------- */
.outing-row { display: block; }
.outing-toggle {
  width: 100%;
  min-height: 56px;
  border: 0;
  border-radius: 18px;
  padding: 14px;
  color: #fffaf2;
  background: linear-gradient(160deg, var(--amber), var(--amber-deep));
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 10px 22px rgba(156, 97, 24, 0.3);
  cursor: pointer;
}
.outing-toggle.out { background: var(--ink); }
.omamori {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 16px 18px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: linear-gradient(150deg, var(--cream), var(--amber-soft));
}
.omamori img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; }
.omamori strong { font-family: var(--display); font-size: 17px; }
.omamori p { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.outing-place-row { display: flex; gap: 8px; }
.outing-place-row input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  background: var(--cream);
}

/* ---------- today / care ---------- */
.today-summary { margin: 0; font-size: 14px; }
.mirror-line {
  margin: 12px 0 0;
  padding: 12px 16px;
  border-radius: 18px 18px 18px 6px;
  background: var(--rose-soft);
  font-size: 14px;
}
.mirror-line::before { content: "モカより"; font-size: 12px; color: var(--rose); display: block; margin-bottom: 2px; font-weight: 700; }

.care-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.care-btn {
  min-height: 52px;
  padding: 10px 6px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  color: var(--ink);
  background: var(--cream);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.care-btn:active { transform: scale(0.96); background: var(--amber-soft); }
.outfit-form { margin-top: 12px; }
.outfit-form label { font-size: 12px; font-weight: 700; color: var(--muted); }
.outfit-row { display: flex; gap: 8px; margin-top: 6px; }
.outfit-row input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  background: var(--cream);
}

.moka-reply {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 18px 18px 18px 6px;
  background: var(--amber-soft);
}
.moka-reply img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; flex: none; }
.moka-reply p { margin: 2px 0 0; font-size: 14px; }
.moka-reply.pop { animation: pop 0.25s ease-out; }
@keyframes pop { from { transform: scale(0.94); opacity: 0.4; } }

/* ---------- remote ---------- */
.remote-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.remote-action {
  min-height: 62px;
  padding: 10px 13px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 15px;
  color: var(--ink);
  background: var(--cream);
  cursor: pointer;
}
.remote-action span { display: block; margin-bottom: 3px; color: var(--muted); font-size: 11px; }
.remote-action strong { font-size: 15px; }
.remote-action.active { color: #fffaf2; border-color: var(--amber-deep); background: var(--amber); }
.remote-action.active span { color: rgba(255, 250, 242, 0.8); }
.volume-label { display: flex; justify-content: space-between; margin-top: 12px; font-size: 13px; }
input[type="range"] { width: 100%; min-height: 34px; accent-color: var(--amber); }

.device-details { border-radius: 17px; border: 1px solid var(--line); background: var(--card); overflow: hidden; }
.device-details summary { min-height: 46px; padding: 13px 16px; cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 700; }
.device-details dl { margin: 0; padding: 0 16px 14px; }
.device-details dl div { display: flex; justify-content: space-between; gap: 16px; padding: 8px 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; }

/* ---------- album ---------- */
.compose-card { display: grid; gap: 8px; }
.compose-card[hidden] { display: none; }
.compose-preview { width: 100%; max-height: 300px; object-fit: cover; border-radius: 14px; }
.compose-card label { font-size: 12px; font-weight: 700; color: var(--muted); }
.compose-card input {
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  background: var(--cream);
}
.compose-actions { display: flex; gap: 10px; margin-top: 6px; }

.album-group { margin-top: 8px; }
.album-group-title {
  margin: 0 0 10px;
  font-family: var(--display);
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.album-group-title::before { content: ""; width: 18px; height: 2px; background: var(--stitch); border-radius: 2px; }
.album-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.album-item {
  overflow: hidden;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
}
.album-item img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--amber-soft); }
.album-item-body { padding: 10px 12px 12px; }
.album-item .nui-line { margin: 0 0 4px; font-size: 13px; font-weight: 700; }
.album-item .nui-line::before { content: "モカ「"; color: var(--rose); }
.album-item .nui-line::after { content: "」"; color: var(--rose); }
.album-item .caption { margin: 0; color: var(--muted); font-size: 12px; }
.album-item .meta { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.album-item-actions { display: flex; gap: 6px; padding: 0 10px 10px; }
.album-item-actions button {
  flex: 1;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: var(--cream);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.album-item-actions .share-card-btn { color: var(--amber-deep); border-color: var(--stitch); }
.album-item-actions .delete-btn.confirm { color: #fffaf2; background: #b4492f; border-color: #b4492f; }

/* ---------- about / profile ---------- */
.oshi-card {
  display: grid;
  overflow: hidden;
  border-radius: 26px;
  border: 1px solid var(--line);
  background: linear-gradient(150deg, var(--cream), var(--rose-soft));
  box-shadow: var(--shadow);
}
.oshi-face img { display: block; width: 100%; height: 100%; object-fit: cover; aspect-ratio: 4 / 3; }
.oshi-info { padding: 18px 20px 22px; }
.oshi-name { margin: 0; font-family: var(--display); font-size: 28px; }
.oshi-tagline { margin: 2px 0 14px; color: var(--rose); font-size: 13px; font-weight: 700; }
.oshi-info dl { display: grid; gap: 10px; margin: 0; }
.oshi-info dl div { display: grid; grid-template-columns: 6em 1fr; gap: 10px; }
.oshi-info dt { color: var(--muted); font-size: 12px; font-weight: 700; }
.oshi-info dd { margin: 0; font-size: 13px; }
.bday-note { display: block; color: var(--amber-deep); font-size: 12px; }

.rel-layout { display: grid; grid-template-columns: minmax(130px, 44%) 1fr; align-items: center; gap: 10px; }
.trait-chart { width: 100%; height: auto; overflow: visible; }
.trait-chart line, .trait-grid { fill: none; stroke: var(--stitch); stroke-width: 1.3; }
.trait-grid.inner { stroke-dasharray: 3 4; }
.trait-shape { fill: rgba(192, 127, 46, 0.22); stroke: var(--amber); stroke-width: 2.4; }
.personality-labels { display: flex; flex-wrap: wrap; gap: 6px; }
.personality-labels span { padding: 5px 10px; border-radius: 99px; color: var(--amber-deep); background: var(--amber-soft); font-size: 12px; font-weight: 700; }
.rel-note { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }

.mem-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.mem-list li {
  padding: 11px 14px;
  border-radius: 14px;
  background: var(--cream);
  border: 1px solid var(--line);
  font-size: 13px;
}
.mem-list li time { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.mem-list li.pinned { border-color: var(--stitch); background: var(--amber-soft); }

/* ---------- settings ---------- */
.setting-row { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.setting-row small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.setting-row.stacked { align-items: stretch; flex-direction: column; justify-content: flex-start; gap: 8px; }
.setting-inline { display: flex; gap: 8px; }
.setting-inline input {
  flex: 1;
  min-width: 0;
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: var(--cream);
}
.setting-note { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.65; }
.privacy-card p { margin: 0 0 6px; }
.switch { width: 48px; height: 28px; padding: 3px; border: 0; border-radius: 99px; background: #c9bbae; cursor: pointer; flex: none; }
.switch span { display: block; width: 22px; height: 22px; border-radius: 50%; background: #fffaf2; transition: transform 0.18s; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18); }
.switch[aria-pressed="true"] { background: var(--good); }
.switch[aria-pressed="true"] span { transform: translateX(20px); }

.btn-mini {
  min-height: 44px;
  padding: 10px 18px;
  border: 0;
  border-radius: 14px;
  color: #fffaf2;
  background: var(--ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.btn-text { min-height: 44px; border: 0; padding: 8px 12px; color: var(--muted); background: transparent; font-size: 13px; font-weight: 700; cursor: pointer; }
.site-link { display: block; text-align: center; padding: 12px; color: var(--amber-deep); font-size: 13px; font-weight: 700; text-decoration: none; }
.logout-button { width: 100%; min-height: 48px; border: 0; padding: 12px; color: var(--muted); background: transparent; font-size: 13px; cursor: pointer; }

/* ---------- tabs ---------- */
.tabbar {
  position: fixed;
  z-index: 20;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: blur(18px);
}
.nav-tab {
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  padding: 8px 4px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.nav-tab.active { color: var(--amber-deep); background: var(--amber-soft); }

/* ---------- auth / toast ---------- */
.auth-layer {
  position: fixed;
  z-index: 50;
  inset: 0;
  padding: 22px;
  display: grid;
  place-items: center;
  background: rgba(53, 40, 32, 0.4);
  backdrop-filter: blur(8px);
}
.auth-layer[hidden] { display: none; }
.auth-card {
  width: min(100%, 380px);
  padding: 26px;
  border-radius: 26px;
  background: var(--cream);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.25);
}
.auth-card h2 { font-size: 23px; }
.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: 1.5px solid var(--line);
  border-radius: 13px;
  color: var(--ink);
  background: var(--card);
}
.auth-error { min-height: 20px; margin: 4px 0 0; color: #b4492f; font-size: 13px; }
.btn-primary-wide {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  padding: 12px;
  color: #fffaf2;
  background: linear-gradient(160deg, var(--amber), var(--amber-deep));
  font-weight: 700;
  cursor: pointer;
}
.toast {
  position: fixed;
  z-index: 70;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  padding: 11px 18px;
  color: #fffaf2;
  background: var(--ink);
  border-radius: 99px;
  font-size: 13px;
  transition: 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- PC layout ---------- */
@media (min-width: 1024px) {
  .app-shell {
    max-width: 1240px;
    display: grid;
    grid-template-columns: 330px 1fr;
    gap: 30px;
    padding: 28px 34px;
    align-items: start;
  }
  .side { display: block; }
  .side-inner { position: sticky; top: 28px; display: grid; gap: 16px; }
  .side-brand { margin: 0; font-family: var(--display); font-size: 22px; }
  .side .presence { display: grid; gap: 8px; }
  .side .mood-label { margin-top: 6px; }
  .side-nav { display: grid; gap: 6px; }
  .side-nav .nav-tab { text-align: left; padding: 12px 16px; font-size: 14px; }
  .side-conn { margin: 0; color: var(--muted); font-size: 12px; }
  .tabbar { display: none; }
  .presence-inline { display: none; }
  .page { min-height: auto; padding: 0 0 60px; }
  .pages .outing-row { display: none; } /* outing toggle lives in the sidebar */
  .album-grid { grid-template-columns: repeat(3, 1fr); }
  .oshi-card { grid-template-columns: 42% 1fr; }
  .oshi-face img { aspect-ratio: auto; height: 100%; }
  .care-grid { grid-template-columns: repeat(6, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .page.active, .moka-reply.pop { animation: none; }
  .switch span { transition: none; }
  .toast { transition: none; }
}
