:root {
  --bg: #f6f1e6;
  --panel: #fffdf7;
  --panel-2: #efe9d9;
  --line: #e0d8c3;
  --ink: #35443a;
  --ink-2: #6c7a67;
  --ink-3: #9aa590;
  --accent: #4e9c68;
  --ok: #3f9e5f;
  --near: #dfa53d;
  --zone: rgba(78, 156, 104, 0.16);
  --zone-edge: rgba(78, 156, 104, 0.6);
  --gold: #e6b53f;
  --font-round: "Nunito", ui-rounded, "SF Pro Rounded", -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { color-scheme: light; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-round);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 12px;
}

header {
  width: 100%;
  max-width: 720px;
  text-align: center;
  padding: 18px 0 8px;
  border-bottom: 1px solid var(--line);
}
header h1.wordmark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.globe { font-size: 1.9rem; line-height: 1; }
.wm-text {
  font-family: var(--font-round);
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--ink);
}
.wm-text .wm-c { color: var(--accent); }
header .sub {
  margin-top: 4px;
  color: var(--ink-2);
  font-size: 0.85rem;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}
.icon-btn {
  background: var(--panel);
  color: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-weight: 700;
  cursor: pointer;
}
.icon-btn:hover { color: var(--ink); }

main {
  width: 100%;
  max-width: 720px;
  flex: 1;
  padding: 16px 0 24px;
}

/* ---- guess input ---- */
#guess-bar { display: flex; gap: 8px; }
#input-wrap { position: relative; flex: 1; }
#guess-input {
  width: 100%;
  padding: 12px 18px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  outline: none;
}
#guess-input:focus { border-color: var(--accent); }
#guess-btn {
  padding: 12px 22px;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  cursor: pointer;
}
#guess-btn:hover { background: #45905e; }
#guess-btn:disabled { opacity: 0.4; cursor: default; }

#suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  max-height: 180px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 10px 28px rgba(110, 95, 55, 0.18);
}
.suggestion {
  padding: 9px 16px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: center;
}
.suggestion.active, .suggestion:hover { background: rgba(78, 156, 104, 0.12); }
.suggestion.disabled { opacity: 0.45; cursor: default; }
.suggestion.disabled:hover { background: none; }

#status-line {
  margin: 10px 4px 26px;
  color: var(--ink-2);
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
}

/* ---- dimension axes ---- */
#axes { margin-top: 10px; display: flex; flex-direction: column; gap: 12px; }

.dim {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 16px 10px;
  box-shadow: 0 2px 8px rgba(120, 105, 70, 0.07);
}
.dim-name svg {
  width: 15px;
  height: 15px;
  vertical-align: -2.5px;
  margin-right: 6px;
  color: var(--accent);
}
.dim-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.8rem;
  color: var(--ink-2);
  margin-bottom: 4px;
}
.dim-head .dim-name { font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; font-size: 0.72rem; }
.dim-head .dim-solved { color: var(--ok); font-weight: 700; }

.track {
  position: relative;
  height: 46px;
  margin: 2px 6px;
}

.baseline {
  position: absolute;
  left: 0; right: 0;
  bottom: 13px;
  height: 2px;
  background: var(--line);
  border-radius: 1px;
}
.tick {
  position: absolute;
  bottom: 10px;
  width: 2px;
  height: 8px;
  background: var(--line);
}
.zone {
  position: absolute;
  bottom: 7px;
  height: 14px;
  background: linear-gradient(90deg, rgba(78,156,104,0.10), rgba(78,156,104,0.24), rgba(78,156,104,0.10));
  border-left: 2.5px solid var(--accent);
  border-right: 2.5px solid var(--accent);
  border-radius: 7px;
  box-shadow: 0 0 10px rgba(78, 156, 104, 0.22);
  transition: left 0.5s ease, width 0.5s ease;
  animation: zonepulse 0.9s ease-out;
}
.zone.point { background: var(--zone-edge); }
@keyframes zonepulse {
  0% { box-shadow: 0 0 18px rgba(78, 156, 104, 0.5); }
  100% { box-shadow: 0 0 10px rgba(78, 156, 104, 0.22); }
}

.axis-label {
  position: absolute;
  bottom: -4px;
  font-size: 0.68rem;
  color: var(--ink-3);
  white-space: nowrap;
}
.axis-label.min { left: 0; }
.axis-label.max { right: 0; }

.tick-label {
  position: absolute;
  bottom: -4px;
  transform: translateX(-50%);
  font-size: 0.62rem;
  color: var(--ink-3);
  white-space: nowrap;
}

