:root {
  --bg: #f6efe3;
  --surface: #ffffff;
  --surface-2: #fbf7f0;
  --text: #2b2620;
  --text-sub: #625a50;
  --line: #e2d8c8;
  --primary: #d9572b;
  --primary-dark: #b2421c;
  --primary-soft: #fde6dc;
  --accent: #2f7d5b;
  --accent-soft: #dff1e7;
  --info: #2c5f9e;
  --info-soft: #e1ebf8;
  --grass: #cfe8b5;
  --grass-dark: #a9d18a;
  --rare: #8a5a00;
  --rare-soft: #fff1c9;
  --radius: 14px;
  --tap: 48px;
  --shadow: 0 2px 8px rgba(70, 50, 20, 0.08);
  font-size: 100%;
}

html[data-text-size="l"] { font-size: 115%; }
html[data-text-size="xl"] { font-size: 130%; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--info); }

:focus-visible {
  outline: 3px solid var(--info);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -60px;
  background: var(--surface);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 100;
}
.skip-link:focus { top: 8px; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- レイアウト ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
}
.back-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  margin-left: -12px;
  border: 0;
  background: none;
  font-size: 1.4rem;
  color: var(--text);
  cursor: pointer;
  border-radius: 50%;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 120px;
}
main:focus { outline: none; }
body.no-tabbar main { padding-bottom: 40px; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  position: relative;
  flex: 1;
  max-width: 112px;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-sub);
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 600;
}
.tabbar a[aria-current="page"] {
  color: var(--primary-dark);
}
.tabbar a[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 0; left: 20%; right: 20%;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--primary);
}
.tab-icon { font-size: 1.35rem; line-height: 1; }
.tab-badge {
  position: absolute;
  top: 6px;
  left: calc(50% + 8px);
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 0.7rem;
  line-height: 20px;
  text-align: center;
}

/* ---------- 部品 ---------- */
h2 { font-size: 1.1rem; margin: 28px 0 10px; }
h2:first-child { margin-top: 4px; }
p { margin: 0 0 12px; }
.sub { color: var(--text-sub); font-size: 0.9rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 4px; font-size: 1.05rem; line-height: 1.5; }
.card-link {
  display: block;
  color: inherit;
  text-decoration: none;
}
.card-link:hover { border-color: var(--primary); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 10px 20px;
  border: 2px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-dekita {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-size: 1.05rem;
}
.btn-dekita:hover { filter: brightness(0.92); }
.btn-ghost { background: transparent; }
.btn-danger { color: #a3261b; border-color: #e7b8b2; background: #fff; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.6; cursor: wait; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn-row .btn { flex: 1 1 auto; }

.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-sub);
  margin: 0 4px 4px 0;
}
.chip-invite { background: var(--info-soft); border-color: #b9cde8; color: var(--info); }
.chip-inspired { background: var(--accent-soft); border-color: #b5dcc6; color: var(--accent); }
.chip-rare { background: var(--rare-soft); border-color: #ecd58c; color: var(--rare); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 700;
}
.status::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.status-unread { color: var(--primary-dark); }
.status-read { color: var(--text-sub); }
.status-read::before { background: transparent; border: 2px solid currentColor; width: 5px; height: 5px; }
.status-added { color: var(--info); }
.status-achieved { color: var(--accent); }

.empty {
  text-align: center;
  padding: 28px 16px;
  color: var(--text-sub);
  background: var(--surface-2);
  border: 2px dashed var(--line);
  border-radius: var(--radius);
}
.empty .big { font-size: 2.4rem; display: block; margin-bottom: 4px; }

.notice {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--info-soft);
  color: #1f466f;
  font-size: 0.9rem;
  margin-bottom: 12px;
}

/* ---------- フォーム ---------- */
.field { margin-bottom: 18px; }
.field > label, .field > .label, fieldset > legend {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
}
.field .hint { font-size: 0.85rem; color: var(--text-sub); margin: -2px 0 6px; }
.req { color: var(--primary-dark); font-size: 0.8rem; margin-left: 6px; }
.opt { color: var(--text-sub); font-size: 0.8rem; font-weight: 400; margin-left: 6px; }
input[type="text"], input[type="email"], input[type="password"], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font: inherit;
  color: inherit;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--info); outline: none; box-shadow: 0 0 0 3px var(--info-soft); }
