/* =========================================================
   VARIABLES & THEME
========================================================= */
:root {
  --bg: #0d111a;
  --panel: #141821;
  --text: #f0f4fa;
  --muted: #b0b8c6;
  --brand: #4dd0e1;
  --brand-2: #7e57c2;
  --danger: #ff6b6b;
  --success: #4ade80;
  --card: #171c26;
  --border: #2a3040;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(0, 0, 0, .35);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #fafbfe;
    --panel: #ffffff;
    --text: #101321;
    --muted: #5e6779;
    --brand: #0ea5e9;
    --brand-2: #7c3aed;
    --danger: #e11d48;
    --success: #16a34a;
    --card: #ffffff;
    --border: #e6e8ef;
    --shadow: 0 6px 20px rgba(2, 6, 23, .12);
  }
}

/* =========================================================
   BASE
========================================================= */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, system-ui, sans-serif;
  background: radial-gradient(circle at top left, rgba(126, 87, 194, .15), transparent 50%),
              radial-gradient(circle at bottom right, rgba(77, 208, 225, .15), transparent 50%),
              var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a {
  color: var(--brand);
  text-underline-offset: 3px;
  transition: color .2s ease;
}
a:hover { color: var(--brand-2); }

/* =========================================================
   LAYOUT
========================================================= */
.shell { max-width: 1200px; margin: 0 auto; padding: 32px 20px 80px; }

/* =========================================================
   HEADER
========================================================= */
header.app-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 28px;
}
.title { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 50px; height: 50px; border-radius: 14px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: var(--shadow);
}
h1 { font-size: 2rem; margin: 0; font-weight: 700; }
.subtitle { color: var(--muted); font-size: 1rem; margin-top: 4px; }

/* =========================================================
   PANELS
========================================================= */
.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: background .3s ease, border-color .3s ease;
}
.panel.pad { padding: 16px; }

/* =========================================================
   ADD-CARD FORM
========================================================= */
#add-card .grid { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; }
#add-card label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: .9rem; color: var(--muted);
}
#add-card input {
  background: var(--card); color: var(--text);
  border: 1px solid var(--border);
  padding: 12px; border-radius: 10px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
#add-card input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(77, 208, 225, .3);
}
#add-card input.valid { border-color: var(--success); }
#add-card input.invalid { border-color: var(--danger); }
#add-msg { display: inline-block; margin-left: 10px; color: var(--muted); min-height: 1.2em; }

/* =========================================================
   BUTTONS
========================================================= */

/* Base style shared by all three buttons */
:is(#add-btn, #btn-publish, .remove-btn){
  appearance: none;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 16px;
  font: 600 0.95rem/1 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial;
  letter-spacing: .2px;
  cursor: pointer;
  user-select: none;
  transition: transform .15s ease, box-shadow .15s ease, background-color .15s ease,
              border-color .15s ease, color .15s ease, opacity .15s ease;
  outline: none;
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  min-height: 40px;             /* comfortable touch target */
  will-change: transform;
}

/* Focus ring (keyboard) */
:is(#add-btn, #btn-publish, .remove-btn):focus-visible{
  box-shadow:
    0 0 0 3px color-mix(in oklab, var(--brand) 35%, transparent),
    0 0 0 1.5px var(--brand);
}

/* Pressed state */
:is(#add-btn, #btn-publish, .remove-btn):active{
  transform: translateY(0);     /* no "stuck" offset after click */
}

/* Disabled state */
:is(#add-btn, #btn-publish, .remove-btn):disabled{
  opacity: .6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* -----------------------------
   Primary action: PUBBLICA
------------------------------ */
#btn-publish{
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border-color: color-mix(in oklab, var(--brand) 50%, var(--brand-2) 50%);
  box-shadow:
    0 10px 24px rgba(0,0,0,.28),
    0 4px 12px color-mix(in oklab, var(--brand) 22%, transparent);
  transform: translateY(0);
}
#btn-publish:hover{
  transform: translateY(-2px);
  box-shadow:
    0 14px 28px rgba(0,0,0,.34),
    0 6px 16px color-mix(in oklab, var(--brand) 28%, transparent);
}
#btn-publish:active{
  transform: translateY(0);
}

/* -----------------------------
   Secondary/affirmative: AGGIUNGI
   (tonal/soft fill so it’s visible but not competing
   with the primary Publish action)
------------------------------ */
#add-btn{
  background: color-mix(in oklab, var(--brand) 14%, var(--card));
  color: color-mix(in oklab, var(--text) 92%, var(--brand) 8%);
  border-color: color-mix(in oklab, var(--brand) 35%, var(--border));
  box-shadow: 0 6px 18px rgba(0,0,0,.18) inset, 0 2px 8px rgba(0,0,0,.18);
}
#add-btn:hover{
  background: color-mix(in oklab, var(--brand) 22%, var(--card));
  border-color: color-mix(in oklab, var(--brand) 55%, var(--border));
  transform: translateY(-1px);
}
#add-btn:active{
  transform: translateY(0);
}

