:root {
  color-scheme: dark;
  --background: #101412;
  --glass: rgba(16, 22, 19, 0.68);
  --glass-strong: rgba(16, 22, 19, 0.84);
  --text: #f4f7f3;
  --muted: #bac5be;
  --border: rgba(255, 255, 255, 0.18);
  --accent: #1f8b70;
  --accent-strong: #176b57;
  --accent-soft: rgba(31, 139, 112, 0.24);
  --danger: #cf4d4d;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.34);
  --hud-z-index: 20;
  --panel-z-index: 18;
  --modal-z-index: 40;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  overflow: hidden;
  background: var(--background);
  color: var(--text);
  font-family:
    "Avenir Next",
    "Hiragino Sans",
    "Yu Gothic",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 0 14px;
  transition:
    background 180ms ease,
    border-color 180ms ease,
    transform 180ms ease;
}

button:hover:not(:disabled) {
  border-color: rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.18);
}

button:active:not(:disabled) {
  transform: translateY(1px) scale(0.99);
}

button:focus-visible {
  outline: 3px solid rgba(31, 139, 112, 0.55);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.primary-button {
  border-color: rgba(31, 139, 112, 0.78);
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover:not(:disabled) {
  border-color: rgba(45, 170, 138, 0.95);
  background: var(--accent-strong);
}

.game-shell {
  position: relative;
  min-height: 100dvh;
  overflow: hidden;
  background: #141a17;
}

.street-stage,
.street-frame,
.street-frame iframe {
  position: absolute;
  inset: 0;
}

.street-frame {
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(31, 139, 112, 0.18), rgba(39, 55, 64, 0.2)),
    #202923;
}

.street-frame iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #202923;
}

.street-empty {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 28px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 42%, rgba(31, 139, 112, 0.2), transparent 28rem),
    rgba(16, 20, 18, 0.78);
}

.street-empty strong {
  font-size: clamp(20px, 3vw, 32px);
  line-height: 1.18;
}

.street-empty span {
  max-width: 36rem;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.street-empty.is-hidden {
  display: none;
}

.protocol-warning {
  background: rgba(16, 20, 18, 0.88);
}

.hud-header {
  position: absolute;
  z-index: var(--hud-z-index);
  top: 14px;
  right: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 68px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--glass);
  box-shadow: var(--shadow);
  padding: 12px 16px;
  backdrop-filter: blur(18px) saturate(1.12);
}

.hud-brand {
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: clamp(18px, 2.2vw, 28px);
  line-height: 1.1;
  letter-spacing: 0;
}

.hud-status {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.hud-status span {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.08);
  padding: 7px 10px;
}

.hud-status strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.answer-panel {
  position: absolute;
  z-index: var(--panel-z-index);
  right: 16px;
  bottom: 16px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: clamp(330px, 31vw, 440px);
  height: clamp(330px, 42vh, 500px);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--glass-strong);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(1.08);
  transition:
    width 220ms ease,
    height 220ms ease,
    transform 220ms ease;
}

.answer-panel.is-result {
  z-index: calc(var(--modal-z-index) + 1);
  top: 50%;
  right: auto;
  bottom: auto;
  left: 50%;
  width: min(900px, calc(100vw - 48px));
  height: min(650px, calc(100dvh - 130px));
  transform: translate(-50%, -50%);
}

.answer-panel.is-resizing {
  transition: none;
}

.caption {
  display: block;
  color: var(--text);
  font-size: 12px;
  font-weight: 850;
}

.guess-map {
  position: relative;
  overflow: hidden;
  min-height: 0;
  background: #d7e4df;
}

.guess-map:focus-visible {
  outline: 3px solid rgba(31, 139, 112, 0.55);
  outline-offset: -3px;
}

.map-layer-tabs {
  display: flex;
  overflow: hidden;
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
  background: rgba(12, 18, 15, 0.72);
  padding-left: 32px;
}

.answer-resize-handle {
  position: absolute;
  z-index: 510;
  top: 0;
  left: 0;
  width: 32px;
  min-height: 38px;
  border: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0;
  background:
    linear-gradient(135deg, transparent 0 35%, rgba(255, 255, 255, 0.28) 35% 42%, transparent 42%),
    linear-gradient(135deg, transparent 0 52%, rgba(255, 255, 255, 0.22) 52% 58%, transparent 58%),
    rgba(255, 255, 255, 0.08);
  box-shadow: none;
  cursor: nwse-resize;
  padding: 0;
  touch-action: none;
}

