/* ============================
   DOGDLE — Styles
   Dark game aesthetic
   ============================ */

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

:root {
  --bg:            #1a1a2e;
  --bg2:           #16213e;
  --bg3:           #0f3460;
  --card:          #1e2a3a;
  --gold:          #d4af37;
  --gold-dim:      #a07e1a;
  --teal:          #4ecdc4;
  --teal-dim:      #2aa59d;
  --text:          #f0f0f0;
  --text-dim:      #8899aa;
  --border:        rgba(212,175,55,0.4);

  /* Tile colors */
  --correct:       #538d4e;
  --correct-border:#6aac63;
  --partial:       #b59f3b;
  --partial-border:#d4bc4e;
  --wrong:         #3a3a4e;
  --wrong-border:  #555570;

  --radius:        8px;
  --tile-size:     90px;
  --tile-height:   72px;
}

/* ---- Base ---- */
html, body { height: 100%; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(78,205,196,0.05) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(212,175,55,0.07) 0%, transparent 50%);
}

/* ---- Header ---- */
header {
  width: 100%;
  background: var(--bg2);
  border-bottom: 2px solid var(--border);
  padding: 16px 24px;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.logo {
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: 3px;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(212,175,55,0.4);
}

.tagline {
  font-size: 0.9rem;
  color: var(--text-dim);
  flex: 1;
  text-align: center;
}

.puzzle-info {
  font-size: 0.85rem;
  color: var(--gold-dim);
  white-space: nowrap;
}

/* ---- Main ---- */
main {
  width: 100%;
  max-width: 900px;
  padding: 24px 16px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

/* ---- Photo Section ---- */
.photo-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.photo-frame {
  width: 100%;
  max-width: 600px;
  aspect-ratio: 1;
  border-radius: 16px;
  border: 3px solid var(--border);
  overflow: hidden;
  background: var(--card);
  position: relative;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4), 0 0 0 1px rgba(212,175,55,0.1);
}

.dog-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.3s;
}

.dog-photo.hidden { opacity: 0; }
.dog-photo.loaded { opacity: 1; }

.photo-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.paw-spinner {
  font-size: 2.5rem;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50%       { transform: scale(1.15); opacity: 1; }
}

.photo-caption {
  font-size: 1rem;
  color: var(--text-dim);
  text-align: center;
}

/* ---- Input Section ---- */
.input-section {
  width: 100%;
  max-width: 540px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.input-wrapper {
  display: flex;
  width: 100%;
  gap: 10px;
}

.autocomplete-container {
  position: relative;
  flex: 1;
}

#guess-input {
  width: 100%;
  padding: 12px 18px;
  font-size: 1rem;
  background: var(--card);
  border: 2px solid var(--teal-dim);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#guess-input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(78,205,196,0.15);
}

#guess-input::placeholder { color: var(--text-dim); }
#guess-input:disabled { opacity: 0.5; cursor: not-allowed; }

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg3);
  border: 1px solid var(--teal-dim);
  border-radius: var(--radius);
  list-style: none;
  max-height: 220px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.suggestions.hidden { display: none; }

.suggestions li {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.suggestions li:last-child { border-bottom: none; }
.suggestions li:hover,
.suggestions li.active {
  background: rgba(78,205,196,0.15);
  color: var(--teal);
}

#submit-btn {
  padding: 0 20px;
  background: var(--teal);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  color: #1a1a2e;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 4px 12px rgba(78,205,196,0.3);
  min-width: 52px;
  height: 48px;
}

#submit-btn:hover {
  background: #6eddd6;
  box-shadow: 0 4px 20px rgba(78,205,196,0.5);
}

#submit-btn:active { transform: scale(0.97); }
#submit-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.guesses-left {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.guesses-left strong { color: var(--gold); }

/* ---- Grid ---- */
.grid-section {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#grid-container {
  min-width: 700px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#guess-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.grid-header {
  display: grid;
  grid-template-columns: 160px repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 4px;
}

.grid-header-cell {
  text-align: center;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-dim);
  padding: 4px 0;
  text-transform: uppercase;
}

.grid-header-cell:first-child {
  text-align: left;
  padding-left: 8px;
}

