/* LINK IN TIME 1.0 — stile */
:root {
  --primary: #5cff2e;      /* colore principale (personalizzabile) */
  --primary-ink: #021000;  /* testo sopra il colore principale */
  --accent: #5cff2e;       /* colore principale reso leggibile su fondo scuro */
  --bg-color: #000000;
  --surface: rgba(12, 14, 12, 0.82);
  --surface-2: rgba(28, 32, 28, 0.9);
  --line: rgba(255, 255, 255, 0.12);
  --text: #ffffff;
  --muted: #b9c2b9;
  --danger: #ff4d4d;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Montserrat", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #000; }
body { min-height: 100dvh; overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 1.3em; height: 1.3em; fill: currentColor; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Sfondo ---------- */
#bg {
  position: fixed; inset: 0; z-index: -1;
  background-color: var(--bg-color);
  background-size: cover; background-position: center;
  transition: background-color .3s ease;
}
#bg::after { /* bagliore TIME di base */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(120% 60% at 100% 0%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%),
    radial-gradient(120% 60% at 0% 100%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 60%);
}
#bg.has-image::after { background: linear-gradient(180deg, rgba(0,0,0,.55), rgba(0,0,0,.35) 40%, rgba(0,0,0,.6)); }

/* ---------- Splash ---------- */
#splash {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: #000;
  transition: opacity .5s ease;
}
#splash img {
  width: min(94vmin, 600px); height: auto; display: block;
  /* bordi sfumati nel nero, senza toccare il logo */
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 7%, #000 93%, transparent), linear-gradient(to right, transparent, #000 7%, #000 93%, transparent);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(to bottom, transparent, #000 7%, #000 93%, transparent), linear-gradient(to right, transparent, #000 7%, #000 93%, transparent);
  mask-composite: intersect;
  animation: splashIn .7s ease both;
}
#splash.out { opacity: 0; pointer-events: none; }
@keyframes splashIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }

