:root {
  /* Defaults mirror config.json palette; app.js overwrites these at runtime
     so palette changes only ever require editing config.json. */
  --yellow: #F6B93B;
  --yellowd: #E09A1E;
  --orange: #F58E4E;
  --oranged: #E0703A;
  --cream: #FFFBF3;
  --card: #FFFFFF;
  --ink: #5b4a37;
  --mut: #a3927c;
  --line: #f0e6d4;
  --good: #67B26F;
  --ok: #F0A93B;
  --weak: #EB7C6A;

  --bg: var(--cream);
  --surface: var(--card);
  --surface-soft: #FBF1DE;
  --text: var(--ink);
  --text-soft: var(--mut);
  --border: var(--line);
  --shadow: 0 6px 18px rgba(91, 74, 55, 0.10);
  --shadow-lg: 0 -8px 28px rgba(91, 74, 55, 0.20);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="dark"] {
  --bg: #211a12;
  --surface: #2c2318;
  --surface-soft: #362b1c;
  --text: #f6ecd9;
  --text-soft: #c2ac8c;
  --border: rgba(246, 236, 217, 0.12);
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 -8px 28px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #211a12;
    --surface: #2c2318;
    --surface-soft: #362b1c;
    --text: #f6ecd9;
    --text-soft: #c2ac8c;
    --border: rgba(246, 236, 217, 0.12);
    --shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 -8px 28px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
  font-family: "M PLUS Rounded 1c", "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Rounded Mplus 1c", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* ---------- Header ---------- */
.app-header {
  flex: 0 0 auto;
  padding: 12px 16px 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  font-size: 1.8rem;
  line-height: 1;
}

.brand-text h1 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.brand-text p {
  margin: 1px 0 0;
  font-size: 0.72rem;
  color: var(--text-soft);
  font-weight: 500;
}

/* ---------- Chip row ---------- */
.chip-row {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 16px 10px;
  scrollbar-width: none;
}

.chip-row::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chip:active {
  transform: scale(0.96);
}

.chip .chip-icon {
  font-size: 1.05rem;
}

.chip.is-on {
  background: var(--chip-color, var(--orange));
  border-color: var(--chip-color, var(--orange));
  color: #fff;
}

/* ---------- Segment control ---------- */
.segment {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  margin: 0 16px 10px;
  padding: 4px;
  background: var(--surface-soft);
  border-radius: 16px;
}

.segment-btn {
  flex: 1;
  padding: 9px 0;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text-soft);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.segment-btn.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ---------- Main view area ---------- */
.view-area {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  padding: 0 16px;
}

.view {
  display: none;
  height: 100%;
  min-height: 0;
}

.view.is-active {
  display: block;
}

#view-map.is-active {
  display: flex;
  flex-direction: column;
}

/* ---------- List ---------- */
.list-body {
  list-style: none;
  margin: 0;
  padding: 2px 2px 14px;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.m-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-radius: 18px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.m-card:active {
  transform: scale(0.98);
}

.m-card.is-top {
  border-color: var(--yellow);
  background: linear-gradient(135deg, rgba(246, 185, 59, 0.16), var(--surface) 55%);
}

.m-rank {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  background: var(--surface-soft);
  color: var(--text-soft);
}

.m-card.is-top .m-rank {
  background: var(--yellow);
  color: #fff;
}

.m-main {
  flex: 1 1 auto;
  min-width: 0;
}

.m-name-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.m-name {
  font-size: 1rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-zone {
  font-size: 0.68rem;
  color: var(--text-soft);
  flex: 0 0 auto;
}

.m-score-row {
  display: flex;
  align-items: baseline;
  gap: 3px;
  margin-top: 1px;
}

.m-score {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--oranged);
}

.m-score-label {
  font-size: 0.66rem;
  color: var(--text-soft);
}

.m-icons {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
}

.m-icon-badge {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 800;
  color: #fff;
}

.badge-good { background: var(--good); }
.badge-ok { background: var(--ok); }
.badge-weak { background: var(--weak); }

.m-chevron {
  flex: 0 0 auto;
  color: var(--text-soft);
  font-size: 1.1rem;
}

/* ---------- Map ---------- */
#view-map {
  gap: 8px;
  padding-bottom: 10px;
}

#map {
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--surface-soft);
}

.leaflet-container {
  background: var(--surface-soft);
  font-family: inherit;
}

.map-legend {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.68rem;
  color: var(--text-soft);
  font-weight: 600;
  padding: 2px 4px;
}

.legend-bar {
  flex: 1 1 auto;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--legend-from, #eee), var(--legend-to, #333));
}

.zone-tooltip {
  font-weight: 800;
  font-size: 0.72rem;
  padding: 2px 8px;
  font-family: inherit;
}