/* ---- Guess Row ---- */
.guess-row {
  display: grid;
  grid-template-columns: 160px repeat(7, 1fr);
  gap: 6px;
  align-items: stretch;
}

/* Breed name cell */
.breed-cell {
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  min-height: var(--tile-height);
}

.breed-cell-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
}

.breed-cell-name {
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Category tile */
.tile {
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: var(--tile-height);
  padding: 6px 4px;
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
  position: relative;
  perspective: 400px;
  cursor: default;
  line-height: 1.2;
}

/* Unrevealed state */
.tile.unrevealed {
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.1);
  color: transparent;
}

/* Color states */
.tile.correct {
  background: var(--correct);
  border: 1px solid var(--correct-border);
  color: #fff;
}

.tile.partial {
  background: var(--partial);
  border: 1px solid var(--partial-border);
  color: #fff;
}

.tile.wrong {
  background: var(--wrong);
  border: 1px solid var(--wrong-border);
  color: #fff;
}

/* Flip animation */
.tile.flip {
  animation: tileFlip 0.5s ease forwards;
}

@keyframes tileFlip {
  0%   { transform: rotateX(0deg); }
  50%  { transform: rotateX(90deg); opacity: 0.4; }
  100% { transform: rotateX(0deg); opacity: 1; }
}

.tile-value {
  font-size: 0.8rem;
  font-weight: 700;
  display: block;
}

.tile-arrow {
  font-size: 1rem;
  line-height: 1;
  margin-top: 2px;
  display: block;
}

/* ---- Legend ---- */
.legend-section {
  width: 100%;
  max-width: 540px;
}

.legend-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.82rem;
  transition: color 0.2s, border-color 0.2s;
}

.legend-toggle:hover { color: var(--gold); border-color: var(--gold); }

.legend-content {
  margin-top: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.legend-content.hidden { display: none; }

.legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
}

.legend-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.legend-tile {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
}

.legend-tile.green  { background: var(--correct); border: 1px solid var(--correct-border); }
.legend-tile.yellow { background: var(--partial); border: 1px solid var(--partial-border); }
.legend-tile.red    { background: var(--wrong);   border: 1px solid var(--wrong-border);   }

/* ---- Modal ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal[aria-hidden="true"] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px);
}

.modal-box {
  position: relative;
  background: var(--bg2);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  max-width: 440px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: modalIn 0.3s ease;
}

@keyframes modalIn {
  from { transform: scale(0.9) translateY(20px); opacity: 0; }
  to   { transform: scale(1)   translateY(0);    opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 14px; right: 16px;
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  color: var(--text-dim);
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, border-color 0.2s;
}

.modal-close:hover { color: var(--text); border-color: var(--text); }

.modal-section {
  text-align: center;
}

.modal-section.hidden { display: none; }

.modal-icon {
  font-size: 2.5rem;
  margin-bottom: 6px;
}

.modal-section h2 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: 4px;
}

.modal-section p {
  font-size: 0.9rem;
  color: var(--text-dim);
}

/* Breed reveal */
.modal-breed-reveal {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.08);
}

#modal-photo {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--border);
}

.modal-breed-text h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.modal-breed-text p {
  font-size: 0.82rem;
  color: var(--text-dim);
}

/* Adopt section */
.adopt-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.adopt-cta {
  font-size: 0.88rem;
  color: var(--text-dim);
}

.adopt-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: var(--gold);
  color: #1a1a2e;
  font-weight: 800;
  font-size: 0.95rem;
  border-radius: 30px;
  text-decoration: none;
  letter-spacing: 0.5px;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 4px 16px rgba(212,175,55,0.35);
}

.adopt-btn:hover {
  background: #e8c84a;
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(212,175,55,0.5);
}

/* Keep playing */
.keep-playing-section {
  display: flex;
  justify-content: center;
}

