/* ============================================================
   Nara NFC cards — admin.
   Same glass material as the cards, dialled down. This is a tool:
   legibility and tap targets win over atmosphere.
   ============================================================ */

@font-face {
  font-family: 'Archivo';
  font-style: normal;
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
  src: url('/fonts/archivo-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Martian Mono';
  font-style: normal;
  font-weight: 100 800;
  font-stretch: 75% 112.5%;
  font-display: swap;
  src: url('/fonts/martianmono-latin.woff2') format('woff2');
}

:root {
  --ink: #070a12;
  --stamp: #f2f0ea;
  --muted: #98a2b6;
  --rule: rgba(255, 255, 255, 0.1);

  --foil-1: #f7e3ae;
  --foil-2: #d5a851;
  --foil-3: #94702a;

  --danger: #ff8a8a;
  --ok: #7fe3a8;

  --glass: rgba(255, 255, 255, 0.075);
  --glass-2: rgba(255, 255, 255, 0.03);
  --field: rgba(6, 9, 16, 0.42);

  --display: 'Archivo', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Martian Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --radius: 16px;
  --ease: cubic-bezier(0.22, 0.68, 0.24, 1);
}

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

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

body {
  margin: 0;
  min-height: 100svh;
  background: var(--ink);
  color: var(--stamp);
  font-family: var(--display);
  /* 16px keeps iOS Safari from zooming when a field takes focus. */
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(46% 32% at 24% 10%, rgba(213, 168, 81, 0.5), transparent 68%),
    radial-gradient(40% 30% at 88% 16%, rgba(104, 142, 240, 0.42), transparent 70%),
    radial-gradient(44% 34% at 74% 84%, rgba(42, 194, 196, 0.34), transparent 70%),
    radial-gradient(46% 36% at 8% 82%, rgba(140, 82, 232, 0.38), transparent 72%);
  filter: blur(26px);
}

a {
  color: inherit;
}

img {
  max-width: 100%;
  display: block;
}

:focus-visible {
  outline: 2px solid var(--foil-1);
  outline-offset: 2px;
  border-radius: 8px;
}

[hidden] {
  display: none !important;
}

/* ---------- glass ---------- */

.panel {
  position: relative;
  z-index: 1;
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 0.9rem;
  background: linear-gradient(158deg, var(--glass), var(--glass-2));
  -webkit-backdrop-filter: blur(22px) saturate(170%);
  backdrop-filter: blur(22px) saturate(170%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.14) inset,
    0 0 0 1px rgba(255, 255, 255, 0.07),
    0 18px 40px -24px rgba(0, 0, 0, 0.85);
}

@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .panel {
    background: linear-gradient(158deg, rgba(24, 30, 46, 0.95), rgba(14, 19, 31, 0.95));
  }
}

.panel-title {
  margin: 0 0 0.85rem;
  font-family: var(--mono);
  font-size: 0.58rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.panel-head .panel-title {
  margin: 0;
}

details.panel > summary {
  cursor: pointer;
  margin: 0;
  list-style: none;
}

details.panel > summary::-webkit-details-marker {
  display: none;
}

details.panel > summary::after {
  content: ' ▾';
}

details.panel[open] > summary {
  margin-bottom: 0.9rem;
}

.panel-danger {
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.1) inset,
    0 0 0 1px rgba(255, 138, 138, 0.22),
    0 18px 40px -24px rgba(0, 0, 0, 0.85);
}

/* ---------- sign in ---------- */

