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

:root {
  --primary:        #2e7d32;
  --primary-light:  #43a047;
  --primary-dark:   #1b5e20;
  --primary-bg:     #e8f5e9;
  --accent:         #f57c00;
  --danger:         #c62828;
  --danger-bg:      #ffebee;
  --success:        #2e7d32;
  --success-bg:     #e8f5e9;
  --warning:        #e65100;
  --warning-bg:     #fff3e0;
  --info:           #1565c0;
  --info-bg:        #e3f2fd;
  --bg:             #f0f4f0;
  --surface:        #ffffff;
  --text:           #1a2e1a;
  --text-muted:     #5a7a5a;
  --border:         #c8e6c9;
  --radius:         14px;
  --radius-sm:      9px;
  --shadow:         0 2px 10px rgba(0, 60, 0, 0.10);
  --shadow-lg:      0 6px 24px rgba(0, 60, 0, 0.14);
  --transition:     0.18s ease;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  max-width: 600px;
  margin: 0 auto;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Screen management ─────────────────────────────────────────────────────── */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.screen.active {
  display: flex;
}

.hidden {
  display: none !important;
}

/* ── App header ────────────────────────────────────────────────────────────── */
.app-header {
  background: linear-gradient(150deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: white;
  padding: 2rem 1.25rem 1.5rem;
  text-align: center;
  flex-shrink: 0;
}

.app-header--compact {
  padding: 1.25rem 1.25rem 1rem;
}

.app-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 0.875rem;
  background: url('icons/icon.svg') center/contain no-repeat;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.3));
}

.app-header h1 {
  font-size: clamp(1.4rem, 5vw, 1.9rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.app-header h2 {
  font-size: clamp(1.25rem, 4.5vw, 1.6rem);
  font-weight: 700;
}

.subtitle {
  margin-top: 0.4rem;
  font-size: 0.9rem;
  opacity: 0.82;
}

/* ── Home screen ───────────────────────────────────────────────────────────── */
.home-main {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  -webkit-overflow-scrolling: touch;
}

.categories-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  align-content: start;
}

@media (min-width: 520px) {
  .categories-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 339px) {
  .categories-list {
    grid-template-columns: 1fr;
  }
}

.category-item {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.55rem;
  min-height: 2.75rem;
  cursor: pointer;
  transition: border-color var(--transition), background-color var(--transition);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.category-item:hover,
.category-item:focus-within {
  border-color: var(--primary);
  background: #f1f8e9;
}

.category-item input[type="checkbox"] {
  width: 1.2rem;
  height: 1.2rem;
  margin-top: 0.12rem;
  accent-color: var(--primary);
  flex-shrink: 0;
  cursor: pointer;
}

.cat-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 0.82rem;
  line-height: 1.25;
  color: var(--text);
  word-break: break-word;
  hyphens: auto;
}

.cat-count {
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
  background: var(--bg);
  padding: 0.12rem 0.35rem;
  border-radius: 20px;
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 0.05rem;
}

/* ── Home footer ───────────────────────────────────────────────────────────── */
.home-footer {
  padding: 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex-shrink: 0;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--transition), transform 0.1s, opacity var(--transition);
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.2;
}

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

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn:disabled:active {
  transform: none;
}

/* Primary */
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-light);
}

/* Secondary */
.btn-secondary {
  background: var(--primary-bg);
  color: var(--primary-dark);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: #c8e6c9;
}

/* Warning */
.btn-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1.5px solid #ffcc80;
}
.btn-warning:hover:not(:disabled) {
  background: #ffe0b2;
}

/* Quit */
.btn-quit {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1.5px solid #ffcdd2;
  font-size: 0.82rem;
  padding: 0.45rem 0.85rem;
}
.btn-quit:hover:not(:disabled) {
  background: #ffcdd2;
}

/* Known */
.btn-known {
  background: var(--info-bg);
  color: var(--info);
  border: 1.5px solid #bbdefb;
  min-width: 90px;
}
.btn-known:hover:not(:disabled) {
  background: #bbdefb;
}
.btn-known.is-known {
  background: var(--info);
  color: white;
  border-color: var(--info);
}

/* Sizes */
.btn-sm {
  font-size: 0.875rem;
  padding: 0.5rem 0.875rem;
}
.btn-lg {
  width: 100%;
  padding: 0.9rem;
  font-size: 1.05rem;
}
.btn-flex {
  flex: 1;
}

.btn-row {
  display: flex;
  gap: 0.75rem;
}

