:root {
  color-scheme: light;
  --bg: #f7f1e6;
  --surface: rgba(255, 252, 245, 0.9);
  --surface-strong: #fffefa;
  --line: rgba(53, 38, 20, 0.12);
  --ink: #21150d;
  --muted: #6a5648;
  --accent: #ef6a43;
  --accent-deep: #b43f1e;
  --accent-soft: rgba(239, 106, 67, 0.14);
  --shadow: 0 18px 50px rgba(62, 41, 22, 0.12);
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
  --max-width: 1200px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(255, 189, 133, 0.38), transparent 28rem),
    radial-gradient(circle at top right, rgba(79, 140, 112, 0.2), transparent 24rem),
    linear-gradient(180deg, #f7efe3 0%, #f3eadc 46%, #efe4d5 100%);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

img {
  display: block;
  max-width: 100%;
}

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

.app-shell {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px 16px 40px;
}

.layout {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1.6fr) minmax(300px, 0.95fr);
  align-items: start;
}

.panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.panel::after {
  content: "";
  position: absolute;
  inset: auto -24px -24px auto;
  width: 120px;
  height: 120px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(239, 106, 67, 0.18), transparent 68%);
  pointer-events: none;
}

.topbar,
.hero {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  padding: 18px 20px;
  background:
    linear-gradient(135deg, rgba(255, 250, 244, 0.95), rgba(255, 243, 227, 0.88)),
    linear-gradient(135deg, rgba(239, 106, 67, 0.06), rgba(79, 140, 112, 0.08));
}

.topbar h1,
.hero__copy h1,
.section-heading h2,
.empty-state h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  line-height: 1.02;
}

.topbar h1 {
  font-size: clamp(1.35rem, 2vw, 1.7rem);
}

.topbar__row {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: start;
}

.topbar__actions {
  margin-left: auto;
}

.hero__lede,
.section-copy,
.game-card__meta,
.game-card__notes,
.field span,
.hint,
.cover-search__label,
.game-card__last-played,
.stat-card__label,
#libraryMeta {
  color: var(--muted);
}

.hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.topbar__actions,
.topbar__stats,
.hero__stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar__stats {
  align-items: center;
}

.stat-card {
  display: inline-flex;
  gap: 8px;
  align-items: baseline;
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.48);
}

.stat-card__label {
  display: block;
  font-size: 0.9rem;
}

.stat-card__value {
  display: block;
  margin-top: 0;
  font-size: 1.15rem;
  line-height: 1;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-deep);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.8rem;
  font-weight: 700;
}

.section-heading {
  display: flex;
  gap: 20px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.section-heading__actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  margin-left: auto;
  flex-wrap: wrap;
}

.section-heading__actions #libraryMeta {
  margin: 0;
}

.section-heading h2 {
  font-size: 1.25rem;
}

.panel--wide,
.panel--full,
.stack > .panel {
  padding: 18px;
}

.panel--full {
  grid-column: 1 / -1;
}

.panel--library {
  min-width: 0;
}

.stack {
  display: grid;
  gap: 16px;
}

.stack--tight {
  gap: 10px;
}

.catalog-grid,
.library-grid {
  display: grid;
  gap: 12px;
}

.catalog-grid {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.catalog-grid--search {
  margin: 10px 0 12px;
  grid-template-columns: 1fr;
}

.catalog-grid--search .game-card {
  grid-template-columns: 78px minmax(0, 1fr);
  padding: 10px;
}

.catalog-grid--search .game-card__image {
  height: 100px;
}

.library-grid {
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
}

.game-card {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 14px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-strong);
}

.game-card--catalog {
  align-items: stretch;
}

.game-card--picked {
  border-color: rgba(239, 106, 67, 0.42);
  box-shadow: 0 10px 24px rgba(239, 106, 67, 0.12);
}