.marker {
  position: absolute;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--panel);
  border: 1.5px solid #b9c2b1;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.72rem;
  white-space: nowrap;
  color: var(--ink);
  line-height: 1.35;
  z-index: 2;
  box-shadow: 0 1px 4px rgba(100, 90, 55, 0.2);
}
.marker.ghost {
  border-style: dashed;
  color: var(--ink-3);
  background: transparent;
  box-shadow: none;
}
.marker.win {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(230, 181, 63, 0.35), 0 1px 4px rgba(100, 90, 55, 0.2);
}
.marker.win .dir { color: var(--gold); }
.marker .flag { font-size: 0.9rem; }
.marker[data-name]::after {
  content: attr(data-name);
  position: absolute;
  bottom: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  border-radius: 8px;
  padding: 3px 9px;
  font-size: 0.72rem;
  color: #fffdf7;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
  z-index: 10;
}
.marker[data-name]:hover::after { opacity: 1; }
.marker .dir { font-weight: 800; }
.marker.far .dir { color: var(--ink-2); }
.marker.near { border-color: var(--near); }
.marker.near .dir { color: var(--near); }
.marker.exact { border-color: var(--ok); }
.marker.exact .dir { color: var(--ok); }
.marker.latest { box-shadow: 0 0 0 2px rgba(78, 156, 104, 0.3); }
.marker.answer {
  border-color: var(--accent);
  background: #e4f1e8;
  z-index: 3;
  box-shadow: 0 0 0 2px rgba(78, 156, 104, 0.3);
}

#axes-hint {
  margin-top: 12px;
  font-size: 0.78rem;
  color: var(--ink-3);
  text-align: center;
}
.zone-swatch {
  display: inline-block;
  width: 14px;
  height: 10px;
  background: var(--zone);
  border: 1px solid var(--zone-edge);
  border-radius: 3px;
  vertical-align: -1px;
}

/* ---- result panel ---- */
#result {
  margin: 12px 0 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(120, 105, 70, 0.07);
}
#result.won {
  border-color: var(--gold);
  box-shadow: 0 0 24px rgba(230, 181, 63, 0.25);
}
#result.won h2 { color: #c99a26; }
#result.lost { border-color: var(--near); }
#result h2 { font-size: 1.2rem; margin-bottom: 6px; }
.confetti-bit {
  position: absolute;
  top: -10px;
  width: 7px;
  height: 11px;
  border-radius: 2px;
  pointer-events: none;
  opacity: 0.95;
  animation: confetti-fall linear forwards;
  z-index: 5;
}
@keyframes confetti-fall {
  to { transform: translateY(360px) rotate(540deg); opacity: 0; }
}
#result .answer-name { font-size: 1.5rem; }
#result .facts {
  margin: 10px auto 4px;
  color: var(--ink-2);
  font-size: 0.85rem;
  line-height: 1.7;
  max-width: 460px;
}
.rbars { margin: 14px auto 2px; max-width: 460px; text-align: left; }
.rbars-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 8px;
  text-align: center;
}
.rbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.8rem;
}
.rbar-name { flex: 0 0 128px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rbar-track {
  flex: 1;
  height: 12px;
  background: var(--panel-2);
  border-radius: 6px;
  overflow: hidden;
}
.rbar-fill { height: 100%; border-radius: 6px; }
.rbar-fill.g { background: var(--ok); }
.rbar-fill.m { background: var(--near); }
.rbar-fill.w { background: #dd7a6a; }
.rbar-count { flex: 0 0 52px; text-align: right; color: var(--ink-2); font-size: 0.72rem; }

#share-panel {
  margin: 12px 0 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(120, 105, 70, 0.07);
}
#share-panel .share-preview {
  display: inline-block;
  background: var(--panel-2);
  border-radius: 12px;
  padding: 10px 16px;
}
#share-panel button {
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  display: block;
  margin: 0 auto;
}
#share-panel button:hover { background: #45905e; }
.share-box-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 8px;
}
.share-preview {
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 0 0 10px;
  white-space: pre-wrap;
  text-align: left;
}
.share-legend {
  margin-top: 10px;
  font-size: 0.7rem;
  color: var(--ink-3);
  line-height: 1.6;
}

#result .buttons { margin-top: 12px; display: flex; gap: 8px; justify-content: center; }
#result button, dialog button.primary {
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  cursor: pointer;
}
#result .countdown { margin-top: 10px; color: var(--ink-3); font-size: 0.8rem; }

/* ---- dialog ---- */
dialog {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px;
  max-width: 440px;
  margin: auto;
  box-shadow: 0 14px 40px rgba(110, 95, 55, 0.25);
}
dialog::backdrop { background: rgba(70, 60, 35, 0.4); }
dialog h2 { margin-bottom: 10px; }
dialog p { margin-bottom: 10px; font-size: 0.92rem; color: var(--ink-2); line-height: 1.5; }
dialog .ok { color: var(--ok); font-weight: 700; }
dialog form { text-align: center; margin-top: 6px; }

footer {
  width: 100%;
  max-width: 720px;
  text-align: center;
  color: var(--ink-3);
  font-size: 0.75rem;
  padding: 14px 0 18px;
  border-top: 1px solid var(--line);
}
footer a { color: var(--ink-2); }

@media (max-width: 480px) {
  .marker { font-size: 0.66rem; padding: 2px 4px; }
  .dim { padding: 10px 12px 8px; }
  /* keep the dropdown small on phones: the keyboard already eats half the
     screen, so show ~4 rows and let it scroll */
  #suggestions { max-height: 120px; }
  .suggestion { padding: 7px 14px; font-size: 0.9rem; }
}
