:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --panel: #ffffff;
  --ink: #171717;
  --muted: #656565;
  --line: #dedbd3;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --danger: #9f1239;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.page-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

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

.segmented-control {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.segment {
  min-height: 36px;
  padding: 0 13px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.segment.active {
  background: var(--accent);
  color: #fff;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

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

.refresh-button {
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.refresh-button:hover,
.refresh-button:focus-visible {
  background: var(--accent-strong);
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.toolbar > div {
  min-width: 0;
  padding: 14px 16px;
  background: var(--panel);
}

.label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.results-wrap {
  min-height: 220px;
}

.title-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 18px;
}

.title-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.poster-wrap {
  position: relative;
  background: #e8e4da;
}

.poster {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  background: #e8e4da;
  object-fit: cover;
}

.poster-fallback {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  text-transform: uppercase;
}

.rank {
  position: absolute;
  top: 8px;
  left: 8px;
  min-width: 34px;
  padding: 4px 7px;
  border-radius: 999px;
  background: rgba(23, 23, 23, 0.78);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
}

.rating-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 5px 8px;
  border-radius: 999px;
  background: #f5c518;
  color: #171717;
  font-size: 0.76rem;
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(23, 23, 23, 0.22);
}

.title-card-body {
  padding: 12px;
}

.title-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.title-name {
  display: -webkit-box;
  min-height: 2.5rem;
  margin: 0;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 1rem;
  line-height: 1.25;
}

.popularity {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.type-pill {
  display: inline-block;
  min-width: 58px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f9fafb;
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
}

.metric {
  font-variant-numeric: tabular-nums;
}

.state {
  grid-column: 1 / -1;
  padding: 42px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
}

.state.error {
  color: var(--danger);
}

.debug-panel {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 20;
  width: min(460px, calc(100vw - 28px));
  max-height: min(420px, calc(100vh - 28px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #171717;
  color: #f8fafc;
  box-shadow: 0 14px 34px rgba(23, 23, 23, 0.26);
}

.debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.debug-refresh {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.debug-panel pre {
  max-height: 340px;
  margin: 0;
  overflow: auto;
  padding: 12px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 720px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding: 20px 0;
  }

  .page-header {
    align-items: stretch;
    flex-direction: column;
  }

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

  .segmented-control {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .refresh-button {
    width: 100%;
  }

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

  .title-grid {
    grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
    gap: 12px;
  }

  .title-card-body {
    padding: 10px;
  }

  .debug-panel {
    right: 10px;
    bottom: 10px;
    max-height: 300px;
  }
}