.answer-resize-handle:hover:not(:disabled) {
  border-color: rgba(255, 255, 255, 0.16);
  background:
    linear-gradient(135deg, transparent 0 35%, rgba(255, 255, 255, 0.42) 35% 42%, transparent 42%),
    linear-gradient(135deg, transparent 0 52%, rgba(255, 255, 255, 0.34) 52% 58%, transparent 58%),
    rgba(255, 255, 255, 0.12);
}

.answer-resize-handle:active:not(:disabled) {
  transform: none;
}

.answer-panel.is-result .answer-resize-handle {
  display: none;
}

.map-layer-tab {
  flex: 1 1 0;
  min-height: 38px;
  min-width: 0;
  border: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  padding: 0 6px;
  white-space: nowrap;
}

.map-layer-tab:last-child {
  border-right: 0;
}

.map-layer-tab:hover:not(:disabled) {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
}

.map-layer-tab.is-active {
  background: var(--accent);
  color: #ffffff;
}

.map-debug-toggle {
  position: absolute;
  z-index: 500;
  top: 48px;
  right: 10px;
  min-height: 30px;
  border-color: rgba(24, 32, 27, 0.18);
  background: rgba(255, 255, 255, 0.9);
  color: #18201b;
  box-shadow: 0 3px 12px rgba(17, 27, 22, 0.18);
  font-size: 12px;
  line-height: 1;
  padding: 0 10px;
}

.map-debug-toggle:hover:not(:disabled) {
  border-color: rgba(24, 32, 27, 0.3);
  background: #ffffff;
}

.map-debug-toggle.is-active {
  border-color: rgba(207, 77, 77, 0.9);
  background: rgba(207, 77, 77, 0.94);
  color: #ffffff;
}

.guess-marker-icon,
.answer-marker-icon {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.guess-marker-icon {
  border: 2px solid #ffffff;
  background: var(--accent);
  box-shadow: 0 3px 14px rgba(11, 74, 60, 0.45);
}

.answer-marker-icon {
  border: 2px solid #ffffff;
  background: var(--danger);
  box-shadow: 0 3px 14px rgba(153, 28, 28, 0.42);
}

.leaflet-container {
  font-family: inherit;
  cursor: crosshair;
}

.leaflet-control-zoom {
  border: 0 !important;
  box-shadow: 0 3px 12px rgba(17, 27, 22, 0.18) !important;
}

.leaflet-control-zoom a {
  border-color: rgba(20, 34, 29, 0.16) !important;
  background: rgba(255, 255, 255, 0.94) !important;
  color: #18201b !important;
}

.leaflet-control-zoom a:hover {
  background: #ffffff !important;
}

.leaflet-control-attribution {
  border-radius: 4px 0 0;
  background: rgba(255, 255, 255, 0.78) !important;
  color: rgba(24, 32, 27, 0.82);
  font-size: 10px;
  font-weight: 700;
}

.leaflet-control-attribution a {
  color: rgba(24, 32, 27, 0.9);
}

.answer-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 58px;
  border-top: 1px solid rgba(255, 255, 255, 0.13);
  padding: 10px 12px;
}

.answer-footer .primary-button {
  width: 100%;
}

.answer-footer .is-hidden,
.primary-button.is-hidden {
  display: none;
}

.result-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.result-summary p {
  margin: 4px 0 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
}

.result-modal {
  position: fixed;
  inset: 0;
  z-index: var(--modal-z-index);
  background: rgba(7, 10, 8, 0.58);
  backdrop-filter: blur(6px);
}

.result-modal.is-hidden {
  display: none;
}

@media (max-width: 820px) {
  body {
    overflow: hidden;
  }

  .hud-header {
    top: 10px;
    right: 10px;
    left: 10px;
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    padding: 12px;
  }

  .hud-status {
    width: 100%;
    justify-content: stretch;
  }

  .hud-status span {
    flex: 1;
    justify-content: center;
    padding: 7px 8px;
  }

  .answer-panel {
    right: 10px;
    bottom: 10px;
    left: 10px;
    width: auto;
    height: min(42dvh, 390px);
  }

  .answer-panel.is-result {
    top: auto;
    right: 10px;
    bottom: 10px;
    left: 10px;
    width: auto;
    height: min(62dvh, 560px);
    transform: none;
  }

  .result-summary {
    grid-template-columns: 1fr;
  }

  .map-layer-tabs {
    padding-left: 0;
    overflow-x: auto;
  }

  .answer-resize-handle {
    display: none;
  }
}

@media (max-width: 520px) {
  .hud-status {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .hud-status span:first-child {
    grid-column: 1 / -1;
  }

  .answer-panel {
    height: 40dvh;
  }

  .answer-footer .primary-button {
    width: 100%;
  }
}