/* ── Card screen header ────────────────────────────────────────────────────── */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.progress-text {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* Progress bar */
.progress-bar {
  height: 4px;
  background: #e0e0e0;
  flex-shrink: 0;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.35s ease;
  min-width: 0;
}

/* ── Card main ─────────────────────────────────────────────────────────────── */
.card-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Image container ───────────────────────────────────────────────────────── */
.image-container {
  background: #12201c;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
  height: clamp(190px, 42vw, 300px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: rgba(255,255,255,0.65);
}

.image-loading {
  background: #12201c;
}

.image-placeholder {
  background: #12201c;
}

.placeholder-icon {
  width: 48px;
  height: 48px;
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 50%;
  position: relative;
}

.placeholder-icon::before {
  content: '';
  position: absolute;
  inset: 8px;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
}

.placeholder-icon::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 6px;
  height: 6px;
  background: rgba(255,255,255,0.4);
  border-radius: 50%;
}

/* ── Answer section ────────────────────────────────────────────────────────── */
.answer-section {
  padding: 1.1rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.answer-label {
  font-size: 0.88rem;
  color: var(--text-muted);
  font-weight: 500;
}

.answer-input {
  width: 100%;
  padding: 0.875rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.answer-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.15);
}

.answer-input:disabled {
  opacity: 0.6;
  background: #f8faf8;
}

/* ── Result section ────────────────────────────────────────────────────────── */
.result-section {
  padding: 1.1rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.result-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem 1.1rem;
  border-radius: 2rem;
  font-size: 1rem;
  font-weight: 700;
  align-self: flex-start;
}

.result-badge.correct {
  background: var(--success-bg);
  color: var(--success);
}

.result-badge.wrong {
  background: var(--danger-bg);
  color: var(--danger);
}

.correct-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary-dark);
  padding: 0.75rem 1rem;
  background: var(--primary-bg);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--primary);
  word-break: break-word;
}

.correct-name .label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.2rem;
}

.user-answer {
  font-size: 0.875rem;
  color: var(--text-muted);
  word-break: break-word;
}

/* ── Stats screen ──────────────────────────────────────────────────────────── */
.stats-main {
  flex: 1;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  overflow-y: auto;
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem 0.5rem;
  text-align: center;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.stat-number {
  font-size: clamp(2rem, 8vw, 2.8rem);
  font-weight: 800;
  line-height: 1;
}

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

.stat-total   .stat-number { color: var(--text); }
.stat-correct .stat-number { color: var(--success); }
.stat-wrong   .stat-number { color: var(--danger); }

/* Score bar */
.score-bar-wrap {
  height: 10px;
  background: var(--danger-bg);
  border-radius: 999px;
  overflow: hidden;
}

.score-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.5s ease;
}

.score-percent {
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-muted);
  font-weight: 500;
}

