:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f242d;
  --border: #2a303b;
  --text: #e6e8ec;
  --text-dim: #9aa3b2;
  --accent: #7cc4ff;
  --accent-2: #4d9fe0;
  --danger: #ff6b6b;
  --ok: #6bd495;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  --tap: 48px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

h1,
h2,
h3 {
  margin: 0 0 0.5em;
  font-weight: 600;
}

.accent {
  color: var(--accent);
}

/* Flash messages */
.flash {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--danger);
  color: white;
  padding: 12px 16px;
  z-index: 100;
  text-align: center;
  font-weight: 500;
}

/* Login page */
.login-wrap {
  max-width: 380px;
  margin: 15vh auto 0;
  padding: 24px;
  text-align: center;
}

.login-wrap h1 {
  font-size: 32px;
  margin-bottom: 32px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-form input {
  height: var(--tap);
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 17px;
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-form button {
  height: var(--tap);
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #001726;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  font-size: 20px;
  margin: 0;
}

.btn-link {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14px;
  padding: 8px;
}

/* Tabs */
.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 49px;
  z-index: 9;
}

.tab {
  flex: 1;
  height: var(--tap);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.badge {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  vertical-align: middle;
}

.tab.active .badge {
  background: var(--accent-2);
  color: white;
}

/* Panels */
main {
  padding: 16px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
}

.btn.big {
  min-height: 64px;
  font-size: 18px;
  width: 100%;
  border-radius: var(--radius-lg);
}

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

.btn.ghost {
  background: transparent;
}

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

.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Preview */
.preview {
  margin-top: 16px;
  padding: 12px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
}

.preview.hidden {
  display: none;
}

#preview-img {
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--surface-2);
}

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

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

/* Status */
.status {
  margin-top: 16px;
  padding: 12px;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text-dim);
  min-height: 20px;
}

.status.ok {
  background: rgba(107, 212, 149, 0.12);
  color: var(--ok);
}

.status.err {
  background: rgba(255, 107, 107, 0.12);
  color: var(--danger);
}

/* Files */
.file-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-item {
  display: flex;
  align-items: stretch;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.file-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  text-decoration: none;
  color: var(--text);
  min-width: 0;
}

.thumb {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-2);
}

.thumb-doc {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.file-meta {
  min-width: 0;
  flex: 1;
}

.file-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-sub {
  font-size: 12px;
  color: var(--text-dim);
}

.file-del {
  display: flex;
  margin: 0;
}

.file-del button {
  width: var(--tap);
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
}

.file-del button:active {
  background: rgba(255, 107, 107, 0.12);
  color: var(--danger);
}

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
}

/* Chess placeholder */
.placeholder {
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-align: center;
}

.placeholder h2 {
  color: var(--accent);
}

.placeholder .hint {
  color: var(--text-dim);
  font-size: 14px;
  margin-top: 16px;
}

/* ─────────────────────────────────
   NFC / Chess tab
   ───────────────────────────────── */

.nfc-hw-status {
  padding: 8px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 14px;
  text-align: center;
}

.nfc-hw-status.ok {
  background: rgba(107, 212, 149, 0.12);
  color: var(--ok);
}

.nfc-hw-status.err {
  background: rgba(255, 107, 107, 0.12);
  color: var(--danger);
}

.nfc-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
  min-height: 120px;
  transition: border-color 0.25s, background 0.25s;
}

.nfc-card.nfc-known {
  border-color: var(--ok);
  background: rgba(107, 212, 149, 0.06);
}

.nfc-card.nfc-unknown {
  border-color: var(--accent);
  background: rgba(124, 196, 255, 0.06);
}

.nfc-idle-msg {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: var(--text-dim);
  padding: 12px 0;
}

.nfc-idle-msg.hidden {
  display: none;
}

.nfc-pulse-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(124, 196, 255, 0.6);
  animation: nfc-pulse 1.6s infinite;
}