fieldset { border: 0; padding: 0; margin: 0 0 18px; }
.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  margin-bottom: 8px;
  cursor: pointer;
}
.check input { width: 22px; height: 22px; margin: 2px 0 0; flex-shrink: 0; accent-color: var(--primary); }
.check:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.check small { display: block; color: var(--text-sub); }
.field-error { color: #a3261b; font-size: 0.88rem; font-weight: 700; margin-top: 4px; }

details.section {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px 14px;
  margin-bottom: 18px;
}
details.section > summary {
  min-height: var(--tap);
  display: flex;
  align-items: center;
  font-weight: 700;
  cursor: pointer;
}
details.section[open] > summary { margin-bottom: 8px; }

/* ---------- ようこそ ---------- */
.hero { text-align: center; padding: 24px 0 8px; }
.hero h2 { font-size: 1.6rem; margin: 12px 0 4px; }
.steps { list-style: none; padding: 0; margin: 20px 0; counter-reset: step; }
.steps li {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.steps .emo { font-size: 1.8rem; }

/* ---------- 町 ---------- */
.town-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 10px;
}
.town-header h2 { margin: 0; font-size: 1.3rem; }
.stats { display: flex; gap: 8px; margin: 0 0 14px; }
.stat {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  text-align: center;
}
.stat b { display: block; font-size: 1.4rem; line-height: 1.2; }
.stat span { font-size: 0.78rem; color: var(--text-sub); }

.town-art {
  background: linear-gradient(180deg, #f7f4ec 0%, #fbfaf6 100%);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 4px 0 8px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.town-svg { display: block; width: 100%; height: auto; }
.town-svg .bld { cursor: pointer; outline: none; }
.town-svg .bld-body { transition: transform 0.15s ease-out; }
.town-svg .bld:hover .bld-body,
.town-svg .bld:focus-visible .bld-body { transform: translateY(-3px); }
.town-svg .bld-ring { fill: transparent; stroke: transparent; stroke-width: 2.5; }
.town-svg .bld:focus-visible .bld-ring { fill: rgba(44, 95, 158, 0.12); stroke: var(--info); }
.town-svg .bld.is-new .bld-body {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: pop 0.7s ease-out;
}
.hero-town { max-width: 360px; margin: 0 auto; }

.asset-icon { display: block; width: 100%; height: 100%; }

@keyframes pop {
  0% { transform: scale(0.3); }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* ---------- 目標 ---------- */
.goal-card .memo { color: var(--text-sub); font-size: 0.9rem; margin: 6px 0 0; white-space: pre-wrap; }
.goal-card .btn-row { margin-top: 12px; }

/* ---------- 記録 ---------- */
.record-item {
  display: flex;
  align-items: center;
  gap: 12px;
}
.record-item .emo {
  width: 56px; height: 56px;
  padding: 3px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  border-radius: 12px;
  flex-shrink: 0;
}
.record-item .body { min-width: 0; }
.record-item h3 { font-size: 1rem; margin: 0; }
.record-hero { text-align: center; padding: 8px 0 4px; }
.record-hero .emo { width: 150px; height: 150px; margin: 0 auto; }
.quote {
  background: var(--surface-2);
  border-left: 4px solid var(--primary);
  border-radius: 6px;
  padding: 10px 14px;
  white-space: pre-wrap;
  margin: 8px 0 12px;
}
dl.meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; font-size: 0.92rem; }
dl.meta dt { color: var(--text-sub); }
dl.meta dd { margin: 0; }

/* ---------- 招待状 ---------- */
.invite-card { border-left: 6px solid var(--line); }
.invite-card.is-unread { border-left-color: var(--primary); }
.invite-card .shop { font-size: 0.85rem; color: var(--text-sub); margin: 0; }
.support-list { list-style: none; padding: 0; margin: 0; }
.support-list li { padding: 6px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 8px; align-items: center; }
.support-list li:last-child { border-bottom: 0; }
.support-list .mark { font-weight: 700; color: var(--accent); }
.support-list .match { margin-left: auto; font-size: 0.75rem; }

/* ---------- みんなの町 ---------- */
.mini-town { display: flex; gap: 2px; margin: 6px 0; }
.mini-town .asset-icon { width: 40px; height: 40px; }

/* ---------- プロフィール ---------- */
.profile-head { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--primary-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; font-weight: 700; color: var(--primary-dark);
  flex-shrink: 0;
}

/* ---------- メッセージ ---------- */
.conv-card { display: flex; align-items: center; gap: 12px; }
.conv-card .avatar { width: 48px; height: 48px; font-size: 1.2rem; }
.conv-card .body { flex: 1; min-width: 0; }
.conv-card h3 { margin: 0; font-size: 1rem; }
.conv-card .last { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat { list-style: none; padding: 0; margin: 12px 0 16px; display: flex; flex-direction: column; gap: 12px; }
.chat-msg { max-width: 85%; align-self: flex-start; }
.chat-msg.is-mine { align-self: flex-end; text-align: right; }
.chat-bubble {
  display: inline-block;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-msg.is-mine .chat-bubble { background: var(--primary-soft); border-color: #f2c9b7; }
.chat-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 0.78rem; color: var(--text-sub); margin-top: 2px; }
.chat-msg.is-mine .chat-meta { justify-content: flex-end; }
.btn-small { padding: 4px 14px; font-size: 0.85rem; font-weight: 600; }
.warn-list { padding-left: 1.3em; margin: 0 0 12px; font-size: 0.92rem; }
.warn-list li { margin-bottom: 4px; }

/* ---------- 規約 ---------- */
.legal h3 { font-size: 1rem; margin: 24px 0 8px; }
.legal ol, .legal ul { padding-left: 1.4em; margin: 0 0 12px; }
.legal li { margin-bottom: 4px; }
.legal-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; margin: 0 0 12px; }
.legal-table th, .legal-table td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.legal-table th { background: var(--surface-2); }
.legal-links { text-align: center; margin-top: 24px; }

/* ---------- ダイアログ ---------- */
dialog {
  width: min(92vw, 440px);
  max-height: 90vh;
  border: 0;
  border-radius: 20px;
  padding: 22px 20px 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(40, 30, 20, 0.5); }
dialog h2 { margin-top: 0; font-size: 1.2rem; }
.reward { text-align: center; }
.reward .gift { font-size: 4.5rem; display: inline-block; }
.reward .gift.shake { animation: shake 0.8s ease-in-out; }
.reward .got { width: 170px; height: 170px; display: block; margin: 0 auto; animation: pop 0.6s ease-out; transform-origin: 50% 90%; }
.reward .got-name { font-size: 1.4rem; font-weight: 800; margin: 4px 0; }
@keyframes shake {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-12deg); }
  40% { transform: rotate(12deg); }
  60% { transform: rotate(-8deg); }
  80% { transform: rotate(8deg) scale(1.1); }
}

/* ---------- トースト ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%) translateY(20px);
  background: #2b2620;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.92rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 動きを減らす ---------- */
html[data-reduce-motion="true"] *,
html[data-reduce-motion="true"] *::before,
html[data-reduce-motion="true"] *::after {
  animation: none !important;
  transition: none !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