.keep-playing-btn {
  padding: 10px 28px;
  background: transparent;
  border: 2px solid var(--teal-dim);
  border-radius: 30px;
  color: var(--teal);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.keep-playing-btn:hover {
  background: rgba(78,205,196,0.1);
  border-color: var(--teal);
}

/* Share section */
.share-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.share-btn {
  padding: 10px 28px;
  background: transparent;
  border: 2px solid var(--teal-dim);
  border-radius: 30px;
  color: var(--teal);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.share-btn:hover {
  background: rgba(78,205,196,0.1);
  border-color: var(--teal);
}

.toast {
  font-size: 0.82rem;
  color: var(--correct-border);
  transition: opacity 0.3s;
}

.toast.hidden { display: none; }

/* Next puzzle */
.next-puzzle {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-dim);
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 16px;
}

.next-puzzle strong { color: var(--gold); }

/* Error banner */
.error-banner {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #7b2d2d;
  border: 1px solid #c0392b;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 300;
  animation: slideDown 0.2s ease, fadeOut 0.4s ease 2.6s forwards;
  pointer-events: none;
}

@keyframes slideDown {
  from { transform: translateX(-50%) translateY(-10px); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0);     opacity: 1; }
}

@keyframes fadeOut {
  to { opacity: 0; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }

/* ---- Dev Console ---- */
#dev-console {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 340px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-bottom: none;
  border-right: none;
  border-radius: 10px 0 0 0;
  font-family: 'Consolas', 'Fira Code', monospace;
  font-size: 0.82rem;
  color: #c9d1d9;
  z-index: 500;
  transform: translateY(100%);
  transition: transform 0.25s ease;
  box-shadow: -4px -4px 24px rgba(0,0,0,0.5);
}

#dev-console.dev-open {
  transform: translateY(0);
}

.dev-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  border-radius: 10px 0 0 0;
  font-weight: 700;
  color: #58a6ff;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
}

#dev-close {
  background: none;
  border: none;
  color: #8b949e;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
}
#dev-close:hover { color: #c9d1d9; background: rgba(255,255,255,0.08); }

.dev-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dev-current {
  color: #8b949e;
  font-size: 0.78rem;
}
.dev-current strong { color: #f0f6fc; }

.dev-label {
  color: #8b949e;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dev-row {
  display: flex;
  gap: 6px;
}

.dev-ac-wrap {
  position: relative;
  flex: 1;
}

#dev-input {
  width: 100%;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 4px;
  padding: 6px 10px;
  color: #f0f6fc;
  font-family: inherit;
  font-size: 0.82rem;
  outline: none;
  transition: border-color 0.15s;
}
#dev-input:focus { border-color: #58a6ff; }

.dev-suggestions {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0; right: 0;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 4px;
  list-style: none;
  max-height: 180px;
  overflow-y: auto;
  z-index: 10;
}
.dev-suggestions:empty { display: none; }
.dev-suggestions li {
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.8rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.dev-suggestions li:hover,
.dev-suggestions li.active { background: rgba(88,166,255,0.15); color: #58a6ff; }

#dev-set-btn {
  padding: 6px 12px;
  background: #238636;
  border: 1px solid #2ea043;
  border-radius: 4px;
  color: #fff;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
#dev-set-btn:hover { background: #2ea043; }

.dev-actions { gap: 6px; }

.dev-actions button {
  flex: 1;
  padding: 5px 8px;
  background: transparent;
  border: 1px solid #30363d;
  border-radius: 4px;
  color: #8b949e;
  font-family: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.dev-actions button:hover { border-color: #58a6ff; color: #58a6ff; }

.dev-hint {
  color: #484f58;
  font-size: 0.72rem;
  font-style: italic;
}

/* Responsive */
@media (max-width: 640px) {
  .header-inner { flex-direction: column; gap: 4px; }
  .logo { font-size: 1.3rem; }
  .photo-frame { max-width: 100%; }
  :root { --tile-size: 60px; --tile-height: 56px; }
  .breed-cell { padding: 4px 6px; font-size: 0.7rem; min-width: 100px; }
  .breed-cell-icon { font-size: 1.1rem; }
  .tile-value { font-size: 0.65rem; }
  .grid-header-cell { font-size: 0.6rem; }
  #grid-container { min-width: 520px; }
  .grid-header,
  .guess-row { grid-template-columns: 100px repeat(7, 1fr); }
}
