:root {
  --bg: var(--tg-theme-bg-color, #101511);
  --surface: var(--tg-theme-secondary-bg-color, #182019);
  --text: var(--tg-theme-text-color, #f3f5ee);
  --muted: var(--tg-theme-hint-color, #9da79e);
  --accent: var(--tg-theme-button-color, #b9e769);
  --accent-text: var(--tg-theme-button-text-color, #17200d);
  --link: var(--tg-theme-link-color, #b9e769);
  --line: color-mix(in srgb, var(--text) 13%, transparent);
  --shadow: 0 24px 70px rgb(0 0 0 / 28%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 85% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 38%),
    var(--bg);
}

button, input { font: inherit; }
button { color: inherit; }

.shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 18px max(32px, env(safe-area-inset-bottom));
}

.hero { padding: 10px 2px 22px; }
.eyebrow { color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .18em; }
.hero h1 { margin: 8px 0 7px; font-family: Georgia, serif; font-size: clamp(2.25rem, 10vw, 4.2rem); font-weight: 500; letter-spacing: -.045em; line-height: .98; }
.hero p { max-width: 470px; margin: 0; color: var(--muted); font-size: .98rem; line-height: 1.5; }

.search {
  position: sticky;
  top: 10px;
  z-index: 4;
  display: flex;
  gap: 8px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: 0 12px 35px rgb(0 0 0 / 13%);
  backdrop-filter: blur(18px);
}

.search input { flex: 1; min-width: 0; padding: 12px; border: 0; outline: 0; color: var(--text); background: transparent; }
.search input::placeholder { color: var(--muted); }
.search button, .share-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 12px;
  color: var(--accent-text);
  background: var(--accent);
  font-weight: 750;
  cursor: pointer;
}
.search button { padding: 0 16px; }
.search svg, .share-button svg { width: 19px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }

.empty-state { padding: 72px 18px 30px; text-align: center; }
.empty-state h2 { margin: 24px 0 7px; font-family: Georgia, serif; font-size: 1.7rem; font-weight: 500; }
.empty-state p { max-width: 410px; margin: 0 auto; color: var(--muted); line-height: 1.5; }
.empty-state code { padding: 2px 5px; border-radius: 5px; color: var(--text); background: var(--surface); }
.card-stack { position: relative; width: 80px; height: 104px; margin: 0 auto; }
.card-stack i { position: absolute; inset: 0; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-family: Georgia, serif; font-size: 2rem; font-style: normal; box-shadow: var(--shadow); }
.card-stack i:nth-child(1) { transform: rotate(-10deg) translate(-8px, 4px); opacity: .45; }
.card-stack i:nth-child(2) { transform: rotate(7deg) translate(8px, 1px); opacity: .7; }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 24px; }
.suggestions button, .tabs button, .face-toggle { border: 1px solid var(--line); border-radius: 999px; background: transparent; cursor: pointer; }
.suggestions button { padding: 8px 12px; color: var(--muted); font-size: .82rem; }

.status { margin: 34px 0; padding: 20px; border: 1px solid var(--line); border-radius: 15px; color: var(--muted); text-align: center; background: var(--surface); }
.status.loading::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 9px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; vertical-align: -2px; animation: spin .7s linear infinite; }

.result { display: grid; gap: 22px; margin-top: 26px; animation: reveal .35s ease-out; }
.art-panel { position: relative; align-self: start; }
.art-panel img { display: block; width: min(100%, 390px); margin: auto; border-radius: 4.7% / 3.4%; box-shadow: var(--shadow); background: var(--surface); }
.face-toggle { position: absolute; right: 12px; bottom: 12px; padding: 8px 12px; color: #fff; border-color: rgb(255 255 255 / 25%); background: rgb(0 0 0 / 67%); backdrop-filter: blur(10px); }
.card-content { padding: 3px 2px; }
.card-heading { display: flex; justify-content: space-between; gap: 16px; align-items: end; }
.set-line { margin: 0 0 4px; color: var(--accent); font-size: .7rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.card-heading h2 { margin: 0; font-family: Georgia, serif; font-size: 2rem; font-weight: 500; line-height: 1.05; }
.mana { flex-shrink: 0; margin: 0; color: var(--muted); }
.type-line { margin: 10px 0 18px; color: var(--muted); font-style: italic; }
.oracle-text { padding: 17px 0; border-block: 1px solid var(--line); line-height: 1.55; white-space: pre-line; }
.stats { width: fit-content; margin: -13px 0 0 auto; padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-weight: 750; }
.tabs { display: flex; gap: 7px; margin: 22px 0 14px; }
.tabs button { padding: 8px 13px; color: var(--muted); }
.tabs button.active { color: var(--accent-text); border-color: var(--accent); background: var(--accent); }
.tab-panel { min-height: 82px; color: var(--muted); font-size: .9rem; line-height: 1.5; }
.detail-grid, .legality-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.detail, .legality-group, .ruling { padding: 11px 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.detail span, .legality-group span { display: block; margin-bottom: 3px; color: var(--muted); font-size: .68rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.detail strong { color: var(--text); font-weight: 650; }
.legality-group strong { color: var(--text); text-transform: capitalize; }
.legality-group p { margin: 5px 0 0; }
.rulings { display: grid; gap: 9px; }
.ruling time { color: var(--accent); font-size: .72rem; font-weight: 750; }
.ruling p { margin: 5px 0 0; color: var(--text); white-space: pre-line; }
.share-button { width: 100%; margin-top: 20px; padding: 13px 18px; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes reveal { from { opacity: 0; transform: translateY(8px); } }

@media (min-width: 680px) {
  .shell { padding-inline: 28px; }
  .result { grid-template-columns: minmax(270px, 42%) 1fr; align-items: start; gap: 34px; }
  .art-panel { position: sticky; top: 92px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation-duration: .01ms !important; }
}