@keyframes nfc-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(124, 196, 255, 0.6);
  }
  70% {
    box-shadow: 0 0 0 14px rgba(124, 196, 255, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(124, 196, 255, 0);
  }
}

.nfc-detected.hidden {
  display: none;
}

.nfc-uid-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.nfc-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}

.nfc-uid {
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 15px;
  color: var(--text);
  word-break: break-all;
}

.nfc-known-info {
  display: flex;
  align-items: center;
  gap: 14px;
}

.nfc-known-info.hidden {
  display: none;
}

.nfc-name {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.nfc-color-chip {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.nfc-register-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

.nfc-register-form.hidden {
  display: none;
}

.nfc-register-form input[type="text"] {
  width: 100%;
  height: var(--tap);
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
}

.nfc-form-actions {
  display: flex;
  gap: 10px;
}

.nfc-form-actions .btn {
  flex: 1;
}

.nfc-known-actions {
  display: flex;
  justify-content: center;
  margin-top: 12px;
}

.nfc-known-actions.hidden {
  display: none;
}

.nfc-known-actions .btn {
  min-width: 120px;
}

.nfc-register-form input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.nfc-color-choice {
  display: flex;
  gap: 8px;
}

.nfc-color-opt {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--tap);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  padding: 0 8px;
  transition: border-color 0.15s, background 0.15s;
}

.nfc-color-opt input {
  display: none;
}

.nfc-color-opt:has(input:checked) {
  border-color: var(--accent);
  background: rgba(124, 196, 255, 0.12);
}

/* Color dots */
.dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}

.dot-yellow {
  background: #f1c40f;
  box-shadow: 0 0 8px rgba(241, 196, 15, 0.5);
}

.dot-green {
  background: #27ae60;
  box-shadow: 0 0 8px rgba(39, 174, 96, 0.5);
}

.dot-red {
  background: #e74c3c;
  box-shadow: 0 0 8px rgba(231, 76, 60, 0.5);
}

.nfc-color-chip.dot {
  width: 32px;
  height: 32px;
  border-width: 2px;
}

/* Tags list */
.nfc-tags-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 20px;
}

.nfc-tags-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.nfc-tags-header h3 {
  margin: 0;
  font-size: 15px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.nfc-tags-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nfc-tags-list .empty {
  padding: 20px 10px;
  color: var(--text-dim);
  text-align: center;
  font-size: 14px;
}

.nfc-tag-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.nfc-tag-color {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.nfc-tag-meta {
  flex: 1;
  min-width: 0;
}

.nfc-tag-name {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nfc-tag-uid {
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 11px;
  color: var(--text-dim);
}

.nfc-tag-del {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  border-radius: 50%;
}

.nfc-tag-del:active {
  background: rgba(255, 107, 107, 0.12);
  color: var(--danger);
}

/* LED test buttons */
.nfc-led-test {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.nfc-led-test .nfc-label {
  display: block;
  margin-bottom: 10px;
}

.nfc-led-buttons {
  display: flex;
  gap: 8px;
}

.led-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 8px;
  font-size: 14px;
}

/* Magnet section */
.magnet-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-top: 14px;
  text-align: center;
}

.magnet-section .nfc-label {
  display: block;
  margin-bottom: 12px;
}

.magnet-btn {
  width: 100%;
  min-height: 72px;
  font-size: 19px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--surface-2);
  border: 2px solid var(--border);
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.magnet-btn .magnet-icon {
  font-size: 28px;
  filter: grayscale(0.3);
  transition: filter 0.2s;
}

.magnet-btn.active {
  background: rgba(255, 107, 107, 0.18);
  border-color: var(--danger);
  color: var(--danger);
  animation: magnet-glow 1.2s ease-in-out infinite alternate;
}

.magnet-btn.active .magnet-icon {
  filter: none;
}

.magnet-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@keyframes magnet-glow {
  from {
    box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.3);
  }
  to {
    box-shadow: 0 0 18px 4px rgba(255, 107, 107, 0.35);
  }
}

.magnet-timer {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-dim);
  min-height: 18px;
}
