/* ==========================================================================
   Project: SpellCheck (PWA) — UI Stylesheet
   Purpose: Styling, theming and responsive utilities for the calculator app.
   Notes:
     - Variabili CSS centralizzate in :root (light) e in .dark (manual dark).
     - Le sezioni sono segmentate per componente (Header, Card/Form, Modals, ...).
     - Evitare l’uso di !important salvo override responsivi o integrazioni Bootstrap.
   Authoring: Refactor by ChatGPT — 2025-08-19
   ========================================================================== */

:root {
  --bg: #f8fafc;
  --bg-alt: #ffffff;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --primary: #2563eb;
  --primary-600: #1d4ed8;
  --primary-700: #1e40af;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --border: #e2e8f0;
  --shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
  --radius: 16px;
  --font-display: "IM Fell English", serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
  --fs-xxl: clamp(28px, 4vw, 44px);
  --fs-xl: clamp(22px, 3vw, 30px);
  --fs-lg: 18px;
  --fs-md: 16px;
  --fs-sm: 14px;
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --space-6: 48px;
}

/* Automatic dark mode (OS-driven) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --bg-alt: #0f172a;
    --surface: #111827;
    --text: #e5e7eb;
    --muted: #a3a3a3;
    --primary: #60a5fa;
    --primary-600: #3b82f6;
    --primary-700: #2563eb;
    --success: #22c55e;
    --warning: #fbbf24;
    --danger: #f87171;
    --border: #1f2937;
    --shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  }
}

/* Manual dark mode (class-driven) */
.dark {
  --bg: #0b1220;
  --bg-alt: #0f172a;
  --surface: #111827;
  --text: #e5e7eb;
  --muted: #a3a3a3;
  --primary: #60a5fa;
  --primary-600: #3b82f6;
  --primary-700: #2563eb;
  --success: #22c55e;
  --warning: #fbbf24;
  --danger: #f87171;
  --border: #1f2937;
  --shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

/* ---------- Base elements ---------- */
html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.5;
}

/* ---------- Header & Typography ---------- */
header {
  padding: var(--space-5) var(--space-3) var(--space-4);
  background:
    radial-gradient(1000px 500px at 50% -10%,
      color-mix(in oklab, var(--primary) 16%, transparent),
      transparent 60%),
    linear-gradient(180deg, var(--bg-alt), var(--bg));
  border-bottom: 1px solid var(--border);
}

h1 {
  font-family: var(--font-display);
  font-size: var(--fs-xxl);
  letter-spacing: 0.5px;
  margin-bottom: var(--space-2);
}

h2.h4, h3.h4 {
  font-size: var(--fs-xl);
  margin: var(--space-4) 0 var(--space-2);
}

/* ---------- Card/Form container ---------- */
.container form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-4);
}
.dark .container form {
  background: linear-gradient(
    180deg,
    color-mix(in oklab, var(--surface) 96%, transparent),
    color-mix(in oklab, var(--surface) 88%, transparent)
  );
  border-color: color-mix(in oklab, var(--border) 85%, transparent);
}

/* ---------- Buttons ---------- */
.btn.btn-custom, #install-button, .button-container .btn {
  --btn-bg: var(--primary);
  --btn-bg-hover: var(--primary-600);
  --btn-bg-active: var(--primary-700);
  --btn-text: #ffffff;

  background: var(--btn-bg);
  color: var(--btn-text);
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 600;
  transition: transform 0.05s ease, background 0.15s ease;
  box-shadow: 0 2px 0 rgba(0,0,0,0.08);
}
.btn.btn-custom:hover, #install-button:hover, .button-container .btn:hover { background: var(--btn-bg-hover); }
.btn.btn-custom:active, #install-button:active, .button-container .btn:active { background: var(--btn-bg-active); transform: translateY(1px); }

.button-container {
  display: grid;
  grid-auto-flow: column;
  gap: var(--space-3);
  justify-content: center;
  margin-top: var(--space-4);
}

/* ---------- Forms ---------- */
.form-label, label {
  font-weight: 600;
  color: var(--muted);
}

