:root {
  --ink: #0B4A57;
  --ink2: #3D7A8A;
  --teal: #1BA9C4;
  --tealbg: #E9F7FA;
  --yellow: #F2C94E;
  --yellowbg: #FFF7DC;
  --coral: #FF6F61;
  --coralbg: #FFE9E5;
  --gray: #8098A3;
  --bg: #FAFDFE;
  --white: #FFFFFF;
  --dash: #C9D8DC;
  --radius: 20px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E2A31;
    --white: #123A43;
    --ink: #EAF6F8;
    --ink2: #BFE0E6;
    --tealbg: #164752;
    --yellowbg: #3A331B;
    --coralbg: #4A2723;
    --gray: #8FAAB2;
    --dash: #2A5560;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.app {
  max-width: 520px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
}

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 100vh;
  padding: 8px 20px 28px;
  animation: fadein 0.25s ease;
}

.screen:not([hidden]) {
  display: flex;
}

@keyframes fadein {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
}

.badge {
  font-size: 11px;
  background: var(--coralbg);
  color: var(--coral);
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
  flex: 1 1 auto;
}

.explorer-rank {
  display: grid;
  justify-items: center;
  gap: 4px;
  min-width: 0;
  max-width: min(120px, 34vw);
  padding: 4px 6px 6px;
  border-radius: 4px;
  background:
    linear-gradient(180deg, #fffdf6 0%, #f4ecd8 100%);
  border: 1px solid #8b7355;
  box-shadow:
    inset 0 0 0 2px #f7f1e4,
    inset 0 0 0 3px #c4a574;
  color: #3d2f1f;
  line-height: 1.15;
  text-align: center;
}

.explorer-rank-image {
  display: block;
  width: 56px;
  height: 72px;
  object-fit: contain;
  object-position: center bottom;
  image-rendering: auto;
}

.explorer-rank-name {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #3d2f1f;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.explorer-rank-meta {
  display: grid;
  justify-items: center;
  gap: 1px;
  font-size: 8px;
  font-weight: 700;
  color: #7a6548;
  letter-spacing: 0.02em;
  max-width: 100%;
}

.explorer-rank-meta-line {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .explorer-rank {
    background: linear-gradient(180deg, #2a2418 0%, #1c1810 100%);
    border-color: #a89068;
    box-shadow:
      inset 0 0 0 2px #322b1e,
      inset 0 0 0 3px #8b7355;
    color: #f0e6d2;
  }

  :root:not([data-theme="light"]) .explorer-rank-name {
    color: #f0e6d2;
  }

  :root:not([data-theme="light"]) .explorer-rank-meta {
    color: #b8a078;
  }
}

.back {
  font-size: 13px;
  color: var(--ink2);
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
  padding: 8px 0;
  min-height: 44px;
}

h1 {
  font-size: 22px;
  margin: 6px 0 4px;
  font-weight: 800;
}

h2 {
  font-size: 17px;
  margin: 0 0 10px;
  font-weight: 700;
}

.lead {
  color: var(--ink2);
  font-size: 14px;
  line-height: 1.6;
  margin: 0 0 18px;
}

.home-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 18px;
}

.home-hero .lead {
  margin: 0;
}

.home-mark {
  font-size: 52px;
  line-height: 1;
}

.home-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.btn {
  font-family: inherit;
  border: none;
  border-radius: 999px;
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 80%;
}

.btn:active {
  transform: scale(0.97);
}

.btn:focus-visible,
.back:focus-visible,
.list-item:focus-visible,
.search-input:focus {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--teal);
  color: #fff;
}

.btn-yellow {
  background: var(--yellow);
  color: #0B4A57;
}

.notice {
  margin: 0;
}

.footer-note {
  margin-top: auto;
  padding-top: 16px;
  text-align: center;
  color: var(--gray);
  font-size: 11px;
  line-height: 1.6;
}

.search-input {
  width: 100%;
  border-radius: 999px;
  border: 1.5px solid var(--dash);
  padding: 13px 18px;
  font-family: inherit;
  font-size: 16px;
  background: var(--white);
  color: var(--ink);
  margin-bottom: 14px;
}