.game-card__image,
.manual-preview img {
  width: 100%;
  height: 148px;
  object-fit: cover;
  border-radius: 16px;
  border: 1px solid rgba(44, 27, 16, 0.08);
  background: linear-gradient(145deg, #fde4c7, #f5f0e8);
}

.manual-preview img {
  height: 140px;
}

.game-card__body {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.game-card__topline {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: start;
}

.game-card__title {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.2;
}

.game-card__meta,
.game-card__tags,
.game-card__notes {
  margin: 0;
  line-height: 1.45;
}

.game-card__tags {
  margin-top: -4px;
  font-size: 0.92rem;
  color: var(--accent-deep);
}

.game-card__footer {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
}

.game-card__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.game-card__actions--icons {
  margin-left: auto;
  flex-wrap: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.button {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  background: linear-gradient(135deg, var(--accent), #f08b5d);
  color: white;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease, filter 160ms ease;
}

.button:hover,
.button:focus-visible {
  transform: translateY(-1px);
  filter: saturate(1.08);
}

.button--ghost {
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
  border: 1px solid rgba(55, 36, 19, 0.08);
}

.button--small {
  padding: 8px 12px;
  font-size: 0.88rem;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid rgba(55, 36, 19, 0.1);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink);
  cursor: pointer;
  transition: transform 160ms ease, background-color 160ms ease, color 160ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  transform: translateY(-1px);
  background: white;
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.topbar__icon-button {
  margin-left: auto;
}

.icon-button--danger {
  color: var(--accent-deep);
}

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

.history-item {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid rgba(67, 44, 29, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
}

.history-item__date {
  font-weight: 700;
}

.history-item__winner {
  color: var(--muted);
}

.history-empty {
  padding: 14px;
  border-radius: 16px;
  border: 1px dashed rgba(67, 44, 29, 0.16);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.4);
}

.field,
.cover-search {
  display: grid;
  gap: 8px;
}

.field-row {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field-row--triple {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid rgba(67, 44, 29, 0.16);
  border-radius: 14px;
  padding: 10px 12px;
  background: white;
  color: var(--ink);
}

.field textarea {
  resize: vertical;
}

.field--file span {
  color: var(--ink);
  font-size: 0.9rem;
}

.toolbar {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1.4fr) repeat(2, minmax(0, 0.7fr)) minmax(120px, 0.8fr);
  margin-bottom: 14px;
}

.manual-preview {
  padding: 12px;
  border-radius: 18px;
  background: rgba(248, 240, 230, 0.74);
  border: 1px dashed rgba(67, 44, 29, 0.18);
}

.cover-search__links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.link-chip {
  display: inline-flex;
  align-items: center;
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid rgba(67, 44, 29, 0.14);
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 700;
}

.empty-state {
  padding: 20px;
  border-radius: var(--radius-md);
  border: 1px dashed rgba(67, 44, 29, 0.16);
  background: rgba(255, 255, 255, 0.38);
  text-align: center;
}

.empty-state p {
  margin-bottom: 0;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: 320px;
  padding: 14px 16px;
  border-radius: 18px;
  background: #1f463c;
  color: white;
  box-shadow: 0 16px 40px rgba(11, 34, 28, 0.22);
}

.dialog {
  width: min(100% - 24px, 520px);
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: transparent;
}

.dialog::backdrop {
  background: rgba(28, 18, 10, 0.35);
  backdrop-filter: blur(4px);
}

.dialog__panel {
  display: grid;
  gap: 14px;
  padding: 18px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.dialog__header {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: start;
}

.dialog__title {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.4rem;
}

.dialog__copy {
  margin: 0;
  color: var(--muted);
}

.dialog__actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.is-hidden {
  display: none !important;
}

.search-empty {
  margin: 10px 0 12px;
  padding: 12px;
  border-radius: 16px;
  border: 1px dashed rgba(67, 44, 29, 0.16);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.4);
}

.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;
}

@media (max-width: 920px) {
  .layout {
    grid-template-columns: 1fr;
  }

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

  .panel--full {
    grid-column: auto;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding-inline: 12px;
  }

  .hero,
  .panel--wide,
  .panel--full,
  .stack > .panel {
    padding: 18px;
  }

  .game-card,
  .field-row,
  .toolbar {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: start;
  }

  .section-heading {
    gap: 10px;
  }

  .section-heading__actions {
    margin-left: auto;
  }

  .dialog {
    width: calc(100% - 20px);
  }

  .game-card {
    grid-template-columns: 1fr;
  }

  .game-card__image {
    height: 220px;
  }
}