/* Make the Add button a touch smaller so it reads as a sub-action */
#add-btn{
  padding: 10px 14px;
  font-weight: 600;
  min-height: 38px;
}

/* -----------------------------
   Destructive: RIMUOVI
   (subtle outline until hover)
------------------------------ */
.remove-btn{
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in oklab, var(--danger) 60%, var(--border));
  box-shadow: none;
  padding: 8px 12px;            /* compact inside card */
  font-weight: 700;
}
.remove-btn:hover{
  background: color-mix(in oklab, var(--danger) 14%, transparent);
  color: #fff;
  border-color: var(--danger);
  box-shadow: 0 6px 18px rgba(0,0,0,.18);
}
.remove-btn:focus-visible{
  box-shadow:
    0 0 0 3px color-mix(in oklab, var(--danger) 30%, transparent),
    0 0 0 1.5px var(--danger);
}

/* -----------------------------
   Optional: icon sizing inside buttons
------------------------------ */
:is(#add-btn, #btn-publish, .remove-btn) svg{
  width: 1.05em;
  height: 1.05em;
  flex: 0 0 auto;
  opacity: .95;
}

/* -----------------------------
   Reduced motion preference
------------------------------ */
@media (prefers-reduced-motion: reduce){
  :is(#add-btn, #btn-publish, .remove-btn){
    transition: none;
  }
}


/* =========================================================
   TOOLBAR
========================================================= */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 16px; }
#view-toggle { display: flex; gap: 10px; align-items: center; }
#view-toggle .seg {
  display: inline-flex; background: var(--card);
  border-radius: 12px; padding: 6px; border: 1px solid var(--border);
}
#view-toggle button {
  background: transparent; color: var(--text); border: 0;
  padding: 8px 14px; border-radius: 10px; font-weight: 600;
  transition: background .2s ease;
}
#view-toggle button.active {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
}
#mode-hint { color: var(--muted); font-size: .9rem; margin-left: 6px; }

/* =========================================================
   PAGER
========================================================= */
#pager { display: flex; gap: 8px; align-items: center; margin-left: auto; }
#pager button {
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); padding: 8px 10px; border-radius: 10px;
  transition: background .2s ease, color .2s ease;
}
#pager button:hover { background: var(--brand); color: #fff; }
#page-info { color: var(--muted); font-variant-numeric: tabular-nums; }

/* =========================================================
   BINDER VIEW
========================================================= */
#binder-view { margin-top: 20px; }

/* Box grid */
#cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}
#cards.as-box {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

