:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --panel: #ffffff;
  --ink: #20241f;
  --muted: #666f62;
  --line: #dce2d7;
  --accent: #22735d;
  --accent-strong: #174f42;
  --accent-soft: #e5f2ed;
  --gold: #b78324;
  --danger: #a53a33;
  --shadow: 0 14px 35px rgba(39, 48, 41, 0.1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(247, 248, 245, 0.9)),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(16px, 4vw, 48px) 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 4vw, 3.2rem);
  line-height: 1;
}

h2 {
  margin-bottom: 4px;
  font-size: 1.08rem;
}

main {
  padding: 20px clamp(16px, 4vw, 48px) 48px;
}

.tabs,
.segmented,
.button-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tabs {
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef1ea;
}

.header-actions,
.account-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.account-bar {
  position: relative;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.account-trigger {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f1f4ef;
  color: var(--ink);
  min-height: 42px;
  padding: 10px 14px;
  font-weight: 900;
}

.account-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  min-width: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 8px;
  box-shadow: var(--shadow);
}

.account-menu .secondary {
  width: 100%;
}

.auth-screen {
  padding: 34px clamp(16px, 4vw, 48px) 48px;
}

.auth-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 420px));
  gap: 18px;
  align-items: start;
}

.tab {
  min-width: 86px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 10px 14px;
  font-weight: 800;
}

.tab.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 3px 10px rgba(35, 39, 34, 0.08);
}

.source-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 0.92rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--gold);
}

.source-bar.ok .status-dot {
  background: var(--accent);
}

.source-bar.error .status-dot {
  background: var(--danger);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.split,
.stats-grid {
  display: grid;
  grid-template-columns: minmax(340px, 0.8fr) minmax(0, 1.2fr);
  gap: 18px;
  align-items: start;
}

.deck-layout {
  grid-template-columns: minmax(340px, 0.72fr) minmax(0, 1.28fr);
}

.panel,
.deck-card,
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.panel-heading {
  margin-bottom: 16px;
}

.panel-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.form-panel {
  display: grid;
  gap: 14px;
}

label,
fieldset {
  display: grid;
  gap: 7px;
  margin: 0;
  min-width: 0;
  border: 0;
  padding: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

legend {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfa;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34, 115, 93, 0.13);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.two-col.compact {
  align-items: end;
}

.segmented {
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfa;
}

.segmented label {
  flex: 1;
  display: block;
  color: var(--ink);
  font-size: 0.9rem;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: block;
  min-height: 43px;
  padding: 12px 10px;
  text-align: center;
  border-right: 1px solid var(--line);
}

.segmented label:last-child span {
  border-right: 0;
}

.segmented input:checked + span {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.primary,
.secondary,
.ghost,
.danger {
  min-height: 42px;
  border-radius: 7px;
  padding: 10px 14px;
  font-weight: 900;
}

.primary {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
}

.secondary {
  border: 1px solid var(--line);
  background: #f1f4ef;
  color: var(--ink);
}

.ghost {
  border: 1px solid transparent;
  background: transparent;
  color: var(--accent-strong);
}

.danger {
  border: 1px solid rgba(165, 58, 51, 0.2);
  background: #fff4f2;
  color: var(--danger);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 670px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.result {
  display: inline-flex;
  min-width: 54px;
  justify-content: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.result.win {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.result.loss {
  background: #fff0ed;
  color: var(--danger);
}

.result.draw {
  background: #f5eedf;
  color: #795718;
}

.deck-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

.deck-card {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.deck-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.deck-card h3 {
  margin: 0 0 3px;
  font-size: 1rem;
}

.deck-card p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.decklist-preview {
  max-height: 180px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8faf6;
  padding: 11px;
  color: #374036;
  font-size: 0.84rem;
  white-space: pre-wrap;
}

.deck-sections {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.deck-sections span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8faf6;
  color: var(--muted);
  padding: 5px 9px;
  font-size: 0.78rem;
  font-weight: 800;
}

.deck-sections strong {
  color: var(--accent-strong);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  padding: 18px;
}

.metric span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 2rem;
}

.stat-list {
  display: grid;
  gap: 10px;
}

.stat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
}

.stat-row h3 {
  overflow-wrap: anywhere;
  margin: 0 0 5px;
  font-size: 0.95rem;
}

.stat-row p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.winrate {
  color: var(--accent-strong);
  font-size: 1.3rem;
  font-weight: 950;
  text-align: right;
}

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

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  max-width: min(380px, calc(100vw - 36px));
  border-radius: 8px;
  background: #20241f;
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.visible {
  transform: translateY(0);
  opacity: 1;
}

.suggestion-menu {
  position: fixed;
  z-index: 40;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 5px;
}

.suggestion-menu button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  padding: 9px 10px;
  text-align: left;
}

.suggestion-menu button:hover,
.suggestion-menu button.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

@media (max-width: 920px) {
  .app-header,
  .split,
  .stats-grid,
  .two-col {
    grid-template-columns: 1fr;
  }

  .app-header {
    display: grid;
    align-items: start;
  }

  .tabs {
    width: 100%;
  }

  .header-actions,
  .account-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .account-menu {
    position: static;
    min-width: 0;
  }

  .auth-grid {
    grid-template-columns: 1fr;
  }

  .tab {
    flex: 1;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  main {
    padding-inline: 12px;
  }

  .app-header {
    padding-inline: 12px;
  }

  .tabs {
    overflow-x: auto;
  }

  .panel {
    padding: 14px;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .button-row {
    align-items: stretch;
    flex-direction: column;
  }
}