.form-select, .form-control, input[type="number"] {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.form-select:focus, .form-control:focus, input[type="number"]:focus {
  outline: none;
  border-color: var(--primary-600);
  box-shadow: 0 0 0 4px color-mix(in oklab, var(--primary) 20%, transparent);
}

/* Checkbox rows */
.form-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}
.form-check-input { flex: 0 0 auto; margin-top: 2px; }
.form-check-label { display: block; flex: 1 1 auto; min-width: 0; line-height: 1.35; }

/* ---------- Icons & helpers ---------- */
.dice-icon {
  width: 48px;
  height: 48px;
  user-select: none;
  cursor: pointer;
  transition: transform .1s ease;
}
.dice-icon:active { transform: scale(0.96); }

.adjust-icon {
  width: 28px;
  height: 28px;
  cursor: pointer;
  transform: translateY(5px);
  opacity: 0.9;
}
.adjust-icon:hover { opacity: 1; }

/* Centered numeric controls in .text-center contexts */
.dice-input-container,
.text-center .form-control.mx-auto {
  margin-left: auto !important;
  margin-right: auto !important;
  display: block !important;
  text-align: center;
}

/* ---------- Modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: color-mix(in oklab, var(--text) 45%, transparent);
  z-index: 1000;
}
.modal.is-open { display: flex !important; }

.modal-content {
  width: min(760px, 94vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: var(--space-4);
}

/* Popup rows (key-value layout) */
.popup-row {
  display: grid;
  grid-template-columns: 1fr 180px;
  gap: var(--space-2);
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
  align-items: center;
}
.popup-row:last-child { border-bottom: 0; }

.popup-row > :first-child {
  text-align: left !important;
  justify-self: start;
  color: var(--muted);
  font-weight: 600;
}
.popup-row > :last-child {
  justify-self: center;
  text-align: center;
  display: inline-block;
  min-width: 130px;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 800;
  letter-spacing: .2px;
  font-size: clamp(16px, 2vw, 20px);
  border: 1px solid color-mix(in oklab, var(--primary) 32%, var(--border));
  background: color-mix(in oklab, var(--primary) 14%, transparent);
}

/* ---------- Footer ---------- */
footer {
  color: var(--muted);
  padding: var(--space-4) 0 var(--space-6);
}

/* ---------- Spacing utilities ---------- */
.mt-4 { margin-top: var(--space-4) !important; }
.mb-3 { margin-bottom: var(--space-3) !important; }

/* ---------- Adjust wrapper (generic) ---------- */
.adjust-wrapper {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: nowrap;
}
.adjust-wrapper[style*="display:none"] { display: none !important; }
.adjust-wrapper .form-control,
.adjust-wrapper input[type="number"] {
  display: inline-block !important;
  width: auto !important;
  min-width: 88px;
  text-align: center;
  margin: 0 2px;
}
.adjust-wrapper .adjust-icon,
img.adjust-icon {
  display: inline-block !important;
  width: 28px;
  height: 28px;
  vertical-align: middle;
}

/* ---------- Mago input (CONSOLIDATED) ---------- */
.mago-input-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}
.mago-input-container .mago-label {
  display: block;
  font-weight: 600;
  color: var(--muted);
  margin: 0;
}
.mago-input-container .input-group {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center;
  gap: 10px;
  flex-wrap: nowrap;
  width: auto;
  margin: 0 auto;
}
.mago-input-container .input-group > * { flex: 0 0 auto; }
.mago-input-container .input-group .form-control {
  display: inline-block !important;
  width: auto !important;
  min-width: 88px;
  text-align: center;
  margin: 0 2px;
  border-radius: 12px;
}
.mago-input-container .input-group .adjust-icon,
.mago-input-container .input-group img.adjust-icon {
  display: inline-block !important;
  width: 28px;
  height: 28px;
  vertical-align: middle;
}

/* ---------- Media queries (consolidated) ---------- */
@media (max-width: 576px) {
  .adjust-wrapper { flex-wrap: wrap; justify-content: center; row-gap: 8px; }
  .mago-input-container .input-group { flex-wrap: wrap; row-gap: 8px; }
}
@media (max-width: 520px) {
  .button-container { grid-auto-flow: row; }
  .popup-row { grid-template-columns: 1fr; }
  .popup-row > :last-child { margin-top: 6px; }
}