.hint {
  font-size: 13px;
  color: var(--gray);
  text-align: center;
  margin: 20px 0;
  font-weight: 700;
  line-height: 1.6;
}

.visit-hint {
  background: var(--coralbg);
  color: var(--coral);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 700;
  margin: 0 0 12px;
}

.search-results {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: var(--white);
  border: none;
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(11, 74, 87, 0.06);
  font-family: inherit;
  color: inherit;
  text-align: left;
}

.list-item:active {
  transform: scale(0.98);
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
}

.avatar.is-teal { background: var(--teal); }
.avatar.is-yellow { background: var(--yellow); color: var(--ink); }
.avatar.is-coral { background: var(--coral); }

.avatar.has-image {
  padding: 0;
  overflow: hidden;
  background: #ddd;
}

.avatar.has-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.item-copy {
  display: block;
  flex: 1;
  min-width: 0;
}

.item-title {
  display: block;
  font-weight: 700;
  font-size: 14px;
}

.item-sub {
  display: block;
  font-size: 12px;
  color: var(--gray);
  margin-top: 2px;
}

.chev {
  margin-left: auto;
  color: var(--gray);
  font-size: 18px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.photo-area {
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: 18px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--tealbg);
  color: var(--ink);
  text-align: center;
  padding: 12px;
  position: relative;
  overflow: hidden;
}

.photo-area.is-yellow { background: var(--yellowbg); }
.photo-area.is-coral { background: var(--coralbg); }

.photo-area.is-empty {
  background: transparent;
  border: 2px dashed var(--dash);
  color: var(--gray);
}

.photo-area.has-image {
  padding: 0;
  background: #111;
}

.photo-area.is-broken {
  background: var(--tealbg);
}

.photo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #111;
}

.photo-controls {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.photo-nav {
  pointer-events: auto;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.photo-counter {
  pointer-events: none;
  min-width: 64px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.photo-mark {
  margin: 0;
  font-size: 48px;
  line-height: 1;
}

.photo-label {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  margin: 0 0 10px;
  color: var(--ink2);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.6;
}

.meta-line span {
  white-space: nowrap;
}

.attr-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 12px 14px;
  background: var(--white);
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(11, 74, 87, 0.06);
}

.attr-list li {
  font-size: 14px;
  line-height: 1.6;
}

.mock-note {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--yellowbg);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.6;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 0 12px;
}

.chat-row.them-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  align-self: flex-start;
  max-width: 92%;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--teal);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  overflow: hidden;
}

.chat-avatar.has-image {
  background: #ddd;
  padding: 0;
}

