:root {
  color-scheme: dark;
  --bg: #14110f;
  --panel: #231d18;
  --line: #41362b;
  --text: #f1e8da;
  --muted: #b3a491;
  --gold: #d9a441;
  --monster: #b5392f;
  --nilfgaard: #c9a227;
  --northern-realms: #3f7fc4;
  --scoiatael: #4d9a4f;
  --skellige: #8a5cc2;
  --syndicate: #d9702b;
  --neutral: #9c8a6c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding-bottom: 6rem;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

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

button {
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  gap: 0.5rem;
  padding: 0.75rem 0.75rem 0.5rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

#find {
  display: flex;
  gap: 0.5rem;
}

#witcher3 {
  flex: none;
  padding: 0 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.875rem;
}

#witcher3[aria-pressed="true"] {
  border-color: var(--gold);
  color: var(--gold);
  font-weight: 600;
}

#search {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  /* 16px stops iOS zooming in on focus. */
  font-size: 16px;
}

#filters {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  scrollbar-width: none;
}

#filters button {
  flex: none;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.875rem;
}

#filters button[aria-pressed="true"] {
  border-color: var(--gold);
  background: var(--gold);
  color: var(--bg);
  font-weight: 600;
}

#message {
  margin: 0;
  color: var(--muted);
  text-align: center;
}

#message:not(:empty) {
  padding: 2rem 1rem;
}

#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(6.75rem, 1fr));
  gap: 0.5rem;
  padding: 0.75rem;
}

.tile {
  position: relative;
  aspect-ratio: 5 / 7;
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
  outline: 2px solid var(--faction);
  outline-offset: -2px;
  content-visibility: auto;
  contain-intrinsic-size: 7rem 10rem;
}

.tile.loading {
  outline-color: var(--gold);
  outline-style: dashed;
}

.tile.playing {
  outline-color: var(--gold);
  outline-width: 3px;
  animation: speak 0.9s ease-in-out infinite alternate;
}

@keyframes speak {
  to {
    transform: scale(1.03);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile.playing {
    animation: none;
  }
}

/* .tile clips anything drawn outside it. */
.tile button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: -4px;
}

.play {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.play img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.play span {
  position: absolute;
  inset: auto 0 0;
  padding: 1.75rem 0.4rem 0.4rem;
  background: linear-gradient(transparent, rgb(0 0 0 / 88%) 60%);
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
}

.star {
  position: absolute;
  top: 0;
  right: 0;
  width: 2.75rem;
  height: 2.75rem;
  color: #fff;
  font-size: 1.25rem;
  line-height: 1;
  background: radial-gradient(circle, rgb(0 0 0 / 60%) 0.8rem, transparent 0.85rem);
}

.star[aria-pressed="true"] {
  color: var(--gold);
}

footer {
  padding: 1rem;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

footer a {
  color: inherit;
}

#player {
  position: fixed;
  inset: auto 0 0;
  z-index: 3;
  background: var(--panel);
  border-top: 1px solid var(--gold);
}

#now {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
}

#quote {
  flex: 1;
  min-width: 0;
}

#speaker {
  display: block;
  color: var(--gold);
  font-size: 0.8125rem;
}

#text {
  display: block;
  font-family: Georgia, serif;
  font-style: italic;
  line-height: 1.3;
}

#text.error {
  color: #ef9a8f;
  font-family: inherit;
  font-style: normal;
}

#toggle-lines,
#stop {
  flex: none;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.875rem;
}

#lines {
  max-height: 45vh;
  margin: 0;
  padding: 0.25rem 0;
  overflow-y: auto;
  list-style: none;
  border-bottom: 1px solid var(--line);
}

#lines button {
  width: 100%;
  padding: 0.7rem 0.75rem;
  font-family: Georgia, serif;
  font-style: italic;
  text-align: left;
}

#lines button[aria-current="true"] {
  color: var(--gold);
}