/* ---------- Layout ---------- */
.app {
  max-width: 920px; margin: 0 auto;
  padding: calc(var(--safe-top) + 10px) 14px calc(var(--safe-bottom) + 28px);
  animation: fadeIn .45s ease both;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.topbar, .toolbar, .panel, .link-card {
  background: var(--surface);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px 10px 14px; border-radius: var(--radius);
  position: sticky; top: calc(var(--safe-top) + 6px); z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.brand h1 {
  margin: 0; font-size: 1.25rem; font-weight: 800; letter-spacing: .06em; font-style: italic;
  background: linear-gradient(180deg, #fff 30%, #b8bdb8);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  white-space: nowrap;
}
.brand h1 .accent { color: var(--accent); -webkit-text-fill-color: var(--accent); background: none; }
.slogan { margin: 2px 0 0; font-size: .74rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 12px;
  background: transparent; border: 1px solid var(--line); color: var(--text);
  transition: background .2s, border-color .2s, color .2s, transform .1s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn:active { transform: scale(.94); }

.toolbar { margin-top: 10px; padding: 12px; border-radius: var(--radius); display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.toolbar-row { display: flex; gap: 10px; }
.toolbar-row .btn { min-width: 0; }
.brand > div { min-width: 0; }
.brand h1 { overflow: hidden; text-overflow: ellipsis; }
.btn-add { flex: 1; font-size: 1.05rem; }
.search {
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,.55); border: 1px solid var(--line); border-radius: 14px;
  padding: 0 12px; color: var(--muted);
}
.search:focus-within { border-color: var(--accent); }
.search input {
  flex: 1; min-width: 0; height: 46px; border: 0; background: transparent; outline: none;
  font-size: 16px; color: var(--text);
}
.search input::placeholder { color: #8a948a; }

/* ---------- Pulsanti ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px; border-radius: 14px;
  font-weight: 700; letter-spacing: .02em; text-decoration: none; white-space: nowrap;
  border: 1px solid transparent;
  transition: transform .1s ease, background .2s, box-shadow .2s, border-color .2s, color .2s;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: var(--primary); color: var(--primary-ink);
  box-shadow: 0 0 18px color-mix(in srgb, var(--primary) 45%, transparent);
}
.btn-primary:hover { box-shadow: 0 0 26px color-mix(in srgb, var(--primary) 70%, transparent); }
.btn-primary span { font-size: 1.35em; line-height: 1; }
.btn-ghost { background: rgba(255,255,255,.06); border-color: var(--line); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: rgba(255,77,77,.12); border-color: rgba(255,77,77,.5); color: #ff8080; }
.btn-danger:hover { background: rgba(255,77,77,.22); }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: .88rem; border-radius: 11px; }
.btn.wide { width: 100%; }

/* ---------- Elenco ---------- */
.content { margin-top: 12px; }
.panel { border-radius: var(--radius); padding: 28px 20px; text-align: center; }
.empty img { border-radius: 16px; opacity: .95; }
.empty h2 { margin: 12px 0 6px; font-size: 1.15rem; }
.empty p { margin: 0; color: var(--muted); }

.link-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.link-card {
  display: grid; align-items: center;
  grid-template-columns: auto 58px minmax(0, 1fr) auto;
  grid-template-areas:
    "grip icon text edit"
    "grip icon actions actions";
  column-gap: 12px; row-gap: 8px;
  padding: 12px 12px 12px 6px; border-radius: var(--radius);
  transition: border-color .2s, box-shadow .2s;
  animation: itemIn .3s ease both;
}
.link-card:hover { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
@keyframes itemIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.grip {
  grid-area: grip; align-self: stretch;
  width: 30px; border: 0; background: transparent; color: #7e887e; border-radius: 10px;
  display: grid; place-items: center; touch-action: none; cursor: grab;
}
.grip:hover { color: var(--accent); }
.reorder-off .grip { opacity: .3; cursor: not-allowed; }

.link-icon {
  grid-area: icon; width: 58px; height: 58px; border-radius: 15px; overflow: hidden; flex: none;
  background: #0b0d0b; border: 1px solid var(--line);
  display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(0,0,0,.45);
}
.link-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }
.link-icon img.small { width: 64%; height: 64%; object-fit: contain; } /* favicon piccole */
.link-icon.big { width: 84px; height: 84px; border-radius: 20px; }

.link-text { grid-area: text; min-width: 0; display: grid; gap: 2px; }
.link-name { font-weight: 700; font-size: 1.02rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-url { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-name mark, .link-url mark { background: color-mix(in srgb, var(--accent) 35%, transparent); color: inherit; border-radius: 3px; }

.edit {
  grid-area: edit; width: 40px; height: 40px; border-radius: 11px;
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  display: grid; place-items: center;
}
.edit svg { width: 1.1em; height: 1.1em; }
.edit:hover { color: var(--accent); border-color: var(--accent); }

.link-actions { grid-area: actions; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.act {
  min-height: 40px; padding: 0 6px; border-radius: 11px;
  font-size: .78rem; font-weight: 800; letter-spacing: .06em;
  background: rgba(255,255,255,.06); border: 1px solid var(--line); color: var(--text);
  transition: background .2s, color .2s, border-color .2s, transform .1s;
}
.act:active { transform: scale(.95); }
.act-open { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.act:not(.act-open):hover { border-color: var(--accent); color: var(--accent); }

/* Smartphone: i tre pulsanti usano tutta la larghezza sotto il nome */
@media (max-width: 559px) {
  .link-card { grid-template-areas: "grip icon text edit" "grip actions actions actions"; }
  .act { letter-spacing: .03em; padding: 0 2px; }
}
/* Desktop: tutto su una riga */
@media (min-width: 760px) {
  .app { padding-left: 24px; padding-right: 24px; }
  .link-card {
    grid-template-columns: auto 58px minmax(0, 1fr) 330px auto;
    grid-template-areas: "grip icon text actions edit";
  }
  .act { min-height: 42px; font-size: .8rem; }
}
@media (max-width: 380px) {
  .link-card {
    grid-template-columns: auto 50px minmax(0, 1fr) auto; column-gap: 10px;
    grid-template-areas: "grip icon text edit" "grip actions actions actions";
  }
  .act { padding: 0 2px; }
  .link-icon { width: 50px; height: 50px; border-radius: 13px; }
  .act { font-size: .7rem; letter-spacing: .03em; }
  .brand h1 { font-size: 1.08rem; }
  .toolbar-row .btn-ghost { padding: 0 10px; font-size: .88rem; white-space: normal; line-height: 1.1; text-align: center; }
  .btn-add { font-size: .9rem; padding: 0 8px; gap: 4px; white-space: normal; line-height: 1.1; }
  .btn-add span { font-size: 1.2em; }
  .topbar { padding: 8px 8px 8px 10px; }
  .brand { gap: 9px; }
  .brand img { width: 34px; height: 34px; }
}

/* Trascinamento */
.link-card.dragging {
  position: fixed; z-index: 50; pointer-events: none; margin: 0;
  box-shadow: 0 16px 40px rgba(0,0,0,.7), 0 0 0 2px var(--accent);
  animation: none; opacity: .96;
}
.drop-placeholder {
  border: 2px dashed color-mix(in srgb, var(--accent) 60%, transparent);
  border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 8%, transparent);
}
body.is-dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }

/* ---------- Finestre ---------- */
dialog.sheet {
  width: min(560px, calc(100vw - 20px)); max-height: calc(100dvh - 30px);
  padding: 0; border: 1px solid var(--line); border-radius: 22px;
  background: #0c0f0c; color: var(--text);
  box-shadow: 0 30px 80px rgba(0,0,0,.8), 0 0 40px color-mix(in srgb, var(--accent) 12%, transparent);
  overflow: hidden;
}
dialog.sheet.small { width: min(420px, calc(100vw - 20px)); }
dialog.sheet[open] { animation: sheetIn .25s ease both; }
dialog::backdrop { background: rgba(0,0,0,.7); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
@keyframes sheetIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
dialog form, .sheet-inner { display: flex; flex-direction: column; max-height: calc(100dvh - 32px); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px 20px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 1.15rem; }
.sheet-head .close { width: 38px; height: 38px; font-size: 1rem; }
.sheet-body { padding: 16px 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-body h2 { margin: 4px 0 8px; font-size: 1.15rem; }
.sheet-body h3 { margin: 18px 0 10px; font-size: .82rem; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.sheet-body h3:first-child { margin-top: 2px; }
.sheet-foot { display: flex; gap: 8px; padding: 12px 16px calc(12px + var(--safe-bottom)); border-top: 1px solid var(--line); flex-wrap: wrap; }
.spacer { flex: 1; }

.icon-editor { display: flex; gap: 16px; align-items: center; margin-bottom: 14px; }
.icon-editor-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.hint { margin: 2px 0 0; font-size: .8rem; color: var(--muted); width: 100%; }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field span { font-size: .85rem; color: var(--muted); font-weight: 600; }
.field input {
  height: 48px; padding: 0 14px; border-radius: 12px; font-size: 16px;
  background: #000; border: 1px solid var(--line); outline: none;
}
.field input:focus { border-color: var(--accent); }
.form-error { margin: 0; padding: 10px 12px; border-radius: 10px; background: rgba(255,77,77,.12); color: #ff9a9a; font-size: .88rem; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.setting input[type=color] { width: 54px; height: 38px; padding: 2px; border-radius: 10px; border: 1px solid var(--line); background: #000; cursor: pointer; }
.setting-btns { display: flex; gap: 8px; }
.setting-btns.two { display: grid; grid-template-columns: 1fr 1fr; margin-top: 10px; }
#btnResetTheme { margin-top: 14px; }
.version { margin: 22px 0 4px; text-align: center; font-size: .78rem; color: var(--muted); line-height: 1.6; }

.help section { padding: 4px 0 2px; }
.help h3 { text-transform: none; letter-spacing: 0; font-size: 1rem; color: var(--text); margin: 14px 0 6px; }
.help p { margin: 0 0 6px; color: #d6ddd6; line-height: 1.55; font-size: .93rem; }
.help .notice { margin-top: 12px; padding: 4px 14px 10px; border-radius: 14px; border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); background: color-mix(in srgb, var(--accent) 7%, transparent); }
#btnInstall { margin-top: 10px; }

.share-url { word-break: break-all; padding: 10px 12px; border-radius: 10px; background: #000; border: 1px solid var(--line); font-size: .85rem; color: var(--muted); margin: 0 0 12px; }
.share-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- Avvisi ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 22px); z-index: 200;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 32px);
  padding: 12px 18px; border-radius: 14px;
  background: #0f130f; border: 1px solid var(--accent); color: var(--text);
  box-shadow: 0 10px 30px rgba(0,0,0,.6), 0 0 18px color-mix(in srgb, var(--accent) 30%, transparent);
  font-weight: 600; font-size: .92rem; display: flex; align-items: center; gap: 12px;
  transition: opacity .25s ease, transform .25s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast.error { border-color: var(--danger); }
.toast button { background: var(--primary); color: var(--primary-ink); border: 0; border-radius: 10px; padding: 8px 12px; font-weight: 800; }
.noscript { color: #fff; text-align: center; padding: 40px 20px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