.gate {
  position: relative;
  z-index: 1;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.gate-panel {
  width: min(23rem, 100%);
  margin: 0;
  padding: 1.6rem;
}

.gate-title {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 800;
  font-variation-settings: 'wdth' 110, 'wght' 800;
  letter-spacing: -0.02em;
  background: linear-gradient(101deg, var(--foil-3), var(--foil-1) 42%, var(--foil-2) 68%, var(--foil-3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.gate-sub {
  margin: 0.3rem 0 1.2rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.gate-error {
  margin: 0.8rem 0 0;
  color: var(--danger);
  font-size: 0.88rem;
}

/* ---------- chrome ---------- */

.app {
  position: relative;
  z-index: 1;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: env(safe-area-inset-top);
  background: rgba(7, 10, 18, 0.72);
  -webkit-backdrop-filter: blur(18px) saturate(170%);
  backdrop-filter: blur(18px) saturate(170%);
  border-bottom: 1px solid var(--rule);
}

.topbar-in {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  max-width: 54rem;
  margin-inline: auto;
  padding: 0.7rem max(0.9rem, env(safe-area-inset-left));
}

.topbar-title {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 700;
  font-variation-settings: 'wdth' 108, 'wght' 700;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  gap: 0.4rem;
}

/* Sign out is the least likely thing wanted on a phone; keep the two that
   matter and let it come back with room. */
@media (max-width: 30rem) {
  #logoutBtn {
    display: none;
  }
}

.wrap {
  max-width: 54rem;
  margin-inline: auto;
  padding:
    1rem
    max(0.9rem, env(safe-area-inset-right))
    max(2.5rem, env(safe-area-inset-bottom))
    max(0.9rem, env(safe-area-inset-left));
}

/* ---------- live preview ----------
   Hidden by default on a phone, where the form needs the whole screen; the
   Preview button in the topbar toggles it. On a wide screen it earns a
   permanent column of its own. */

.preview {
  display: none;
  margin-bottom: 0.9rem;
}

body.show-preview .preview {
  display: block;
}

.preview-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 390 / 844;
  max-height: 62svh;
  margin-inline: auto;
  border-radius: 18px;
  overflow: hidden;
  background: #070a12;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.12) inset,
    0 18px 40px -22px rgba(0, 0, 0, 0.9);
}

/* aspect-ratio sets the box; the iframe fills whatever that resolves to. */
.preview-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.preview-note {
  margin: 0.5rem 0 0;
  text-align: center;
  font-size: 0.74rem;
  color: var(--muted);
}

.preview-note[data-state='error'] {
  color: var(--danger);
}

@media (min-width: 68rem) {
  .wrap {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 22rem;
    grid-template-areas:
      'rail    rail'
      'form    preview'
      'site    preview'
      'hint    preview';
    gap: 0 1.4rem;
    align-items: start;
  }

  .cards-rail {
    grid-area: rail;
  }
  #editor {
    grid-area: form;
  }
  .wrap > details {
    grid-area: site;
  }
  .tag-hint {
    grid-area: hint;
  }

  /* Always on at this width, regardless of the toggle. */
  .preview,
  body.show-preview .preview {
    display: block;
    grid-area: preview;
    position: sticky;
    top: 4.6rem;
  }

  .preview-frame {
    max-height: calc(100svh - 8rem);
  }

  /* The toggle only means something where the preview can be hidden. */
  #previewToggle {
    display: none;
  }
}

#previewToggle[aria-pressed='true'] {
  color: #1b1405;
  background: linear-gradient(140deg, var(--foil-1), var(--foil-2) 58%, var(--foil-3));
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset;
}

/* ---------- card switcher ---------- */

.cards-rail {
  display: flex;
  gap: 0.45rem;
  margin-bottom: 0.9rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 0.2rem;
}

.cards-rail::-webkit-scrollbar {
  display: none;
}

.pills {
  display: flex;
  gap: 0.45rem;
}

.pill {
  flex: none;
  min-height: 2.6rem;
  padding: 0 0.95rem;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.09) inset;
  color: var(--stamp);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.16s var(--ease);
}

.pill[aria-selected='true'] {
  background: linear-gradient(140deg, var(--foil-1), var(--foil-2) 60%, var(--foil-3));
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset;
  color: #1b1405;
  font-weight: 700;
}

.pill-add {
  color: var(--muted);
}

/* ---------- fields ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0.75rem;
}

.site-grid {
  grid-template-columns: 1fr;
}

.field {
  display: block;
  margin-bottom: 0.75rem;
}

.grid .field {
  margin-bottom: 0;
}

/* A hint on the last grid row would otherwise butt straight into the label
   of whatever field follows the grid. */
.grid + .field {
  margin-top: 0.9rem;
}

.field-label {
  display: block;
  margin-bottom: 0.32rem;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--muted);
}

.field-hint {
  display: block;
  margin: 0.35rem 0 0;
  font-size: 0.76rem;
  line-height: 1.4;
  color: var(--muted);
}

.input {
  width: 100%;
  min-height: 2.9rem;
  padding: 0.55rem 0.75rem;
  border: 0;
  border-radius: 11px;
  background: var(--field);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  color: var(--stamp);
  font-family: inherit;
  font-size: 1rem;
  transition: box-shadow 0.16s var(--ease);
}

textarea.input {
  min-height: 4.2rem;
  resize: vertical;
  line-height: 1.45;
}

select.input {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2.2rem;
}

.input::placeholder {
  color: rgba(152, 162, 182, 0.6);
}

.input:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--foil-2) inset;
}

/* :user-invalid, not :invalid — an untouched required field is empty, not
   wrong, and should not greet you in red. */
.input:user-invalid {
  box-shadow: 0 0 0 2px rgba(255, 138, 138, 0.7) inset;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.75rem;
  padding: 0 1rem;
  border: 0;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 650;
  color: var(--stamp);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: filter 0.16s var(--ease), transform 0.16s var(--ease);
}

