/* ============================================================
   ChessSnap · style.css
   Mobile-first, tema scuro, nessuna dipendenza esterna.
   ============================================================ */

/* ---------- Variabili di tema ---------- */
:root {
  --color-bg: #12151f;
  --color-surface: #1a1f2e;
  --color-surface-alt: #222840;
  --color-border: #2e3550;
  --color-text: #f5f7fa;
  --color-text-muted: #9aa3b8;
  --color-primary: #4f7cff;
  --color-primary-dark: #3a63d6;
  --color-success: #37c978;
  --color-danger: #ff6b6b;
  --color-light-square: #e8edf5;
  --color-dark-square: #6d84b0;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

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

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

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100dvh;
  /* Rispetta le aree sicure dei telefoni con notch */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: rgba(18, 21, 31, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-border);
}

.app-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.app-title .logo {
  color: var(--color-primary);
}

/* ---------- Layout principale ---------- */
.app-main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 480px;           /* mobile-first: colonna stretta */
  margin: 0 auto;
  padding: 1rem;
}

.app-footer {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  padding: 1rem 0 2rem;
}

/* ---------- Card generiche ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
}

/* ---------- Area fotocamera / anteprima ---------- */
.camera-box {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--color-surface-alt);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.camera-preview,
.photo-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-placeholder {
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

/* ---------- Scacchiera ---------- */
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--color-border);
  user-select: none;
}

.square {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.1rem, 4.5vw, 2rem);
  line-height: 1;
}

.square.light { background: var(--color-light-square); }
.square.dark  { background: var(--color-dark-square); }

.square .piece.white { color: #ffffff; text-shadow: 0 0 2px rgba(0, 0, 0, 0.8); }
.square .piece.black { color: #111318; }

/* ---------- Input FEN ---------- */
.fen-label {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.fen-input {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.6rem 0.75rem;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  color: var(--color-text);
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.fen-input:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

/* ---------- Bottoni ---------- */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn {
  flex: 1 1 auto;
  min-height: 44px;            /* target touch comodo */
  padding: 0.6rem 1rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

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

.btn-primary {
  background: var(--color-primary);
  color: #ffffff;
}

.btn-primary:hover { background: var(--color-primary-dark); }

.btn-secondary {
  background: var(--color-surface-alt);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border-color: var(--color-border);
}

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

.btn-wide { flex: 1 1 100%; }

/* ---------- Stato / messaggi ---------- */
.status {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  min-height: 1.4em;
}

.status.is-error  { color: var(--color-danger); }
.status.is-success { color: var(--color-success); }

/* ---------- Risultati analisi ---------- */
.results {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--color-surface-alt);
  border-radius: var(--radius-sm);
}

.result-row dt {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.result-row dd {
  font-size: 1rem;
  font-weight: 600;
  text-align: right;
  overflow-wrap: anywhere;
}

/* ---------- Utilità ---------- */
.hidden { display: none !important; }

/* ---------- Tablet e desktop: layout a due colonne ---------- */
@media (min-width: 600px) {
  .app-main {
    max-width: 960px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }

  #capture-section { grid-column: 1; }
  #board-section   { grid-column: 2; }
  #controls-section { grid-column: 1 / -1; }
  #results-section { grid-column: 1 / -1; }

  .app-header {
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
    padding: 1rem 2rem;
  }
}