/* style.css — Adivina el País del Día */

[hidden] { display: none !important; }

:root {
  --bg: #f4f7f5;
  --bg-card: #ffffff;
  --text: #1a2420;
  --text-muted: #5a6a63;
  --accent: #1b6f5c;
  --accent-strong: #145447;
  --accent-contrast: #ffffff;
  --border: #dde5e1;
  --input-bg: #ffffff;
  --suggestion-hover: #eef5f1;
  --dot-empty: #dde5e1;
  --dot-correct: #2f9e6e;
  --dot-wrong: #d9534f;
  --tier-correct: #2f9e6e;
  --tier-hot: #f0a83c;
  --tier-warm: #e8d54a;
  --tier-cold: #d9534f;
  --shadow: 0 10px 26px rgba(20, 40, 32, 0.14);
  --radius: 10px;
  --mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10201b;
    --bg-card: #16302a;
    --text: #eaf3ef;
    --text-muted: #a3b8b0;
    --accent: #3fbf9a;
    --accent-strong: #58d6b3;
    --accent-contrast: #08130f;
    --border: #26483d;
    --input-bg: #10241e;
    --suggestion-hover: #1d3b32;
    --dot-empty: #26483d;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg: #10201b;
  --bg-card: #16302a;
  --text: #eaf3ef;
  --text-muted: #a3b8b0;
  --accent: #3fbf9a;
  --accent-strong: #58d6b3;
  --accent-contrast: #08130f;
  --border: #26483d;
  --input-bg: #10241e;
  --suggestion-hover: #1d3b32;
  --dot-empty: #26483d;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
}

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

a { color: var(--accent); }

/* Header */
.app-header {
  background: var(--accent);
  color: var(--accent-contrast);
  padding-top: calc(10px + var(--safe-top));
  padding-left: calc(12px + var(--safe-left));
  padding-right: calc(12px + var(--safe-right));
  padding-bottom: 10px;
}
.header-inner {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 1.6rem; line-height: 1; }
.brand h1 { font-size: 1.08rem; margin: 0; font-weight: 800; letter-spacing: -0.01em; }
.tagline { margin: 1px 0 0; font-size: 0.72rem; opacity: 0.8; font-family: var(--mono); letter-spacing: 0.02em; }
.header-actions { display: flex; gap: 2px; flex-wrap: wrap; }
.icon-btn {
  min-width: 44px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--accent-contrast);
  font-size: 1.05rem;
  cursor: pointer;
  touch-action: manipulation;
  opacity: 0.9;
}
.icon-btn:hover { background: rgba(255,255,255,0.14); opacity: 1; }
.icon-btn:active { transform: scale(0.95); }

/* Main layout */
.app-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px calc(14px + var(--safe-left)) 40px calc(14px + var(--safe-right));
}

.practice-banner {
  background: var(--tier-hot);
  color: #2b1c00;
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  flex-wrap: wrap;
}
.link-btn {
  background: none; border: none;
  color: inherit;
  text-decoration: underline;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
  padding: 0 4px;
}

.puzzle-number {
  text-align: center;
  font-family: var(--mono);
  font-weight: 500;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 2px 0 14px;
}

/* Silhouette */
.silhouette-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 18px;
}
.silhouette-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 46vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
@media (max-height: 480px) {
  .silhouette-wrap { max-height: 30vh; }
  .silhouette-card { padding: 10px; margin-bottom: 10px; }
  .puzzle-number { margin: 0 0 8px; }
}
#silhouette-svg {
  width: 100%;
  height: 100%;
  display: block;
}
.silhouette-path {
  fill: var(--accent);
  fill-opacity: 0.92;
  stroke: var(--accent-strong);
  stroke-width: 1.2;
  stroke-linejoin: round;
  transition: fill 0.2s ease;
}
.silhouette-path.revealed {
  fill: var(--tier-correct);
}

.attempts-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}
.attempt-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--dot-empty);
  border: 2px solid var(--border);
}
.attempt-dot.used-correct { background: var(--dot-correct); border-color: var(--dot-correct); }
.attempt-dot.used-wrong { background: var(--dot-wrong); border-color: var(--dot-wrong); }
.attempt-dot.current { border-color: var(--accent); }

