@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@600;700&family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

  :root {
    --bg0: #0b0f14;
    --bg1: #121820;
    --bg2: #1a222d;
    --line: #2a3544;
    --text: #e8eef6;
    --muted: #93a0b3;
    --accent: #f0b429;
    --be: #5eead4;
    --rC: #9ca3af;
    --rR: #3b82f6;
    --rE: #a855f7;
    --rL: #f59e0b;
    --rT: #ec4899;
    --card-w: 252px;
    --card-h: 352px;
  }

  * { box-sizing: border-box; }
  html, body { margin: 0; min-height: 100%; }
  body {
    font-family: 'IBM Plex Sans', system-ui, sans-serif;
    color: var(--text);
    background:
      radial-gradient(1200px 600px at 10% -10%, #1a2740 0%, transparent 55%),
      radial-gradient(900px 500px at 100% 0%, #2a1830 0%, transparent 50%),
      linear-gradient(180deg, #0d1218, var(--bg0));
  }

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

  .wrap { position: relative; z-index: 1; max-width: 1180px; margin: 0 auto; padding: 28px 18px 80px; }

  header {
    display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end;
    justify-content: space-between; margin-bottom: 22px;
  }
  .brand h1 {
    font-family: Cinzel, Georgia, serif;
    font-size: clamp(1.6rem, 3vw, 2.3rem);
    margin: 0 0 4px;
    letter-spacing: .04em;
    background: linear-gradient(90deg, #f8e7a0, #f0b429 40%, #fff6c8);
    -webkit-background-clip: text; background-clip: text; color: transparent;
  }
  .brand p { margin: 0; color: var(--muted); font-size: .95rem; }

  .tabs { display: flex; gap: 8px; flex-wrap: wrap; }
  .tab {
    border: 1px solid var(--line); background: var(--bg1); color: var(--text);
    border-radius: 999px; padding: 8px 14px; cursor: pointer; font-weight: 600;
  }
  .tab.active { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(240,180,41,.25) inset; color: var(--accent); }

  .panel { display: none; }
  .panel.active { display: block; }

  .toolbar {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
    background: rgba(18,24,32,.85); border: 1px solid var(--line);
    border-radius: 14px; padding: 12px; margin-bottom: 18px;
    backdrop-filter: blur(8px);
  }
  .toolbar label { font-size: .8rem; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
  input, select {
    background: var(--bg0); border: 1px solid var(--line); color: var(--text);
    border-radius: 8px; padding: 8px 10px; font: inherit; min-width: 140px;
  }
  button.btn {
    border: 0; border-radius: 10px; padding: 10px 14px; font-weight: 700;
    cursor: pointer; font-family: inherit; color: #111;
    background: linear-gradient(180deg, #ffd76a, #e0a41a);
  }
  button.btn.secondary {
    background: var(--bg2); color: var(--text); border: 1px solid var(--line);
  }
  button.btn.ghost { background: transparent; color: var(--muted); border: 1px dashed var(--line); }
  button.btn:disabled { opacity: .45; cursor: not-allowed; }
  .hint { color: var(--muted); font-size: .85rem; }

  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--card-w), 1fr));
    gap: 18px; justify-items: center;
  }

  /* ===== MTG-style card ===== */
  .card {
    width: var(--card-w); height: var(--card-h);
    border-radius: 14px; padding: 8px;
    position: relative; overflow: hidden;
    background:
      linear-gradient(145deg, rgba(255,255,255,.12), transparent 40%),
      linear-gradient(180deg, #2a2118, #15110d 60%, #0d0b09);
    border: 2px solid #6b542e;
    box-shadow: 0 12px 28px rgba(0,0,0,.45), inset 0 0 0 1px rgba(255,220,140,.15);
    display: flex; flex-direction: column; gap: 5px;
    transition: transform .18s ease, box-shadow .18s ease;
  }
  .card:hover { transform: translateY(-4px) scale(1.01); }
  .card.r-C { border-color: #7b8494; }
  .card.r-R { border-color: #3b82f6; box-shadow: 0 12px 28px rgba(0,0,0,.45), 0 0 18px rgba(59,130,246,.25); }
  .card.r-E { border-color: #a855f7; box-shadow: 0 12px 28px rgba(0,0,0,.45), 0 0 20px rgba(168,85,247,.28); }
  .card.r-L { border-color: #f59e0b; box-shadow: 0 12px 28px rgba(0,0,0,.45), 0 0 24px rgba(245,158,11,.35); }
  .card.r-T { border-color: #ec4899; box-shadow: 0 12px 28px rgba(0,0,0,.45), 0 0 24px rgba(236,72,153,.4); }

  .card-top {
    display: flex; align-items: center; justify-content: space-between; gap: 6px;
    background: linear-gradient(180deg, #3a2f22, #241c14);
    border: 1px solid rgba(255,220,150,.25); border-radius: 8px; padding: 4px 6px;
  }
  .card-name {
    font-family: Cinzel, Georgia, serif; font-size: .78rem; font-weight: 700;
    line-height: 1.15; flex: 1; color: #f6e8c3;
  }
  .cost {
    width: 26px; height: 26px; border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fff7, transparent 45%),
                linear-gradient(160deg, #5eead4, #0f766e);
    border: 2px solid #99f6e4; color: #042f2e;
    display: grid; place-items: center; font-weight: 800; font-size: .85rem;
    flex-shrink: 0;
  }

  .art {
    height: 118px; border-radius: 8px; border: 1px solid rgba(255,255,255,.12);
    display: grid; place-items: center; position: relative; overflow: hidden;
  }
  .art::after {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(180deg, transparent 60%, rgba(0,0,0,.35));
  }
  .art .emoji { font-size: 3.4rem; filter: drop-shadow(0 6px 10px rgba(0,0,0,.45)); z-index: 1; }

  .type-line {
    font-size: .68rem; color: #d6c7a4; display: flex; justify-content: space-between;
    padding: 0 2px; font-weight: 600; text-transform: capitalize;
  }
  .rarity-dot {
    width: 10px; height: 10px; border-radius: 50%; display: inline-block;
    box-shadow: 0 0 6px currentColor;
  }

  .textbox {
    flex: 1; background: linear-gradient(180deg, #f3e7c8, #e7d4a8);
    color: #1c140c; border-radius: 8px; padding: 7px 8px; font-size: .68rem;
    line-height: 1.3; overflow: hidden; border: 1px solid #b89a5a;
  }
  .textbox .rules { margin: 0 0 6px; font-weight: 500; }
  .textbox .flavor {
    margin: 0; font-style: italic; opacity: .8; border-top: 1px solid rgba(0,0,0,.15);
    padding-top: 5px; font-size: .62rem;
  }
  .keywords { display: flex; flex-wrap: wrap; gap: 3px; margin-bottom: 5px; }
  .kw {
    background: #2a2118; color: #f0d9a0; border-radius: 4px;
    padding: 1px 5px; font-size: .58rem; font-weight: 700;
  }

  .pt {
    position: absolute; right: 10px; bottom: 10px;
    min-width: 52px; height: 28px; border-radius: 8px;
    background: linear-gradient(180deg, #3a2f22, #1a140e);
    border: 1px solid #c9a24b; color: #ffe6a3;
    display: grid; place-items: center; font-weight: 800; font-size: .9rem;
    font-family: 'IBM Plex Mono', monospace;
  }

  .card-meta {
    position: absolute; left: 12px; bottom: 10px;
    font-size: .55rem; color: rgba(246,232,195,.55); font-family: 'IBM Plex Mono', monospace;
  }

  .card-actions {
    display: flex; gap: 6px; margin-top: 8px; width: var(--card-w); justify-content: center;
  }
  .card-actions button {
    flex: 1; font-size: .72rem; padding: 6px 8px; border-radius: 8px;
    border: 1px solid var(--line); background: var(--bg1); color: var(--text); cursor: pointer;
  }
  .card-actions button:hover { border-color: var(--accent); color: var(--accent); }

  .empty {
    text-align: center; color: var(--muted); padding: 48px 12px;
    border: 1px dashed var(--line); border-radius: 14px;
  }

  /* combat */
  .duel {
    display: grid; grid-template-columns: 1fr 280px; gap: 14px;
  }
  @media (max-width: 900px) { .duel { grid-template-columns: 1fr; } }
  .arena {
    background: rgba(18,24,32,.9); border: 1px solid var(--line);
    border-radius: 14px; padding: 12px; min-height: 520px;
  }
  .row { display: flex; gap: 8px; flex-wrap: wrap; min-height: 90px; align-items: flex-start; margin: 8px 0; }
  .mini {
    width: 86px; min-height: 110px; border-radius: 8px; padding: 5px;
    background: #1b1510; border: 1px solid #8a6a32; font-size: .62rem;
    position: relative; cursor: pointer;
  }
  .mini .n { font-family: Cinzel, serif; font-size: .62rem; color: #f6e8c3; margin-bottom: 4px; }
  .mini .e { font-size: 1.4rem; text-align: center; }
  .mini .s { text-align: center; font-weight: 800; margin-top: 4px; color: #ffe6a3; }
  .mini.tapped { opacity: .55; transform: rotate(8deg); }
  .mini.selected { outline: 2px solid var(--accent); }
  .hpbar {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--bg0); border-radius: 10px; padding: 8px 10px; margin-bottom: 6px;
    border: 1px solid var(--line); font-size: .9rem;
  }
  .hp { color: #f87171; font-weight: 800; }
  .be { color: var(--be); font-weight: 800; }
  .log {
    background: #0a0e13; border: 1px solid var(--line); border-radius: 14px;
    padding: 10px; height: 520px; overflow: auto; font-size: .8rem;
    font-family: 'IBM Plex Mono', monospace;
  }
  .log div { margin-bottom: 6px; color: #b8c4d6; }
  .log .sys { color: var(--accent); }
  .hand-scroll { overflow-x: auto; white-space: nowrap; padding-bottom: 6px; }
  .hand-scroll .mini { display: inline-block; vertical-align: top; white-space: normal; margin-right: 6px; }

  footer {
    margin-top: 36px; color: var(--muted); font-size: .8rem; text-align: center;
  }
  .toast {
    position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
    background: #1f2937; border: 1px solid var(--accent); color: var(--text);
    padding: 10px 14px; border-radius: 10px; z-index: 50; display: none;
  }