/* ---------- Footer ---------- */
.app-footer {
  flex: 0 0 auto;
  text-align: center;
  padding: 4px 12px 8px;
}

.app-footer p {
  margin: 0;
  font-size: 0.62rem;
  color: var(--text-soft);
}

/* ---------- Bottom sheet ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(60, 45, 25, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  z-index: 40;
}

.sheet-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 82dvh;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow-lg);
  transform: translateY(100%);
  transition: transform 0.26s cubic-bezier(0.32, 0.72, 0.35, 1);
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--safe-bottom) + 10px);
}

.sheet.is-open {
  transform: translateY(0);
}

.sheet-grab {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  padding: 10px 0 6px;
  cursor: grab;
  touch-action: none;
}

.sheet-grab span {
  width: 42px;
  height: 5px;
  border-radius: 999px;
  background: var(--border);
}

.sheet-content {
  overflow-y: auto;
  padding: 0 20px 8px;
  -webkit-overflow-scrolling: touch;
}

.sheet-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.sheet-title {
  font-size: 1.2rem;
  font-weight: 800;
  margin: 0;
}

.sheet-rank {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-soft);
  background: var(--surface-soft);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}

.sheet-zone {
  margin: 0 0 14px;
  font-size: 0.78rem;
  color: var(--text-soft);
  font-weight: 500;
}

.sheet-bars {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}

.bar-row .bar-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
  font-size: 0.84rem;
  font-weight: 700;
}

.bar-head .bar-icon {
  font-size: 1rem;
}

.bar-head .bar-mark {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 1px 9px;
  border-radius: 999px;
  color: #fff;
}

.bar-track {
  height: 11px;
  border-radius: 999px;
  background: var(--surface-soft);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

.bar-value {
  margin-top: 3px;
  font-size: 0.68rem;
  color: var(--text-soft);
  text-align: right;
}

.sendout-row {
  display: flex;
  gap: 8px;
  padding-bottom: 4px;
}

.sendout-btn {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 11px 4px;
  border-radius: 16px;
  background: var(--surface-soft);
  color: var(--text);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
  transition: transform 0.12s ease;
}

.sendout-btn:active {
  transform: scale(0.96);
}

.sendout-btn .sendout-sub {
  font-size: 0.62rem;
  font-weight: 500;
  color: var(--text-soft);
}

/* ---------- Small screens ---------- */
@media (max-height: 640px) {
  .brand-text h1 { font-size: 0.95rem; }
  .brand-text p { font-size: 0.66rem; }
  .m-card { padding: 8px 10px; }
}

/* --- brand assets (logo + mascot) --- */
.brand-logo-img{width:38px;height:38px;border-radius:12px;object-fit:cover;flex:none;box-shadow:0 2px 6px rgba(224,112,58,.18)}
.app-footer{display:flex;align-items:center;gap:8px;justify-content:center}
.footer-mascot{width:26px;height:26px;border-radius:50%;object-fit:cover;flex:none}

/* --- 地図: 空白を"海"に見せてバグ感を消す --- */
.leaflet-container{background:#dceef3 !important}
@media (prefers-color-scheme:dark){.leaflet-container{background:#1a2a30 !important}}
#map{border-radius:14px;overflow:hidden}

/* --- B: チップ右端フェード（横スクロール合図） --- */
.chip-row{-webkit-mask-image:linear-gradient(90deg,#000 86%,transparent);mask-image:linear-gradient(90deg,#000 86%,transparent)}

/* --- B: 初回オンボーディング（シーサーの吹き出し） --- */
.onboard{position:fixed;inset:0;background:rgba(60,45,30,.42);display:flex;align-items:center;justify-content:center;z-index:9999;padding:24px}
.onboard[hidden]{display:none}
.onboard-card{background:#fff;border-radius:22px;max-width:330px;width:100%;padding:22px 20px 18px;text-align:center;box-shadow:0 12px 40px rgba(60,45,30,.28)}
.onboard-card img{width:96px;height:96px;object-fit:contain;margin-top:-58px}
.onboard-card h3{font-size:18px;font-weight:800;margin:6px 0 4px;color:#5b4a37}
.onboard-steps{text-align:left;font-size:14px;line-height:1.9;color:#6b5945;margin:10px 4px 4px}
.onboard-steps b{color:#e0703a}
.onboard-btn{margin-top:16px;width:100%;border:0;background:#F6B93B;color:#fff;font-weight:800;font-size:15px;padding:13px;border-radius:14px;cursor:pointer;font-family:inherit}
@media (prefers-color-scheme:dark){.onboard-card{background:#22292e;color:#e7eef0}.onboard-card h3{color:#e7eef0}.onboard-steps{color:#c8d2d6}}