/* Aggiungi in fondo a style.css */
@media (max-width: 576px) {
  .mago-input-container .input-group .form-control {
    min-width: 60px;   /* ridotto da 88px */
    max-width: 70px;   /* limite massimo per evitare overflow */
    padding: 6px 8px;  /* padding più contenuto */
  }
}

/* === Theme overrides (Arcano, Rosso) merged in === */
/* ===== Tema Arcano (palette viola/teal) ===== */
.theme-viola {
  --primary: #7c3aed;    /* violet-600 */
  --primary-600: #6d28d9;
  --primary-700: #5b21b6;

  --bg: #f7f6fb;
  --bg-alt: #ffffff;
  --surface: #ffffff;
  --text: #1f1b2e;
  --muted: #5b5870;
  --border: #e7e2f5;
  --success: #14b8a6; /* teal-500 */
  --warning: #eab308; /* amber-500 */
  --danger:  #ef4444; /* red-500 */
  --shadow:  0 12px 28px rgba(92, 69, 158, 0.12);
}

/* Arcano + Dark (contrastato) */
.dark.theme-viola {
  --bg: #0d0a18;
  --bg-alt: #1a1330;     /* più chiaro di ~8–10 L* rispetto a --bg */
  --surface: #201a3b;
  --text: #e9e7ff;
  --muted: #b7b3d1;
  --border: #2b2347;
  --primary: #a78bfa;    /* violet-400 */
  --primary-600: #8b5cf6;/* violet-500 */
  --primary-700: #7c3aed;/* violet-600 */
  --success: #2dd4bf;
  --warning: #f59e0b;
  --danger:  #f87171;
  --shadow:  0 12px 28px rgba(0, 0, 0, 0.45);
}

/* ===== Tema Rosso (pulsanti primari rossi + bg aligned) ===== */
.theme-rosso {
  /* Accenti/pulsanti */
  --primary: #dc2626;     /* red-600 */
  --primary-600: #b91c1c; /* red-700 */
  --primary-700: #991b1b; /* red-800 */

  /* Background e superfici coerenti con il tema */
  --bg: #fff5f5;          /* red-50 */
  --bg-alt: #ffffff;
  --surface: #ffffff;
  --text: #1f2937;        /* slate-800 per ottimo contrasto */
  --muted: #6b7280;       /* slate-500 neutro per testi secondari */
  --border: #ffe4e6;      /* rose-100 per un bordo leggero */
  --success: #16a34a;     /* green-600 */
  --warning: #f59e0b;     /* amber-500 */
  --danger:  #dc2626;     /* red-600 */
  --shadow:  0 12px 28px rgba(220, 38, 38, 0.12);
}

/* Rosso + Dark (contrastato) */
.dark.theme-rosso {
  --bg: #120606;
  --bg-alt: #220c0c;     /* più chiaro di ~8–10 L* rispetto a --bg */
  --surface: #2a1010;
  --text: #f3f4f6;
  --muted: #d6cccc;
  --border: #341515;
  --primary: #f87171;     /* red-400 */
  --primary-600: #ef4444; /* red-500 */
  --primary-700: #dc2626; /* red-600 */
  --shadow:  0 12px 28px rgba(0, 0, 0, 0.45);
}

/* ===== Tema Verde (nuovo) ===== */
.theme-verde {
  --primary: #16a34a;    /* green-600 */
  --primary-600: #15803d;
  --primary-700: #166534;
  --bg: #f0fdf4;         /* green-50 */
  --bg-alt: #ffffff;
  --surface: #ffffff;
  --text: #064e3b;       /* green-900 */
  --muted: #4b5563;      /* slate-600 */
  --border: #bbf7d0;     /* green-200 */
  --success: #16a34a;
  --warning: #eab308;
  --danger:  #dc2626;
  --shadow:  0 12px 28px rgba(22, 163, 74, 0.12);
}
.dark.theme-verde {
  --bg: #052e16;
  --bg-alt: #064e3b;
  --surface: #14532d;
  --text: #ecfdf5;
  --muted: #a7f3d0;
  --border: #065f46;
  --primary: #4ade80;    /* green-400 */
  --primary-600: #22c55e;
  --primary-700: #16a34a;
  --success: #22c55e;
  --warning: #facc15;
  --danger:  #f87171;
  --shadow:  0 12px 28px rgba(0, 0, 0, 0.45);
}
