/* ─── Reset & root ──────────────────────────────────────────────────────── */
:root {
  --bg:        #0a0b0f;
  --bg-panel:  #0f1118;
  --bg-card:   #13161f;
  --border:    #2a2d3a;
  --border-hi: #3d3520;
  --gold:      #c9a84c;
  --gold-dim:  #7d6830;
  --gold-glow: rgba(201,168,76,0.18);
  --red-bright:#c84444;
  --text:      #d4c9b0;
  --text-dim:  #6e6a5e;
  --text-hi:   #f0e8d0;
  --white:     #f5f0e8;
  --mana-w: #f9f6e8; --mana-u: #3a6fa8; --mana-b: #1e1228;
  --mana-r: #b03020; --mana-g: #1a6635; --mana-c: #a0a0a0;
}

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

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Crimson Pro', Georgia, serif;
  font-size: 16px;
}

/* Grain overlay */
body::before {
  content: '';
  position: fixed; inset: 0; pointer-events: none; z-index: 999;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  opacity: 0.35;
}

/* ─── App shell ─────────────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ─── Header ────────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
  z-index: 10;
}

.logo { display: flex; align-items: baseline; gap: 10px; }
.logo-main {
  font-family: 'Cinzel', serif;
  font-size: 22px; font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--gold);
  text-shadow: 0 0 24px var(--gold-glow);
}
.logo-sub {
  font-family: 'Crimson Pro', serif;
  font-size: 13px; font-weight: 300;
  letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--text-dim);
}

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

.status-pill {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 12px; border-radius: 20px;
  border: 1px solid var(--border);
  font-size: 12px; letter-spacing: 0.08em;
  color: var(--text-dim); background: var(--bg-card);
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.4s, box-shadow 0.4s;
}
.status-dot.ready   { background: #4cad6e; box-shadow: 0 0 8px #4cad6e88; }
.status-dot.scanning {
  background: var(--gold); box-shadow: 0 0 8px var(--gold-glow);
  animation: pulse-dot 1s ease-in-out infinite;
}
.status-dot.error   { background: var(--red-bright); box-shadow: 0 0 8px #c8444488; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; } 50% { opacity: 0.3; }
}

/* ─── Main layout ───────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 440px;
  overflow: hidden;
  min-height: 0;
}

/* ─── Camera panel ──────────────────────────────────────────────────────── */
.camera-panel {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg); overflow: hidden;
}

.camera-toolbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  background: var(--bg-panel); flex-shrink: 0;
}

.select-device {
  flex: 1;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text); padding: 7px 12px; border-radius: 4px;
  font-family: 'Crimson Pro', serif; font-size: 14px;
  cursor: pointer; outline: none;
  transition: border-color 0.2s;
}
.select-device:focus { border-color: var(--gold-dim); }

.btn-scan {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 22px;
  background: var(--gold-dim); border: 1px solid var(--gold);
  color: var(--white);
  font-family: 'Cinzel', serif; font-size: 12px;
  font-weight: 600; letter-spacing: 0.1em;
  border-radius: 4px; cursor: pointer; white-space: nowrap;
  transition: background 0.2s, box-shadow 0.2s;
}
.btn-scan:hover:not(:disabled) {
  background: var(--gold); color: #1a1400;
  box-shadow: 0 0 20px var(--gold-glow);
}
.btn-scan:disabled { opacity: 0.4; cursor: not-allowed; }

.toggle-auto {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--text-dim);
  cursor: pointer; white-space: nowrap; user-select: none;
}
.toggle-auto input[type=checkbox] { accent-color: var(--gold); cursor: pointer; }

.video-wrapper {
  flex: 1; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}

/* Corner brackets */
.video-wrapper::before, .video-wrapper::after,
.video-inner::before, .video-inner::after {
  content: '';
  position: absolute;
  width: 28px; height: 28px;
  border-color: var(--gold-dim); border-style: solid;
  z-index: 5; pointer-events: none; opacity: 0.7;
}
.video-wrapper::before { top: 26px; left: 26px; border-width: 2px 0 0 2px; }
.video-wrapper::after  { top: 26px; right: 26px; border-width: 2px 2px 0 0; }
.video-inner::before   { bottom: 26px; left: 26px; border-width: 0 0 2px 2px; }
.video-inner::after    { bottom: 26px; right: 26px; border-width: 0 2px 2px 0; }

.video-inner {
  position: relative; width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
}

video {
  width: 100%; height: 100%;
  object-fit: contain; border-radius: 2px;
}

.scan-flash {
  position: absolute; inset: 0;
  background: rgba(201,168,76,0.15);
  pointer-events: none; opacity: 0; border-radius: 2px;
  transition: opacity 0.08s;
}
.scan-flash.active { opacity: 1; }

.no-camera {
  display: flex; flex-direction: column;
  align-items: center; gap: 14px; color: var(--text-dim);
}
.no-camera svg { opacity: 0.3; }
.no-camera p { font-size: 15px; font-style: italic; }

/* ─── Info panel ────────────────────────────────────────────────────────── */
.info-panel {
  display: flex; flex-direction: column;
  overflow: hidden; background: var(--bg-panel);
}

.info-scroll {
  flex: 1; overflow-y: auto; padding: 24px 22px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
  min-height: 0;
}

/* Empty state */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%; gap: 18px; color: var(--text-dim);
  text-align: center; padding: 40px 20px;
}
.empty-glyph {
  font-family: 'Cinzel', serif; font-size: 52px;
  opacity: 0.12; line-height: 1;
}
.empty-state h3 {
  font-family: 'Cinzel', serif; font-size: 14px;
  letter-spacing: 0.14em; color: var(--text-dim); font-weight: 400;
}
.empty-state p { font-size: 14px; font-style: italic; max-width: 240px; line-height: 1.6; }
.empty-state kbd {
  display: inline-block; padding: 1px 6px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 3px; font-family: monospace; font-size: 12px;
  color: var(--text-dim);
}

