:root {
  --bg: #0f1a12;
  --panel: rgba(18, 32, 22, 0.92);
  --ink: #e8f0e4;
  --muted: #9bb39a;
  --accent: #c8e07a;
  --accent-dim: #6a8f3a;
  --danger: #e8a070;
  --sheet-bg: #152419;
  --radius: 16px;
  --top-h: calc(148px + env(safe-area-inset-top, 0px));
  --font-display: "Avenir Next", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC",
    sans-serif;
  --font-body: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  display: grid;
  grid-template-rows: auto 1fr;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.top-bar {
  z-index: 1000;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "brand count"
    "modes modes"
    "layers layers"
    "hide hide";
  gap: 6px 12px;
  align-items: center;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 10px;
  background: linear-gradient(180deg, #1c3320 0%, #142218 100%);
  border-bottom: 1px solid rgba(200, 224, 122, 0.18);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.mode-switch {
  grid-area: modes;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.mode-btn {
  appearance: none;
  border: 1px solid rgba(200, 224, 122, 0.35);
  background: rgba(0, 0, 0, 0.2);
  color: var(--muted);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.92rem;
  font-weight: 700;
  min-height: 40px;
}

.mode-btn.is-active {
  background: linear-gradient(180deg, #8aad4a, #5f8230);
  border-color: transparent;
  color: #f4ffe8;
}

.brand {
  grid-area: brand;
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.count {
  grid-area: count;
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: right;
}

.hide-found {
  grid-area: hide;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 36px;
  user-select: none;
}

.hide-found input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-dim);
}

.layer-switch {
  grid-area: layers;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.layer-btn {
  appearance: none;
  border: 1px solid rgba(200, 224, 122, 0.25);
  background: rgba(0, 0, 0, 0.25);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 10px;
  font-size: 0.9rem;
  font-weight: 600;
  min-height: 40px;
}

.layer-btn.is-active {
  background: linear-gradient(180deg, #6f9a3a, #4a6f28);
  border-color: transparent;
  color: #f4ffe8;
}

.map {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #0a120c;
}

.attribution {
  position: fixed;
  left: 8px;
  bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  z-index: 900;
  margin: 0;
  max-width: calc(100% - 16px);
  font-size: 10px;
  line-height: 1.35;
  color: rgba(232, 240, 228, 0.75);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

.attribution a {
  color: var(--accent);
  pointer-events: auto;
}

/* Korok markers */
.korok-icon {
  width: 28px !important;
  height: 28px !important;
  margin-left: -14px !important;
  margin-top: -14px !important;
  border: none;
  background: transparent;
}

.korok-icon img {
  width: 28px;
  height: 28px;
  display: block;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.7));
}

.korok-icon.is-found img {
  opacity: 0.38;
  filter: grayscale(1) drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background-color: rgba(106, 143, 58, 0.35);
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background-color: rgba(106, 143, 58, 0.85);
  color: #f4ffe8;
  font-weight: 700;
}

/* Bottom sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(0, 0, 0, 0.45);
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1200;
  max-height: min(72vh, 520px);
  padding: 10px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, #1c3020 0%, var(--sheet-bg) 40%);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
  transform: translateY(110%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

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

.sheet-handle {
  width: 42px;
  height: 4px;
  margin: 2px auto 10px;
  border-radius: 999px;
  background: rgba(232, 240, 228, 0.28);
}

.sheet-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font-size: 1.4rem;
  line-height: 1;
}

.sheet-title {
  margin: 0 40px 12px 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--accent);
}

.sheet-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
  margin: 0 0 14px;
}

.sheet-meta dt {
  margin: 0;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: none;
}

.sheet-meta dd {
  margin: 2px 0 0;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.sheet-howto h3 {
  margin: 0 0 6px;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.sheet-howto p {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.55;
}

.guide-note {
  margin-top: 8px !important;
  font-size: 0.8rem !important;
  color: var(--danger);
}

.found-check {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(200, 224, 122, 0.1);
  border: 1px solid rgba(200, 224, 122, 0.28);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent);
  min-height: 48px;
  user-select: none;
}

.found-check input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent-dim);
}

body.sheet-open .map {
  pointer-events: none;
}

/* Armor mode */
.armor-panel {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--top-h);
  bottom: 0;
  z-index: 950;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #142218 0%, #0f1a12 100%);
  border-top: 1px solid rgba(200, 224, 122, 0.18);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.armor-panel[hidden] {
  display: none !important;
}

body.mode-armor .map {
  visibility: hidden;
}

body.mode-armor .attribution {
  display: none;
}

.armor-toolbar {
  padding: 10px 12px 6px;
  flex: 0 0 auto;
}

.armor-search {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(200, 224, 122, 0.28);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink);
  font-size: 1rem;
  padding: 12px 14px;
  min-height: 44px;
  outline: none;
}

.armor-search::placeholder {
  color: var(--muted);
}

.armor-list {
  flex: 1 1 auto;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 10px 16px;
}

.armor-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  appearance: none;
  border: none;
  border-bottom: 1px solid rgba(200, 224, 122, 0.12);
  background: transparent;
  color: var(--ink);
  padding: 14px 10px;
  min-height: 56px;
}

.armor-item:active {
  background: rgba(200, 224, 122, 0.08);
}

.armor-item-name {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
}

.armor-item-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.armor-empty {
  margin: 24px 12px;
  color: var(--muted);
  text-align: center;
}

.armor-desc {
  margin: 0 0 12px;
  font-size: 0.95rem;
  line-height: 1.55;
}

.armor-pieces h3,
.armor-upgrade-block h3 {
  margin: 14px 0 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.armor-piece {
  padding: 12px 0;
  border-top: 1px solid rgba(200, 224, 122, 0.12);
}

.armor-piece header {
  margin-bottom: 6px;
}

.armor-def,
.armor-effect {
  margin: 0 0 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.armor-piece p {
  margin: 0 0 8px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.owned-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 4px 12px 8px 0;
  font-size: 0.95rem;
  color: var(--accent);
  min-height: 40px;
  user-select: none;
}

.owned-check input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent-dim);
}

.locate-btn {
  appearance: none;
  border: 1px solid rgba(200, 224, 122, 0.4);
  background: rgba(106, 143, 58, 0.25);
  color: var(--accent);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  min-height: 40px;
}

.armor-upgrades {
  margin: 0;
  padding-left: 1.1em;
  font-size: 0.9rem;
  line-height: 1.5;
}

.armor-upgrades li {
  margin-bottom: 6px;
}

.armor-note {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.armor-back-map {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 1000;
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 12px 20px;
  min-height: 44px;
  font-weight: 700;
  color: #f4ffe8;
  background: linear-gradient(180deg, #6f9a3a, #4a6f28);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.armor-back-map[hidden] {
  display: none !important;
}

.armor-pin {
  background: transparent;
  border: none;
}

.armor-pin-dot {
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #e8c070;
  border: 2px solid #1a2e1a;
  box-shadow: 0 0 0 3px rgba(232, 192, 112, 0.35);
}

.sheet.is-open {
  max-height: min(85vh, 640px);
}

@media (min-width: 720px) {
  .top-bar {
    grid-template-columns: auto auto 1fr auto;
    grid-template-areas:
      "brand modes layers count"
      "hide hide hide hide";
  }

  .mode-switch {
    min-width: 180px;
  }

  .layer-switch {
    max-width: 360px;
    justify-self: center;
  }

  .hide-found {
    justify-self: end;
  }

  .armor-panel {
    left: auto;
    width: min(420px, 100%);
    right: 0;
    top: var(--top-h);
    height: auto;
    bottom: 0;
    max-height: none;
    border-left: 1px solid rgba(200, 224, 122, 0.18);
    border-top: none;
  }

  body.mode-armor .map {
    visibility: visible;
  }
}
