/* =========================================================================
   Calculosore — Feuille de style Atelier Papier (Accent Bleu Ardoise)
   ========================================================================= */
:root {
  --fd-accent: #3B6B8C;
  --fd-accent-hover: #2F5773;
  --fd-accent-soft: #E8F1F6;

  /* Code couleur pédagogique par rang de position */
  --rank-unit: #2563EB;
  --rank-ten: #C93B2B;
  --rank-hundred: #1D8A56;
  --rank-thousand: #C48A10;
  --rank-default: #26231F;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--fd-bg);
  color: var(--fd-ink);
  font-family: var(--fd-font-body);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

/* Boutons Atelier Papier */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: var(--fd-radius-pill);
  padding: 8px 15px;
  font-family: var(--fd-font-head);
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  border: 1px solid var(--fd-border-strong);
  background: var(--fd-surface);
  color: var(--fd-ink);
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
}

.btn:hover {
  background: var(--fd-surface-soft);
}

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

.btn-soft {
  background: var(--fd-surface-soft);
  border-color: var(--fd-border);
}

.btn-primary {
  background: var(--fd-accent);
  border-color: transparent;
  color: #FFFFFF;
}

.btn-primary:hover {
  background: var(--fd-accent-hover);
}

.btn-primary .fd-pro-pill {
  background: rgba(255, 255, 255, 0.22);
  color: #FFFFFF;
  border-color: rgba(255, 255, 255, 0.35);
}

.btn-success {
  background: var(--fd-success);
  border-color: transparent;
  color: #FFFFFF;
}

.btn-success:hover {
  filter: brightness(0.94);
}

.btn-danger-outline {
  color: var(--fd-danger);
  border-color: rgba(201, 74, 56, 0.45);
  background: var(--fd-surface);
}

.btn-danger-outline:hover {
  background: var(--fd-danger-soft);
}

.btn-icon {
  padding: 8px 10px;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Bouton compte unifié */
.account-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px 5px 6px;
  border-radius: var(--fd-radius-pill);
  border: 1px solid var(--fd-border-strong);
  background: var(--fd-surface-soft);
  font-family: var(--fd-font-head);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--fd-ink);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.account-btn:hover {
  background: #ECE2D2;
}

.account-btn.is-pro {
  border-color: rgba(59, 130, 99, 0.45);
  background: var(--fd-success-soft);
}

.account-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--fd-ink);
  color: var(--fd-bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 800;
  overflow: hidden;
  flex-shrink: 0;
}

.account-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Bannière de notification discrète */
.toast-banner {
  max-width: 720px;
  margin: 8px auto 0;
  padding: 10px 16px;
  border-radius: 16px;
  background: var(--fd-success-soft);
  border: 1px solid rgba(59, 130, 99, 0.3);
  color: #214E3A;
  font-size: 0.88rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toast-banner[hidden] {
  display: none;
}

.toast-close {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 4px;
}

/* Zone de travail principale */
.workspace {
  position: relative;
  min-height: calc(100vh - 82px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 160px 88px 24px;
  overflow: auto;
}

.grid-sheet {
  background: rgba(255, 255, 255, 0.78);
  border: 1.5px solid var(--fd-border);
  border-radius: 28px;
  padding: 20px;
  box-shadow: var(--fd-shadow-card);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  transform-origin: center center;
  transition: transform 0.15s ease;
}

.grid-row {
  display: flex;
  align-items: center;
}

/* Case de calcul */
.math-cell {
  width: 76px;
  height: 86px;
  margin: 2px;
  background: var(--fd-surface);
  border: 1.5px solid var(--fd-border);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 2px 6px rgba(38, 35, 31, 0.03);
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.math-cell:hover {
  border-color: var(--fd-border-strong);
  box-shadow: 0 4px 12px rgba(59, 107, 140, 0.09);
}

.carry-row {
  height: 25px;
  display: flex;
  border-bottom: 1px solid var(--fd-border);
  background: #FAF6EE;
}

.carry-box {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  font-family: var(--fd-font-head);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--fd-ink);
  transition: background 0.12s ease;
}

.carry-box:first-child {
  border-right: 1px solid var(--fd-border);
}

.carry-box:hover {
  background: var(--fd-accent-soft);
}

.carry-crossed {
  color: var(--fd-danger);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  font-size: 0.7rem;
}

.main-box {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  font-family: var(--fd-font-head);
  font-weight: 700;
  font-size: 2rem;
  line-height: 1;
  transition: background 0.12s ease;
}

.main-box:hover {
  background: #FDFBF7;
}

.main-box.rank-0 { color: var(--rank-unit); }
.main-box.rank-1 { color: var(--rank-ten); }
.main-box.rank-2 { color: var(--rank-hundred); }
.main-box.rank-3 { color: var(--rank-thousand); text-shadow: 0 1px 0 rgba(113, 63, 18, 0.18); }
.main-box.rank-default { color: var(--rank-default); }

.digit-crossed {
  text-decoration: line-through;
  text-decoration-thickness: 3px;
  text-decoration-color: var(--fd-danger);
  opacity: 0.55;
  font-size: 1.45rem;
}

.main-box.rank-1 .digit-crossed {
  text-decoration-color: var(--fd-ink);
}

.digit-crossed.solo {
  font-size: 2rem;
}

.digit-replacement {
  font-size: 1.75rem;
}

/* Ligne de barre d'opération intelligente */
.line-cell {
  width: 80px;
  height: 22px;
  display: flex;
  align-items: center;
  cursor: pointer;
}

.line-segment {
  width: 100%;
  height: 4px;
  background: var(--fd-ink);
  border-radius: 2px;
}

.line-cell:hover .line-segment {
  background: var(--fd-accent);
}

/* Bourse à retenue latérale */
.carry-pouch {
  position: fixed;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  width: 118px;
  padding: 14px 12px;
  background: var(--fd-surface);
  border: 1.5px solid var(--fd-border);
  border-radius: 24px;
  box-shadow: var(--fd-shadow-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 20;
}

.carry-pouch.has-value {
  border-color: rgba(59, 107, 140, 0.45);
}

.pouch-title {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--fd-font-head);
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--fd-ink);
}

.pouch-slot {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  border: 2px dashed var(--fd-border-strong);
  background: var(--fd-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: var(--fd-font-head);
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--fd-accent);
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.1s ease;
}

.carry-pouch.has-value .pouch-slot {
  border-style: solid;
  border-color: var(--fd-accent);
  background: var(--fd-accent-soft);
}

.pouch-slot:active {
  transform: scale(0.95);
}

.pouch-hint {
  font-size: 0.68rem;
  color: var(--fd-muted-light);
  text-align: center;
  line-height: 1.25;
}

/* Légende & zoom en bas */
.bottom-bar {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border: 1px solid var(--fd-border);
  border-radius: var(--fd-radius-pill);
  padding: 7px 16px;
  box-shadow: var(--fd-shadow-header);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  z-index: 25;
  font-size: 0.78rem;
  color: var(--fd-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
  color: var(--fd-ink);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding-left: 8px;
  border-left: 1px solid var(--fd-border-strong);
}

.zoom-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--fd-border-strong);
  background: var(--fd-surface-soft);
  color: var(--fd-ink);
  font-family: var(--fd-font-head);
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.zoom-btn:hover {
  background: #ECE2D2;
}

/* Modales Atelier Papier */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(38, 35, 31, 0.42);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--fd-surface);
  border: 1px solid var(--fd-border);
  border-radius: 26px;
  padding: 22px;
  box-shadow: var(--fd-shadow-modal);
  user-select: text;
  -webkit-user-select: text;
}