/* ─── Card display ──────────────────────────────────────────────────────── */
.card-display { animation: reveal 0.35s ease; }
@keyframes reveal {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-header { display: flex; gap: 18px; margin-bottom: 22px; }

.card-img-wrap { flex-shrink: 0; width: 110px; }
.card-img {
  width: 110px; border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.6), 0 0 0 1px var(--border);
}
.card-img-placeholder {
  width: 110px; height: 155px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; display: flex; align-items: center;
  justify-content: center; color: var(--text-dim);
  font-size: 22px; opacity: 0.5;
}

.card-meta { flex: 1; min-width: 0; }
.card-name {
  font-family: 'Cinzel', serif; font-size: 17px; font-weight: 600;
  color: var(--text-hi); line-height: 1.25; margin-bottom: 6px;
}
.card-mana { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.card-type-line {
  font-size: 13px; color: var(--text-dim);
  font-style: italic; margin-bottom: 8px; letter-spacing: 0.02em;
}
.card-set-badge {
  display: inline-block; padding: 2px 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 3px; font-size: 11px; color: var(--text-dim);
  letter-spacing: 0.06em;
}
.pt-badge {
  display: inline-block; margin-top: 8px;
  padding: 4px 12px; background: var(--bg-card);
  border: 1px solid var(--border-hi); border-radius: 4px;
  font-family: 'Cinzel', serif; font-size: 15px;
  font-weight: 600; color: var(--gold);
}
.loyalty-badge {
  display: inline-block; margin-top: 8px;
  padding: 4px 12px; background: #1a2a4a;
  border: 1px solid #3a5a8a; border-radius: 4px;
  font-family: 'Cinzel', serif; font-size: 15px;
  font-weight: 600; color: #7ab8f5;
}

/* Sections */
.section { margin-bottom: 22px; }
.section-label {
  font-family: 'Cinzel', serif; font-size: 10px;
  letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--gold-dim); margin-bottom: 10px;
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.oracle-text {
  font-size: 15px; line-height: 1.7; color: var(--text); white-space: pre-line;
}
.oracle-text em { font-style: italic; color: var(--text-dim); }

/* Mana symbols */
.mana-sym {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%;
  font-size: 10px; font-weight: 700;
  font-family: 'Cinzel', serif;
  border: 1.5px solid rgba(255,255,255,0.2); flex-shrink: 0;
}
.mana-W { background: var(--mana-w); color: #333; }
.mana-U { background: var(--mana-u); color: #fff; }
.mana-B { background: var(--mana-b); color: #ccc; border-color: #555; }
.mana-R { background: var(--mana-r); color: #fff; }
.mana-G { background: var(--mana-g); color: #fff; }
.mana-C { background: var(--mana-c); color: #222; }
.mana-X { background: #333; color: #aaa; }
.mana-generic { background: #4a4030; color: var(--gold); }

/* Legality */
.legality-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.format-pill {
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 4px; border-radius: 4px;
  border: 1px solid var(--border); background: var(--bg-card); gap: 3px;
}
.format-pill.legal      { border-color: #2a5e3a; }
.format-pill.not_legal  { border-color: var(--border); opacity: 0.5; }
.format-pill.banned     { border-color: #5e2a2a; }
.format-pill.restricted { border-color: #4a3a10; }
.format-name { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); }
.format-status { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.format-pill.legal      .format-status { color: #4cad6e; }
.format-pill.not_legal  .format-status { color: var(--text-dim); }
.format-pill.banned     .format-status { color: var(--red-bright); }
.format-pill.restricted .format-status { color: #d4a020; }

/* Rulings */
.ruling-item {
  padding: 12px 14px;
  background: var(--bg-card); border-left: 2px solid var(--gold-dim);
  border-radius: 0 4px 4px 0; margin-bottom: 10px;
}
.ruling-date { font-size: 11px; color: var(--text-dim); letter-spacing: 0.06em; margin-bottom: 5px; }
.ruling-text { font-size: 14px; line-height: 1.6; color: var(--text); }
.no-rulings { font-style: italic; color: var(--text-dim); font-size: 14px; }

/* ─── History strip ─────────────────────────────────────────────────────── */
.history-strip {
  display: flex; gap: 8px; padding: 10px 16px;
  border-top: 1px solid var(--border); background: var(--bg);
  overflow-x: auto; scrollbar-width: none; flex-shrink: 0;
  min-height: 46px; align-items: center;
}
.history-strip::-webkit-scrollbar { display: none; }
.history-empty { color: var(--text-dim); font-size: 12px; font-style: italic; white-space: nowrap; }
.history-chip {
  display: flex; align-items: center; padding: 5px 10px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 4px; font-family: 'Crimson Pro', serif;
  font-size: 12px; color: var(--text-dim);
  cursor: pointer; white-space: nowrap;
  transition: border-color 0.2s, color 0.2s; flex-shrink: 0;
}
.history-chip:hover { border-color: var(--gold-dim); color: var(--gold); }
.history-chip.active { border-color: var(--gold); color: var(--gold); }

/* ─── Skeleton ──────────────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, #1e2130 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: 4px; display: block;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.card-header .skeleton { margin-bottom: 8px; }

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 800px) {
  html, body { overflow: auto; }
  .app { height: auto; }
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: 55vw auto;
    overflow: visible;
  }
  .camera-panel { border-right: none; border-bottom: 1px solid var(--border); min-height: 55vw; }
  .info-panel { overflow: visible; }
  .info-scroll { overflow: visible; height: auto; }
}
