/* PixelGuess — full styles (Phase 6) */

/* ─── Custom properties ────────────────────────────────────────────────────── */
:root {
  --navy:      #1a1a2e;
  --navy-mid:  #16213e;
  --green:     #16a34a;
  --green-bg:  #dcfce7;
  --green-fg:  #166534;
  --red-bg:    #fee2e2;
  --red-fg:    #991b1b;
  --amber:     #b45309;
  --gray-100:  #f5f5f5;
  --gray-200:  #e5e7eb;
  --gray-300:  #d1d5db;
  --gray-400:  #9ca3af;
  --gray-600:  #4b5563;
  --gray-800:  #1f2937;
  --radius:    6px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.12), 0 2px 6px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.18), 0 4px 10px rgba(0,0,0,.10);
  --transition: 150ms ease;
}

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

/* ─── Base ──────────────────────────────────────────────────────────────────── */
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  min-height: 100vh;
  line-height: 1.5;
}

/* ─── Header ────────────────────────────────────────────────────────────────── */
header {
  background: var(--navy);
  color: #fff;
  padding: 0 1rem;
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 480px;
  margin: 0 auto;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

header h1 a {
  color: inherit;
  text-decoration: none;
}

.streak-badge {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.20);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ─── Layout ────────────────────────────────────────────────────────────────── */
main {
  max-width: 480px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

/* ─── Image section ─────────────────────────────────────────────────────────── */
.image-section {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.image-box {
  width: 100%;
  aspect-ratio: 1;
  background: var(--gray-200);
  overflow: hidden;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-300);
}

.image-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  image-rendering: pixelated;
  /* smooth crossfade when JS swaps src */
  transition: opacity 0.3s ease;
}

.image-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
  font-size: 0.9rem;
}

.category-label {
  font-size: 0.8rem;
  color: var(--gray-600);
}

/* ─── Guess form ────────────────────────────────────────────────────────────── */
.guess-section {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.guess-form {
  display: flex;
  gap: 0.5rem;
}

#guess-input {
  flex: 1;
  padding: 0.65rem 0.85rem;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius);
  outline: none;
  background: #fff;
  color: var(--gray-800);
  transition: border-color var(--transition), box-shadow var(--transition);
}

#guess-input:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(26,26,46,.12);
}

#guess-input:disabled {
  background: var(--gray-100);
  color: var(--gray-400);
  cursor: not-allowed;
}

#submit-btn {
  padding: 0.65rem 1.2rem;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  white-space: nowrap;
}

#submit-btn:hover:not(:disabled) {
  background: var(--navy-mid);
}

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

#submit-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.attempts-label {
  font-size: 0.78rem;
  color: var(--gray-600);
}

/* ─── Input error ───────────────────────────────────────────────────────────── */
.guess-error {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--red-fg);
}

.guess-suggestion {
  font-size: 0.82rem;
  font-weight: 500;
  color: #1d4ed8;
}

/* ─── Hint ──────────────────────────────────────────────────────────────────── */
.hint {
  font-style: italic;
  color: var(--amber);
  font-size: 0.9rem;
  background: #fef3c7;
  border-left: 3px solid var(--amber);
  padding: 0.45rem 0.75rem;
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* ─── Guess history ─────────────────────────────────────────────────────────── */
.guess-history {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.guess-history li {
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

.guess-history li.wrong {
  background: var(--red-bg);
  color: var(--red-fg);
}

.guess-history li.correct {
  background: var(--green-bg);
  color: var(--green-fg);
}

/* ─── Modal ─────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  /* backdrop fades in */
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  position: relative;
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 1.75rem 1.5rem 1.5rem;
  max-width: 360px;
  width: calc(100% - 2rem);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  text-align: center;
  /* modal slides up */
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-result {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--navy);
}

.modal-answer-label {
  font-size: 0.8rem;
  color: var(--gray-600);
  margin-bottom: -0.3rem;
}

.modal-answer {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--navy);
}

.modal-guesses {
  font-size: 0.88rem;
  color: var(--gray-600);
}

/* ─── Stats ─────────────────────────────────────────────────────────────────── */
.modal-stats {
  border-top: 1px solid var(--gray-200);
  padding-top: 0.75rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
}

.stat-value {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1;
}

.stat-label {
  font-size: 0.66rem;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ─── Guess distribution ────────────────────────────────────────────────────── */
.distribution {
  margin-top: 0.6rem;
  text-align: left;
}

.distribution-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-600);
  margin-bottom: 0.4rem;
}

.distribution-bars {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
}

.dist-label {
  width: 0.75rem;
  text-align: right;
  flex-shrink: 0;
  color: var(--gray-600);
  font-weight: 600;
}

.dist-bar-wrap {
  flex: 1;
  background: var(--gray-200);
  border-radius: 3px;
  height: 1.15rem;
  overflow: hidden;
}

.dist-bar {
  background: var(--navy);
  height: 100%;
  border-radius: 3px;
  min-width: 3px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 5px;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 600;
  transition: width 0.4s ease 0.1s;
}

.dist-bar.highlight {
  background: var(--green);
}

/* ─── Buttons (modal) ───────────────────────────────────────────────────────── */
#share-btn {
  padding: 0.65rem 1.2rem;
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 600;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  margin-top: 0.2rem;
  transition: background var(--transition), transform var(--transition);
}

#share-btn:hover {
  background: var(--navy-mid);
}

#share-btn:active {
  transform: scale(0.97);
}

/* ─── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-800);
  color: #fff;
  padding: 0.5rem 1.25rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 200;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.2s ease;
}

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

/* ─── No-puzzle page ────────────────────────────────────────────────────────── */
.no-puzzle {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--gray-600);
}

.no-puzzle-icon {
  font-size: 3.5rem;
  margin-bottom: 0.75rem;
}

.no-puzzle h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 0.5rem;
}

.no-puzzle p {
  font-size: 0.95rem;
}

/* ─── Utility ───────────────────────────────────────────────────────────────── */
[hidden] {
  display: none !important;
}

/* ─── Responsive — 320 px minimum ───────────────────────────────────────────── */
@media (max-width: 360px) {
  .header-inner {
    height: 48px;
  }

  header h1 {
    font-size: 1.15rem;
  }

  #guess-input,
  #submit-btn {
    font-size: 0.9rem;
    padding: 0.55rem 0.7rem;
  }

  .modal {
    padding: 1.4rem 1.1rem 1.2rem;
  }

  .stat-value {
    font-size: 1.3rem;
  }

  .modal-result {
    font-size: 1.25rem;
  }
}

/* ─── Modal close button ────────────────────────────────────────────────────── */
.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.1rem;
  color: #6b7280;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  line-height: 1;
}

.modal-close:hover {
  color: #111;
}

/* ─── Stats tab ─────────────────────────────────────────────────────────────── */
.stats-tab {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 2rem;
  padding: 0.75rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  z-index: 100;
  white-space: nowrap;
}

.stats-tab:hover {
  background: var(--navy-mid);
}

/* ─── Try previous link ──────────────────────────────────────────────────────── */
#try-previous {
  margin-top: 1rem;
  text-align: center;
}

.try-previous-link {
  display: inline-block;
  color: var(--navy);
  font-size: 1rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

/* ─── Archive links ─────────────────────────────────────────────────────────── */
#archive-links {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #e5e7eb;
  text-align: center;
}

.archive-label {
  font-size: 0.85rem;
  color: #6b7280;
  margin-bottom: 0.5rem;
}

#archive-link-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.archive-link {
  display: block;
  color: var(--navy);
  font-size: 0.9rem;
  text-decoration: underline;
  cursor: pointer;
}
