/* Jkd Totem — precision-instrument dark theme */

:root {
  color-scheme: dark;
  --ink: #0a0c0f;
  --panel: #12161c;
  --panel-2: #171c23;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.15);
  --text: #ece7dc;
  --text-dim: #99998f;
  --text-faint: #60635f;
  --amber: #e8a23a;
  --amber-hi: #ffc470;
  --red: #ff5d5d;
  --green: #58d68d;
  --font-display: "Fraunces", Georgia, "Songti SC", serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;
  --font-ui: "Instrument Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  --radius: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: var(--font-ui);
  background: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

::selection { background: rgba(232, 162, 58, 0.32); color: #fff; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.22); background-clip: content-box; }

/* ---- atmosphere ---- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(1200px 700px at 88% -12%, rgba(232, 162, 58, 0.13), transparent 60%),
    radial-gradient(900px 620px at -12% 112%, rgba(88, 214, 141, 0.07), transparent 55%),
    var(--ink);
}

.backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.026) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.026) 1px, transparent 1px);
  background-size: 46px 46px;
  -webkit-mask-image: radial-gradient(ellipse at 50% 0%, #000 0%, transparent 72%);
  mask-image: radial-gradient(ellipse at 50% 0%, #000 0%, transparent 72%);
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  opacity: 0.045;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---- masthead ---- */

.masthead {
  display: flex;
  align-items: center;
  gap: 26px;
  max-width: 1080px;
  margin: 0 auto;
  padding: 30px 32px 12px;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark { width: 42px; height: 42px; color: var(--amber); filter: drop-shadow(0 6px 16px rgba(232, 162, 58, 0.35)); }
.brand-mark svg { width: 100%; height: 100%; display: block; }

.brand-name {
  margin: 0;
  font-family: var(--font-display);
  font-size: 27px;
  font-weight: 600;
  letter-spacing: 0.05em;
  line-height: 1;
  color: var(--text);
  font-variation-settings: "opsz" 60;
}

.brand-sub {
  margin: 6px 0 0;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.clock { margin-left: auto; text-align: right; }
.clock-time {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.clock-meta {
  display: block;
  margin-top: 2px;
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 14px;
  line-height: 1;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.btn svg { width: 16px; height: 16px; }
.btn:active { transform: translateY(0) scale(0.99); }

.btn-primary {
  background: linear-gradient(180deg, var(--amber-hi), var(--amber));
  color: #1c1306;
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow: 0 8px 22px -8px rgba(232, 162, 58, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px -8px rgba(232, 162, 58, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-color: var(--line-strong);
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.24); }

.btn-block { width: 100%; margin-top: 16px; }

/* ---- layout ---- */

.wrap { max-width: 1080px; margin: 0 auto; padding: 16px 32px 72px; }

.accounts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 18px;
}

/* ---- account card ---- */

.account {
  position: relative;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.008)), var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 20px 18px;
  overflow: hidden;
  animation: rise 0.5s cubic-bezier(0.22, 0.9, 0.28, 1) both;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.account::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--avatar-color, var(--amber)), transparent);
  opacity: 0.55;
}

.account:hover {
  transform: translateY(-3px);
  border-color: var(--line-strong);
  box-shadow: 0 20px 44px -18px rgba(0, 0, 0, 0.85), inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.account-head {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 0;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.account-head:focus { outline: none; }
.account-head:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; border-radius: 10px; }

.chev {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  color: var(--text-faint);
  transition: transform 0.2s ease;
}
.account.is-open .chev { transform: rotate(180deg); }

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px rgba(88, 214, 141, 0.65);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}
.status-dot.is-expiring { background: var(--red); box-shadow: 0 0 8px rgba(255, 93, 93, 0.8); animation: breathe 1s ease infinite; }

.avatar {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 14px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  color: #0d0b07;
  background: var(--avatar-color, var(--amber));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 8px 18px -8px var(--avatar-color, var(--amber));
}

.meta { min-width: 0; flex: 1; }
.issuer { display: block; font-size: 15px; font-weight: 650; letter-spacing: 0.01em; color: var(--text); }
.account-name {
  display: block;
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-detail { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.account-detail[hidden] { display: none; }

.account-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.1); border-color: var(--line-strong); }
.icon-btn.danger:hover { color: var(--red); background: rgba(255, 93, 93, 0.12); border-color: rgba(255, 93, 93, 0.35); }

/* ---- code row ---- */

.code-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-top: 0;
}

.code {
  display: flex;
  align-items: baseline;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: clamp(30px, 6.5vw, 40px);
  line-height: 1;
  letter-spacing: 0.05em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: all;
}
.code .code-sep { width: 0.42em; }
.code:hover { color: var(--amber-hi); }

.ring { position: relative; width: 46px; height: 46px; flex: 0 0 auto; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); display: block; }
.ring .track { fill: none; stroke: rgba(255, 255, 255, 0.08); stroke-width: 3.5; }
.ring .progress {
  fill: none;
  stroke: var(--amber);
  stroke-width: 3.5;
  stroke-linecap: round;
  transition: stroke 0.4s ease;
}
.ring-num {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.account.is-expiring .ring .progress { stroke: var(--red); }
.account.is-expiring .ring-num { color: var(--red); }
.account.is-expiring .code { color: #ffd9d9; animation: breathe 1s ease infinite; }

@keyframes breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* ---- version footer ---- */

.foot {
  position: fixed;
  bottom: 10px;
  right: 14px;
  z-index: 40;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  pointer-events: none;
}

/* ---- empty state ---- */

.empty {
  text-align: center;
  padding: 84px 24px 40px;
  animation: rise 0.6s ease both;
}
.empty-glyph { width: 76px; height: 76px; margin: 0 auto 24px; color: var(--amber); opacity: 0.9; filter: drop-shadow(0 10px 24px rgba(232, 162, 58, 0.3)); }
.empty-glyph svg { width: 100%; height: 100%; }
.empty-title { margin: 0 0 12px; font-family: var(--font-display); font-size: 32px; font-weight: 600; }
.empty-copy { margin: 0 0 28px; color: var(--text-dim); line-height: 1.8; }

/* ---- modal ---- */

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; }
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 6, 8, 0.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: fade 0.25s ease both;
}