.btn-primary {
  color: #1b1405;
  background: linear-gradient(140deg, var(--foil-1), var(--foil-2) 58%, var(--foil-3));
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset;
}

.btn-quiet {
  background: rgba(255, 255, 255, 0.075);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}

.btn-danger {
  color: var(--danger);
  box-shadow: 0 0 0 1px rgba(255, 138, 138, 0.3) inset;
}

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

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

@media (hover: hover) {
  .btn:not(:disabled):hover {
    filter: brightness(1.15);
  }
}

.gate-panel .btn {
  width: 100%;
  min-height: 3rem;
  margin-top: 0.35rem;
}

/* ---------- photo ---------- */

.photo-row {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 0.9rem;
}

.photo-preview {
  flex: none;
  width: 5.5rem;
  aspect-ratio: 4 / 5;
  display: grid;
  place-items: center;
  border-radius: 13px;
  overflow: hidden;
  background: rgba(6, 9, 16, 0.5);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12) inset;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
}

.photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-actions {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.photo-actions .field-hint {
  flex: 1 0 100%;
}

/* ---------- links editor ---------- */

.links-edit {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* On a phone the label needs the whole row — sharing it with three control
   buttons truncates it to "naradev.c". Controls drop to their own line. */
.link-edit {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    'icon label'
    'url  url'
    'controls controls';
  gap: 0.5rem;
  padding: 0.6rem;
  border-radius: 13px;
  background: rgba(6, 9, 16, 0.3);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.07) inset;
}

.link-icon-btn {
  grid-area: icon;
  display: grid;
  place-items: center;
  width: 2.9rem;
  height: 2.9rem;
  border: 0;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  cursor: pointer;
}

.link-icon-btn svg {
  width: 16px;
  height: 16px;
  fill: var(--foil-1);
}

.link-edit .link-label-in {
  grid-area: label;
  min-width: 0;
}

.link-edit .link-url-in {
  grid-area: url;
}

.link-controls {
  grid-area: controls;
  display: flex;
  justify-content: flex-end;
  gap: 0.25rem;
}

@media (min-width: 34rem) {
  .link-edit {
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      'icon label controls'
      'url  url   url';
  }
}

.icon-btn {
  width: 2.9rem;
  height: 2.9rem;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  transition: color 0.16s var(--ease);
}

@media (hover: hover) {
  .icon-btn:hover {
    color: var(--stamp);
  }
}

.icon-btn.is-danger {
  color: var(--danger);
}

/* ---------- icon picker ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: end center;
  padding: 0;
  background: rgba(4, 6, 11, 0.6);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.sheet-panel {
  width: min(38rem, 100%);
  max-height: 86svh;
  margin: 0;
  display: flex;
  flex-direction: column;
  border-radius: 20px 20px 0 0;
  padding-bottom: max(1.1rem, env(safe-area-inset-bottom));
}

@media (min-width: 40rem) {
  .sheet {
    place-items: center;
    padding: 1.5rem;
  }
  .sheet-panel {
    border-radius: 20px;
  }
}

.sheet-head {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.icon-grid {
  flex: 1 1 auto;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3.4rem, 1fr));
  gap: 0.4rem;
  padding: 0.15rem;
  -webkit-overflow-scrolling: touch;
}

.icon-opt {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.05);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.07) inset;
  cursor: pointer;
  transition: background-color 0.14s var(--ease);
}

.icon-opt svg {
  width: 17px;
  height: 17px;
  fill: var(--stamp);
}

.icon-opt[aria-selected='true'] {
  background: rgba(213, 168, 81, 0.24);
  box-shadow: 0 0 0 1px var(--foil-2) inset;
}

@media (hover: hover) {
  .icon-opt:hover {
    background: rgba(255, 255, 255, 0.12);
  }
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(1.1rem, env(safe-area-inset-bottom));
  z-index: 60;
  max-width: min(30rem, calc(100vw - 2rem));
  padding: 0.8rem 1.1rem;
  border-radius: 14px;
  background: rgba(20, 26, 40, 0.94);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.12) inset,
    0 20px 40px -18px rgba(0, 0, 0, 0.9);
  font-size: 0.9rem;
  line-height: 1.4;
  transform: translate(-50%, calc(100% + 2rem));
  transition: transform 0.36s var(--ease);
}

.toast[data-open='true'] {
  transform: translate(-50%, 0);
}

.toast[data-tone='error'] {
  box-shadow:
    0 0 0 1px rgba(255, 138, 138, 0.45) inset,
    0 20px 40px -18px rgba(0, 0, 0, 0.9);
}

.toast ul {
  margin: 0.4rem 0 0;
  padding-left: 1.1rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.tag-hint {
  margin: 0.4rem 0 0;
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  color: var(--muted);
  overflow-wrap: anywhere;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