.modal-card.wide {
  max-width: 520px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.modal-title {
  margin: 0;
  font-family: var(--fd-font-head);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--fd-ink);
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--fd-border);
  background: var(--fd-surface-soft);
  color: var(--fd-muted);
  font-size: 1.1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.modal-close:hover {
  background: #ECE2D2;
  color: var(--fd-ink);
}

/* Sélecteur de chiffres & symboles */
.picker-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.picker-chip {
  height: 48px;
  border-radius: 14px;
  border: 1px solid var(--fd-border);
  background: var(--fd-surface-soft);
  color: var(--fd-ink);
  font-family: var(--fd-font-head);
  font-size: 1.35rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.1s ease;
}

.picker-chip:hover {
  background: var(--fd-accent-soft);
  border-color: var(--fd-accent);
  color: var(--fd-accent);
}

.picker-chip.selected {
  background: var(--fd-accent);
  border-color: var(--fd-accent);
  color: #FFFFFF;
}

.picker-chip.sym {
  font-size: 1.15rem;
  background: #FAF6EE;
}

.picker-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.picker-actions .btn {
  flex: 1;
}

/* Modale Compte & Pass Éducatif Pro */
.modal-note {
  background: var(--fd-surface-soft);
  border: 1px solid var(--fd-border);
  border-radius: 16px;
  padding: 12px 14px;
  font-size: 0.88rem;
  color: var(--fd-muted);
  margin-bottom: 14px;
}

.modal-note.locked {
  background: var(--fd-accent-soft);
  border-color: rgba(59, 107, 140, 0.25);
  color: #214359;
  font-weight: 700;
}

.plan-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0;
}

.plan-card {
  background: var(--fd-bg);
  border: 1.5px solid var(--fd-border);
  border-radius: 18px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.plan-card.featured {
  border-color: var(--fd-accent);
  background: var(--fd-accent-soft);
}

.plan-price {
  font-family: var(--fd-font-head);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--fd-ink);
}

.input-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.text-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--fd-border-strong);
  background: var(--fd-bg);
  font-family: var(--fd-font-body);
  font-size: 0.92rem;
  color: var(--fd-ink);
}

.text-input:focus {
  outline: 2px solid var(--fd-accent);
  outline-offset: 1px;
}

.saved-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
  max-height: 280px;
  overflow-y: auto;
}

.saved-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--fd-bg);
  border: 1px solid var(--fd-border);
}

.saved-item-title {
  font-family: var(--fd-font-head);
  font-weight: 700;
  font-size: 0.94rem;
}

.saved-item-preview {
  font-size: 0.8rem;
  color: var(--fd-muted);
}

.status-msg {
  margin-top: 10px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--fd-accent);
}

.status-msg.error {
  color: var(--fd-danger);
}

.verify-hero {
  text-align: center;
  padding: 8px 0 12px;
}

.verify-hero img {
  width: 84px;
  height: 84px;
  object-fit: contain;
  margin-bottom: 10px;
}

.verify-msg {
  white-space: pre-line;
  color: var(--fd-muted);
  font-size: 0.95rem;
  line-height: 1.55;
  margin: 0 0 16px;
}

@media (max-width: 820px) {
  .workspace {
    padding: 18px 14px 160px 14px;
  }
  .carry-pouch {
    top: auto;
    bottom: 66px;
    right: 12px;
    transform: none;
    width: auto;
    flex-direction: row;
    padding: 8px 12px;
    border-radius: 18px;
  }
  .pouch-slot {
    width: 48px;
    height: 48px;
    font-size: 1.6rem;
    border-radius: 14px;
  }
  .pouch-hint {
    display: none;
  }
  .math-cell {
    width: 64px;
    height: 76px;
  }
  .line-cell {
    width: 68px;
  }
  .plan-grid {
    grid-template-columns: 1fr;
  }
}