.modal-panel {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  box-shadow: 0 44px 90px -30px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  padding: 24px;
  animation: pop 0.32s cubic-bezier(0.22, 0.9, 0.28, 1) both;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(18px) scale(0.98); } to { opacity: 1; transform: none; } }

.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-title { margin: 0; font-family: var(--font-display); font-size: 24px; font-weight: 600; letter-spacing: 0.01em; }
.modal-close { background: rgba(255, 255, 255, 0.04); }

/* ---- tabs ---- */

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 5px;
  margin: 20px 0 18px;
}

.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}
.tab svg { width: 16px; height: 16px; }
.tab:hover { color: var(--text); }
.tab.is-active {
  background: rgba(255, 255, 255, 0.07);
  color: var(--amber-hi);
  box-shadow: 0 3px 10px -3px rgba(0, 0, 0, 0.6);
}

.tab-panel { display: none; animation: fade 0.25s ease both; }
.tab-panel.is-active { display: block; }

/* ---- scanner ---- */

.scanner {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  border: 1px solid var(--line-strong);
}
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner-overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, 0.22); }

.scan-frame { position: relative; width: 58%; aspect-ratio: 1; }
.corner { position: absolute; width: 28px; height: 28px; border: 2.5px solid var(--amber); filter: drop-shadow(0 0 6px rgba(232, 162, 58, 0.6)); }
.corner.tl { top: 0; left: 0; border-right: 0; border-bottom: 0; border-radius: 8px 0 0 0; }
.corner.tr { top: 0; right: 0; border-left: 0; border-bottom: 0; border-radius: 0 8px 0 0; }
.corner.bl { bottom: 0; left: 0; border-right: 0; border-top: 0; border-radius: 0 0 0 8px; }
.corner.br { bottom: 0; right: 0; border-left: 0; border-top: 0; border-radius: 0 0 8px 0; }

.scan-line {
  position: absolute;
  left: 8%;
  right: 8%;
  height: 2px;
  top: 6%;
  background: linear-gradient(90deg, transparent, var(--amber-hi), transparent);
  box-shadow: 0 0 14px 2px rgba(232, 162, 58, 0.75);
  animation: scan 2.2s ease-in-out infinite;
}
@keyframes scan {
  0%, 100% { top: 6%; }
  50% { top: 92%; }
}

.scanner-status {
  position: absolute;
  bottom: 12px;
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.88);
  text-shadow: 0 1px 5px rgba(0, 0, 0, 0.85);
}

/* ---- scan alternatives ---- */

.scan-alt { margin-top: 14px; }
.scan-alt .btn { width: 100%; }
.scan-alt-hint { margin: 10px 0 0; text-align: center; font-size: 12px; color: var(--text-faint); }

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

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: var(--text-faint);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }

.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field-label {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.field-label em { font-style: normal; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text-faint); }

.field input,
.field select,
.field textarea {
  width: 100%;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field textarea { resize: vertical; line-height: 1.6; }
.field select { appearance: none; -webkit-appearance: none; cursor: pointer; }
.field input::placeholder, .field textarea::placeholder { color: var(--text-faint); }

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(232, 162, 58, 0.16);
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-full { grid-column: 1 / -1; }

.advanced { margin-top: 14px; }
.advanced summary {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13px;
  padding: 4px 0;
  user-select: none;
  list-style-position: inside;
}
.advanced summary:hover { color: var(--text); }
.advanced[open] summary { margin-bottom: 12px; }

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

.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  z-index: 200;
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 20px 44px -14px rgba(0, 0, 0, 0.85);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: rgba(255, 93, 93, 0.45); color: #ffd9d9; }

/* ---- responsive ---- */

@media (hover: none) {
  .account-actions { opacity: 1; transform: none; }
}

@media (max-width: 640px) {
  .masthead { flex-wrap: wrap; gap: 16px; padding: 20px 20px 8px; }
  .clock { order: 3; width: 100%; text-align: left; margin: 0; }
  .brand-name { font-size: 23px; }
  .wrap { padding: 10px 16px 56px; }
  .accounts { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .code { font-size: 32px; }
  .modal-panel { padding: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