/* Guess form */
.guess-section { margin-bottom: 16px; }
#guess-form {
  display: flex;
  gap: 8px;
}
.autocomplete-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}
#guess-input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  font-size: 1rem;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-family: inherit;
}
#guess-input:focus {
  outline: none;
  border-color: var(--accent);
}
.suggestions-list {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0; right: 0;
  margin: 0; padding: 6px;
  list-style: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: min(260px, 45vh);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.suggestions-list.suggestions-list--above {
  top: auto;
  bottom: calc(100% + 4px);
}
.suggestion-item {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.98rem;
}
.suggestion-item .flag { font-size: 1.2rem; }
.suggestion-item:hover,
.suggestion-item.active {
  background: var(--suggestion-hover);
}
.suggestion-item.disabled {
  opacity: 0.5;
  cursor: default;
}

.primary-btn {
  min-height: 48px;
  padding: 0 18px;
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 0.98rem;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}
.primary-btn:hover { background: var(--accent-strong); }
.primary-btn:active { transform: scale(0.98); }
.primary-btn:disabled { opacity: 0.5; cursor: default; }

.status-message {
  min-height: 1.2em;
  margin: 8px 2px 0;
  font-weight: 600;
  font-size: 0.92rem;
}
.status-message.error { color: var(--tier-cold); }
.status-message.ok { color: var(--tier-correct); }

/* Guesses list */
.guesses-section { margin-bottom: 16px; }
.guesses-list {
  list-style: none;
  margin: 0; padding: 0;
  border-top: 1px solid var(--border);
}
.guess-row {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 10px 2px;
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}
.guess-row.correct {
  background: color-mix(in srgb, var(--tier-correct) 10%, transparent);
  border-left: 3px solid var(--tier-correct);
  padding-left: 7px;
}
.guess-flag { font-size: 1.3rem; }
.guess-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.guess-distance { color: var(--text-muted); white-space: nowrap; font-size: 0.82rem; font-family: var(--mono); }
.guess-arrow { font-size: 1.2rem; }
.guess-pct {
  font-weight: 700;
  font-family: var(--mono);
  min-width: 44px;
  text-align: right;
}
.guess-pct.tier-correct { color: var(--tier-correct); }
.guess-pct.tier-hot { color: var(--tier-hot); }
.guess-pct.tier-warm { color: #b8981f; }
.guess-pct.tier-cold { color: var(--tier-cold); }

@media (max-width: 380px) {
  .guess-row { grid-template-columns: auto 1fr auto; row-gap: 4px; }
  .guess-distance { grid-column: 2 / 4; }
}

/* Result panel */
.result-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 18px;
  margin-top: 18px;
  text-align: center;
}
.result-reveal { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.result-flag { font-size: 3rem; line-height: 1; }
.result-panel h2 { margin: 4px 0; }
.result-facts { color: var(--text-muted); margin: 10px 0; text-align: left; }
.result-facts p { margin: 4px 0; }
.share-row { margin: 14px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.share-feedback { min-height: 1.2em; font-weight: 700; color: var(--accent); margin: 0; }
.next-countdown { color: var(--text-muted); font-size: 0.82rem; font-family: var(--mono); margin: 6px 0 0; }
.mini-stats {
  display: flex; justify-content: center; gap: 18px;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.mini-stats .stat-value { display: block; font-size: 1.3rem; font-weight: 700; font-family: var(--mono); }
.mini-stats .stat-label { font-size: 0.75rem; color: var(--text-muted); }

/* Footer */
.app-footer {
  max-width: 640px;
  margin: 0 auto;
  padding: 10px calc(14px + var(--safe-left)) calc(24px + var(--safe-bottom)) calc(14px + var(--safe-right));
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: center;
}
.app-footer p { margin: 4px 0; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 16, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}
@media (min-width: 560px) {
  .modal-backdrop { align-items: center; }
}
.modal {
  background: var(--bg-card);
  color: var(--text);
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 22px calc(20px + var(--safe-left)) calc(24px + var(--safe-bottom)) calc(20px + var(--safe-right));
  position: relative;
  box-shadow: 0 -4px 30px rgba(0,0,0,0.25);
}
@media (min-width: 560px) {
  .modal { border-radius: 18px; max-height: 80vh; }
}
.modal h2 { margin-top: 4px; }
.modal-close {
  position: absolute;
  top: 10px; right: 10px;
  min-width: 44px; min-height: 44px;
  border: none;
  background: var(--suggestion-hover);
  border-radius: 10px;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text);
}
.help-list, .faq-list { padding-left: 0; margin: 10px 0; }
.help-list { list-style: none; }
.help-list li {
  padding: 8px 0 8px 26px;
  position: relative;
  border-bottom: 1px solid var(--border);
}
.help-list li::before { content: "•"; position: absolute; left: 6px; color: var(--accent); font-weight: 800; }
.faq-list dt { font-weight: 800; margin-top: 10px; }
.faq-list dd { margin: 2px 0 0; color: var(--text-muted); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  text-align: center;
  margin: 14px 0;
}
.stats-grid .stat-value { display: block; font-size: 1.4rem; font-weight: 700; font-family: var(--mono); }
.stats-grid .stat-label { font-size: 0.72rem; color: var(--text-muted); }
.stats-distribution { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.dist-row { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; font-family: var(--mono); }
.dist-label { width: 22px; text-align: right; color: var(--text-muted); }
.dist-bar-track {
  flex: 1; height: 18px;
  background: var(--suggestion-hover);
  border-radius: 4px;
  overflow: hidden;
}
.dist-bar-fill { height: 100%; background: var(--accent); min-width: 4%; }
.dist-count { width: 26px; text-align: right; }

.modal-hint { color: var(--text-muted); font-size: 0.85rem; margin-top: -6px; }
.archive-list { display: flex; flex-direction: column; margin-top: 10px; border-top: 1px solid var(--border); }
.archive-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 12px 4px;
  min-height: 44px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: inherit;
  font-size: 0.95rem;
}
.archive-item:hover { background: var(--suggestion-hover); }
.archive-item .flag { font-size: 1.4rem; }
.archive-item .played-badge {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
}
.archive-item .played-badge.win { background: var(--dot-correct); color: #fff; }
.archive-item .played-badge.lose { background: var(--dot-wrong); color: #fff; }
