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

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface-2: #252525;
  --border: #333;
  --text: #e8e8e8;
  --text-dim: #888;
  --accent: #e6b84f;
  --green: #538d4e;
  --yellow: #b59f3b;
  --red: #c45454;
  --radius: 8px;
  --max-width: 640px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: var(--max-width);
  padding: 0 16px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ===== Header ===== */
.header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 0 8px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.header-actions {
  position: absolute;
  right: 0;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius);
  transition: background 0.15s;
}

.icon-btn:hover {
  background: var(--surface-2);
}

/* ===== Puzzle Number ===== */
.puzzle-number {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-top: 8px;
}

/* ===== Image Container ===== */
.image-container {
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 16px;
  position: relative;
}

.puzzle-image {
  width: 100%;
  height: auto;
  transition: clip-path 0.6s ease-in-out;
  display: none;
}

.puzzle-image.loaded {
  display: block;
}

.no-puzzle-msg {
  color: var(--text-dim);
  font-size: 0.95rem;
  text-align: center;
  padding: 24px;
  display: none;
}

.no-puzzle-msg.visible {
  display: block;
}

/* ===== Zoom Lens ===== */
.image-hover-target {
  position: absolute;
  inset: 0;
  z-index: 5;
  cursor: crosshair;
}

.zoom-lens {
  position: fixed;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background-repeat: no-repeat;
  pointer-events: none;
  display: none;
  z-index: 1000;
  box-shadow: 0 0 12px rgba(0,0,0,0.6);
}

/* ===== Clues ===== */
.clues {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  width: 100%;
  justify-content: center;
}

.clue {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: opacity 0.3s, transform 0.3s;
}

.clue.hidden {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

.clue-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.08em;
}

.clue-value {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  margin-top: 2px;
}

/* ===== Step Indicator ===== */
.steps {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.step-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background 0.3s, border-color 0.3s;
}

.step-dot.active {
  background: var(--accent);
  border-color: var(--accent);
}

.step-dot.used {
  background: var(--text-dim);
  border-color: var(--text-dim);
}

.step-dot.correct {
  background: var(--green);
  border-color: var(--green);
}

.step-dot.partial {
  background: var(--yellow);
  border-color: var(--yellow);
}

.step-dot.skipped {
  background: var(--surface-2);
  border-color: var(--border);
}

/* ===== Guess History ===== */
.guess-history {
  width: 100%;
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.guess-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  padding: 6px 12px;
  border-radius: var(--radius);
  background: var(--surface);
}

.guess-row .step-label {
  color: var(--text-dim);
  font-weight: 600;
  min-width: 18px;
}

.guess-row .guess-text {
  flex: 1;
  color: var(--text);
}

.guess-row .guess-text .correct-part {
  color: var(--green);
  font-weight: 600;
}

.guess-row .guess-text .wrong-part {
  color: var(--red);
}

.guess-row.skipped .guess-text {
  color: var(--text-dim);
  font-style: italic;
}

/* ===== Feedback ===== */
.feedback {
  margin-top: 12px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
  transition: opacity 0.3s;
}

.feedback.hidden {
  opacity: 0;
  pointer-events: none;
}

.feedback.halfway {
  background: var(--yellow);
  color: #000;
}

.feedback.win {
  background: var(--green);
  color: #fff;
}

.feedback.lose {
  background: var(--red);
  color: #fff;
}

.feedback.wrong {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

/* ===== Guess Area ===== */
.guess-area {
  width: 100%;
  margin-top: 16px;
}

.input-wrapper {
  position: relative;
  width: 100%;
}

.guess-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s;
}

.guess-input:focus {
  border-color: var(--accent);
}

.guess-input::placeholder {
  color: var(--text-dim);
}

/* ===== Autocomplete ===== */
.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 220px;
  overflow-y: auto;
  z-index: 100;
}

.autocomplete-dropdown.hidden {
  display: none;
}

.autocomplete-item {
  padding: 12px 16px;
  cursor: pointer;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.highlighted {
  background: var(--surface-2);
}

.autocomplete-item .match {
  color: var(--accent);
  font-weight: 600;
}

/* ===== Buttons ===== */
.button-row {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}

.btn {
  flex: 1;
  padding: 14px 20px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  min-height: 48px;
}

.btn:active {
  transform: scale(0.97);
}

.btn-skip {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-skip:hover {
  background: var(--border);
}

.btn-submit {
  background: var(--accent);
  color: #000;
}

.btn-submit:hover {
  background: #d4a843;
}

/* ===== Game Over ===== */
.game-over {
  width: 100%;
  margin-top: 16px;
  text-align: center;
}

.game-over.hidden {
  display: none;
}

.answer {
  font-size: 1.1rem;
  margin-bottom: 16px;
  line-height: 1.5;
}

.answer .answer-actor {
  font-weight: 700;
  color: var(--accent);
}

.answer .answer-film {
  font-weight: 700;
  color: var(--accent);
}

.game-over-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-share {
  background: var(--green);
  color: #fff;
}

.btn-share:hover {
  background: #47793f;
}

.btn-stats {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-donate {
  background: #ff5e5b;
  color: #fff;
  text-decoration: none;
  text-align: center;
}

.btn-donate:hover {
  background: #e04e4b;
}

.modal .btn-donate {
  display: block;
  margin-top: 16px;
}

.share-toast {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--green);
  transition: opacity 0.3s;
}

.share-toast.hidden {
  opacity: 0;
}

/* ===== Stats Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  transition: opacity 0.2s;
}

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

.modal {
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 24px;
  width: 100%;
  max-width: var(--max-width);
  max-height: 80dvh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h2 {
  font-size: 1.2rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
}

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 24px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ===== Distribution ===== */
.distribution {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dist-label {
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 14px;
  text-align: right;
}

.dist-bar {
  height: 24px;
  background: var(--surface-2);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 8px;
  font-size: 0.75rem;
  font-weight: 600;
  min-width: 24px;
  transition: width 0.4s ease-out;
}

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

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

/* ===== Desktop adjustments ===== */
@media (min-width: 500px) {
  .modal-overlay {
    align-items: center;
  }

  .modal {
    border-radius: 16px;
  }
}