.chat-avatar.has-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.bubble {
  margin: 0;
  max-width: 78%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.bubble.me {
  background: var(--teal);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.bubble.them {
  background: var(--yellowbg);
  color: var(--ink);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.chat-row.them-row .bubble.them {
  max-width: none;
  flex: 1;
  min-width: 0;
}

.bubble.choice-block {
  max-width: 92%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-row.them-row .bubble.choice-block {
  max-width: none;
}

.choice-prompt {
  margin: 0;
  font-weight: 700;
}

.choice-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.choice-btn {
  appearance: none;
  border: 1.5px solid var(--dash);
  background: var(--white);
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
}

.choice-btn:hover,
.choice-btn:focus-visible {
  border-color: var(--teal);
  outline: none;
}

.question-form {
  display: flex;
  gap: 8px;
  margin: 0 0 18px;
}

.question-form input {
  flex: 1;
  min-width: 0;
  border-radius: 999px;
  border: 1.5px solid var(--dash);
  padding: 12px 16px;
  font-family: inherit;
  font-size: 16px;
  background: var(--white);
  color: var(--ink);
}

.question-form .btn {
  width: auto;
  min-width: 72px;
  min-height: 48px;
  flex-shrink: 0;
}

.question-form.is-ng-blocked input {
  border-color: #c62828;
  background: #fff5f5;
}

.question-ng-error {
  margin: -8px 0 14px;
  color: #c62828;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
}

.related-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink2);
}

.related-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-bottom: 10px;
  padding: 10px 12px;
  border: none;
  border-radius: 16px;
  background: var(--white);
  box-shadow: 0 1px 3px rgba(11, 74, 87, 0.06);
  font-family: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.related-thumb {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tealbg);
  color: var(--ink2);
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  padding: 4px;
}

.related-thumb.is-yellow { background: var(--yellowbg); }
.related-thumb.is-coral { background: var(--coralbg); }
.related-thumb.is-empty { background: transparent; border: 1.5px dashed var(--dash); }

.related-thumb.has-image {
  padding: 0;
  overflow: hidden;
  background: #ddd;
}

.related-thumb.has-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.map-total {
  margin: -6px 0 12px;
  font-size: 15px;
  font-weight: 800;
}

.map-stage {
  position: relative;
  width: 100%;
  height: 460px;
  margin: 0 0 8px;
}

.map-stage.is-empty {
  border: 2px dashed var(--dash);
  border-radius: 18px;
}

.map-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.map-lines line {
  stroke: var(--teal);
  stroke-width: 3px;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.map-node {
  position: absolute;
  z-index: 1;
  border: none;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px;
  font-family: inherit;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(11, 74, 87, 0.16);
  transform: translate(-50%, -50%);
}

.map-node.is-teal { background: var(--teal); color: #fff; }
.map-node.is-yellow { background: var(--yellow); color: #0B4A57; }
.map-node.is-coral { background: var(--coral); color: #fff; }

.map-node.is-selected {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

.map-node:active {
  transform: translate(-50%, -50%) scale(0.97);
}

.map-node-name { font-size: 15px; }
.map-node-count { font-size: 12px; }

.map-detail { margin-top: 8px; }

.map-acc {
  margin: 0 0 8px;
  background: var(--white);
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(11, 74, 87, 0.06);
}

.map-acc summary {
  min-height: 48px;
  padding: 12px 14px;
  font-weight: 800;
  cursor: pointer;
}

.map-acc .map-acc {
  margin: 0 10px 8px;
  background: var(--yellowbg);
  box-shadow: none;
}

.map-items {
  list-style: none;
  margin: 0;
  padding: 0 10px 8px;
}

.map-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  margin: 0 0 8px;
  padding: 12px 14px;
  border: none;
  border-radius: 16px;
  background: var(--white);
  box-shadow: 0 1px 3px rgba(11, 74, 87, 0.06);
  font-family: inherit;
  font-weight: 800;
  text-align: left;
  color: inherit;
  cursor: pointer;
  min-height: 48px;
}

.map-acc .map-item {
  background: var(--bg);
}

.map-item-note {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink2);
}

.detail-history {
  margin: 0 0 18px;
}

.detail-history .btn,
.history-new,
.talk-card .btn {
  width: 100%;
}

.talk-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.talk-card {
  margin: 0 0 12px;
  padding: 14px;
  background: var(--white);
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(11, 74, 87, 0.06);
}

.talk-when {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 800;
  color: var(--ink2);
}

.talk-preview {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.talk-card .chat-log {
  margin-bottom: 12px;
}

.history-new {
  margin-top: 4px;
}

.card-login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(11, 74, 87, 0.45);
}

.card-login-overlay[hidden] {
  display: none !important;
}

.card-login-panel {
  width: min(420px, 100%);
  padding: 22px 20px;
  border-radius: 18px;
  background: var(--white);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

.card-login-panel h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.card-login-lead {
  margin: 0 0 16px;
  color: var(--ink2);
  font-size: 14px;
  line-height: 1.6;
}

.card-login-panel label {
  display: block;
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink2);
}

.card-login-panel input {
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 12px;
  padding: 12px 14px;
  border: 1.5px solid var(--dash);
  border-radius: 12px;
  font: inherit;
  font-size: 16px;
}

.card-login-error {
  margin: 0 0 12px;
  color: #c62828;
  font-size: 13px;
  font-weight: 700;
}

.card-login-panel .btn {
  width: 100%;
}

/* デモモード（?demo=1）：開発用注記のみ非表示。DOMは残す */
html.demo-mode .demo-dev-only {
  display: none !important;
}

html:not(.demo-mode) .demo-only {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .screen { animation: none; }
  .btn:active,
  .list-item:active { transform: none; }
  .map-node:active { transform: translate(-50%, -50%); }
}