/* Binder pages */
#cards.as-binder {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 20px; max-width: 1140px; align-items: start; margin-inline: auto;
}
.binder-page {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 12px; padding: 16px;
  background: var(--panel);
  border-radius: 20px; box-shadow: var(--shadow);
  position: relative; border: 1px solid var(--border);
  transition: transform .25s ease, box-shadow .25s ease;
}
.binder-page:hover { transform: translateY(-4px); box-shadow: 0 12px 28px rgba(0,0,0,.4); }
.binder-page::after {
  content: ""; position: absolute; left: -10px; top: 12px; bottom: 12px; width: 6px;
  background: radial-gradient(circle, #333 50%, transparent 52%) 0 0/6px 36px repeat-y; opacity: .25;
}
.binder-page.blank { background: transparent; box-shadow: none; border: 0; }
@media (max-width: 860px) {
  #cards.as-binder { grid-template-columns: 1fr; max-width: 560px; }
}
/* =========================================================
   CARDS
========================================================= */
/* Hover popup */
.card { position: relative; }

/* invisible bridge above the card to keep :hover while moving into popup */
.card::before{
  content:"";
  position:absolute;
  left:50%;
  transform:translateX(-50%);
  bottom:100%;
  width:280px;      /* match popup width-ish */
  height:16px;      /* gap coverage */
}

.card-info {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  background: var(--panel);
  color: var(--text);
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 50;
  width: 260px;
  text-align: left;
}

/* show on hover OR when any child is focused (links, etc.) */
.card:hover .card-info,
.card:focus-within .card-info {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.card-info .hover-img {
  width: 100%;
  border-radius: 8px;
  margin-bottom: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,.5);
}
.card-info::after {
  content: "";
  position: absolute;
  top: 100%; left: 50%;
  transform: translateX(-50%);
  border-width: 6px;
  border-style: solid;
  border-color: var(--panel) transparent transparent transparent;
}


/* =========================================================
   PUBLISH AREA
========================================================= */
#publish { margin-top: 24px; }
#publish .row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
#pub-links { margin: 10px 0 0; color: var(--muted); }
#qr {
  margin-top: 12px; background: var(--panel);
  border-radius: 12px; padding: 12px; display: inline-block; border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* =========================================================
   UTILITY
========================================================= */
.divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  margin: 24px 0; border: 0;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* =========================================================
   WANTED — premium highlight & badge (accessible + resilient)
   Tip: flip the color by changing --wanted below to var(--danger)
========================================================= */
/* ===== WANTED — full-size red ring + badge ===== */
:root { --wanted: var(--danger); } /* red */

.card.wanted{
  /* keep normal shadow; ring comes from ::after so no layout shift */
  box-shadow: var(--shadow);
}

/* full-size ring overlay that follows the card radius */
.card.wanted::after{
  content: "";
  position: absolute;
  inset: -4px;                              /* how “thick/outside” the ring looks */
  border-radius: calc(var(--radius) + 4px);
  pointer-events: none;
  z-index: 2;
  box-shadow:
    0 0 0 3px var(--wanted),                /* crisp ring */
    0 0 18px rgba(225, 29, 72, .35);        /* soft glow */
}

/* badge */
.wanted-badge{
  position: absolute; top: 8px; left: 8px; z-index: 3;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 800; letter-spacing: .2px;
  pointer-events: none;
  background: rgba(225, 29, 72, .18);
  border: 1px solid rgba(225, 29, 72, .55);
  color: #2b0a0f;
  box-shadow: 0 6px 14px rgba(0,0,0,.22);
}
.card:not(.wanted) .wanted-badge{ display: none; }

@media (forced-colors: active){
  .card.wanted::after{ box-shadow: none; border: 3px solid Highlight; inset: 0; }
  .wanted-badge{ background: Highlight; color: ButtonText; border-color: ButtonText; }
}

/* =========================================================
   GUIDED FLOW — UTILITIES & COMPONENTS (non-breaking)
   Append-only; safe with your existing styles
========================================================= */

/* Hide/show helper used by JS for progressive disclosure */
.hidden { display: none !important; }

/* Reusable layout row */
.flex-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* Subtle muted text for hints */
.muted {
  color: var(--muted);
  font-size: 0.92rem;
}

/* Guidance banner at the top (view messages) */
.banner {
  padding: 12px 14px;
  border-radius: 12px;
  margin: 0 0 16px;
  font-weight: 700;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--brand) 8%, var(--panel));
}
.banner-view {
  background: color-mix(in oklab, #fde68a 24%, var(--panel));
  border-color: color-mix(in oklab, #f59e0b 55%, var(--border));
  color: color-mix(in oklab, #713f12 85%, var(--text));
}

/* CTA buttons used in Create/Unlock/Publish panels */
.big-btn {
  appearance: none;
  border: 1px solid color-mix(in oklab, var(--brand) 55%, var(--brand-2) 45%);
  border-radius: 14px;
  padding: 12px 20px;
  font: 700 1rem/1 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  cursor: pointer;
  box-shadow:
    0 10px 24px rgba(0,0,0,.22),
    0 4px 10px color-mix(in oklab, var(--brand) 22%, transparent);
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease, opacity .15s ease;
  min-height: 42px;
}
.big-btn:hover {
  transform: translateY(-1px);
  box-shadow:
    0 14px 28px rgba(0,0,0,.28),
    0 8px 16px color-mix(in oklab, var(--brand) 28%, transparent);
}
.big-btn:active { transform: translateY(0); }
.big-btn:disabled { opacity: .6; cursor: not-allowed; box-shadow: none; }

/* Secondary buttons (view toggle, wanted actions, pager) */
.small-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.small-btn:hover {
  background: color-mix(in oklab, var(--brand) 12%, var(--card));
  border-color: color-mix(in oklab, var(--brand) 45%, var(--border));
}
.small-btn:active { transform: translateY(0); }
.small-btn:disabled { opacity: .6; cursor: not-allowed; }

/* Inputs in guided panels (reuse your token but ensure good spacing) */
#owner-pass-first,
#unlock-pass,
#own-pass,
#add-card input,
#wanted textarea,
#wanted-input {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

/* View toggle row inside binder panel — subtle until needed */
#view-toggle {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}
#view-toggle .small-btn.active {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  border-color: color-mix(in oklab, var(--brand) 60%, var(--brand-2) 40%);
}

/* Pager shown only when needed; keep consistent with theme */
#pager {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
}
#pager.hidden { display: none !important; }
#page-info { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Binder “cards” grid name used in the simplified layout */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

/* Small fade-in when a section becomes visible (optional) */
@keyframes subtleFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.panel:not(.hidden) { animation: subtleFadeIn .18s ease-out; }