.stats-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ── Spinner ───────────────────────────────────────────────────────────────── */
.spinner {
  width: 1.75rem;
  height: 1.75rem;
  border: 3px solid rgba(46, 125, 50, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}

.spinner-light {
  border-color: rgba(255,255,255,0.2);
  border-top-color: rgba(255,255,255,0.85);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Loading indicator ─────────────────────────────────────────────────────── */
.loading-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ── Error message ─────────────────────────────────────────────────────────── */
.error-msg {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #ffcdd2;
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin: 1rem;
  font-size: 0.9rem;
  text-align: center;
  line-height: 1.5;
}

/* ── Accessibility ─────────────────────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Focus ring for keyboard navigation */
.btn:focus-visible,
.answer-input:focus-visible,
.category-item input:focus-visible,
.image-admin-select:focus-visible,
.image-upload-form input:focus-visible {
  outline: 3px solid var(--primary-light);
  outline-offset: 2px;
}

/* ── Image admin dialog ────────────────────────────────────────────────────── */
.image-admin-dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: calc(100vw - 2rem);
  width: 26rem;
  box-shadow: var(--shadow-lg);
  background: var(--surface);
}

.image-admin-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.image-admin-inner {
  padding: 1.25rem 1.25rem 1rem;
}

.image-admin-dialog .subtitle {
  text-align: left;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.image-admin-hint code {
  font-size: 0.8em;
  word-break: break-all;
}

.image-upload-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.image-upload-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.image-upload-label-text {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.image-admin-select,
.image-upload-form input[type="file"],
.image-upload-form input[type="password"] {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--surface);
  color: var(--text);
}

.image-upload-msg {
  min-height: 1.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.image-upload-msg:not(:empty) {
  color: var(--text);
}

.image-upload-actions {
  margin-top: 0.25rem;
  justify-content: flex-end;
}

/* ── Difficulty selector (home screen) ─────────────────────────────────────── */
.difficulty-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
}

.difficulty-select {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.difficulty-option {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  transition: border-color var(--transition), background-color var(--transition);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.difficulty-option:hover {
  border-color: var(--primary);
  background: #f1f8e9;
}

.difficulty-option input[type="radio"] {
  margin-top: 0.18rem;
  accent-color: var(--primary);
  flex-shrink: 0;
  width: 1.1rem;
  height: 1.1rem;
  cursor: pointer;
}

.difficulty-option:has(input:checked) {
  border-color: var(--primary);
  background: #f1f8e9;
}

.difficulty-option__body {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.diff-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.diff-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* ── Difficulty badge (card header) ────────────────────────────────────────── */
.difficulty-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.difficulty-badge--easy {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #a5d6a7;
}

.difficulty-badge--hard {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid #ffcc80;
}

/* ── No-image placeholder enhancements ─────────────────────────────────────── */
.placeholder-name {
  font-size: 1rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.9);
  text-align: center;
  max-width: 80%;
  word-break: break-word;
  line-height: 1.3;
}

.placeholder-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
  flex-wrap: wrap;
  justify-content: center;
}

/* ── Outline button (Špatný obrázek) ───────────────────────────────────────── */
.btn-outline {
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  border: 1.5px solid rgba(255, 255, 255, 0.35);
}

.btn-outline:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.6);
  color: white;
}

/* Outline button outside the dark image area (in result-mode) */
.result-section .btn-outline {
  color: var(--warning);
  border-color: #ffcc80;
  background: var(--warning-bg);
}

.result-section .btn-outline:hover:not(:disabled) {
  background: #ffe0b2;
}

.result-section .btn-outline.is-wrong {
  background: var(--warning);
  color: white;
  border-color: var(--warning);
}

/* Toggle state when flagged (in dark placeholder overlay) */
.image-overlay .btn-outline.is-wrong {
  background: rgba(230, 81, 0, 0.7);
  border-color: #ff8f00;
  color: white;
}

/* ── Stats: skipped note ───────────────────────────────────────────────────── */
.stats-skipped-note {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: -0.5rem;
}

/* ── Wrong images section (stats screen) ───────────────────────────────────── */
.wrong-images-section {
  background: var(--warning-bg);
  border: 1.5px solid #ffcc80;
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.wrong-images-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--warning);
}

.wrong-images-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0;
}

.wrong-images-list li {
  font-size: 0.88rem;
  color: var(--text);
  padding: 0.3rem 0.5rem 0.3rem 1rem;
  position: relative;
}

.wrong-images-list li::before {
  content: '–';
  position: absolute;
  left: 0.25rem;
  color: var(--text-muted);
}

/* ── Report modal overlay ──────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-height: 500px) {
  .modal {
    align-items: center;
    padding: 1rem;
  }
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-body {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 540px;
  padding: 1.5rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: 90vh;
  overflow-y: auto;
}

@media (min-height: 500px) {
  .modal-body {
    border-radius: var(--radius);
    padding: 1.5rem 1.25rem;
    max-height: 85vh;
  }
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

/* ── Form fields (report modal) ────────────────────────────────────────────── */
.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

.required {
  color: var(--danger);
  font-weight: 700;
}

.optional {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.form-input {
  width: 100%;
  padding: 0.75rem 0.875rem;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.15);
}

.form-textarea {
  width: 100%;
  padding: 0.75rem 0.875rem;
  font-size: 0.95rem;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  outline: none;
  resize: vertical;
  min-height: 4.5rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.15);
}

.field-error {
  font-size: 0.82rem;
  color: var(--danger);
  font-weight: 500;
}

/* ── Report: items preview ─────────────────────────────────────────────────── */
.report-items-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.report-items-list {
  list-style: none;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  max-height: 8rem;
  overflow-y: auto;
}

.report-items-list li {
  font-size: 0.88rem;
  padding: 0.2rem 0;
  color: var(--text);
}

.report-items-list li + li {
  border-top: 1px solid var(--border);
}

/* ── Responsive tweaks ─────────────────────────────────────────────────────── */
@media (max-width: 380px) {
  .app-header h1 { font-size: 1.35rem; }
  .stat-card { padding: 1rem 0.3rem; }
}

@media (min-height: 700px) {
  .image-container {
    height: clamp(220px, 45vw, 340px);
  }
}
