/* curio — Textual-dark-theme port to real CSS.
   Palette mirrors Textual's default dark design tokens so the web app
   reads like the TUI it replaces. */
:root {
  --background: #1e1e1e;
  --surface: #232323;
  --panel: #2c2c2c;
  --panel-light: #363636;
  --primary: #0178d4;
  --primary-dark: #004578;
  --accent: #ffa62b;
  --text: #e0e0e0;
  --text-muted: #8a8a8a;
  --border: #3a3a3a;

  /* rating tiers, matching discovery.rating_color() */
  --rate-high: #4ebf71;   /* >= 8.0  bright_green  */
  --rate-mid: #e5c07b;    /* >= 6.5  bright_yellow */
  --rate-low: #d98a3d;    /* >= 5.0  dark_orange   */
  --rate-bad: #e06c75;    /* <  5.0  bright_red    */
  --rate-na: #6a6a6a;     /* None    dim           */

  --mono: "SF Mono", "JetBrains Mono", "Fira Code", "Cascadia Code",
          ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--background);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---- Header (Textual Header) ---- */
header#topbar {
  height: 34px;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.05em;
}
header#topbar .brand { font-weight: 700; }
header#topbar .brand .dim { color: var(--text-muted); font-weight: 400; }
header#topbar .count {
  position: absolute;
  right: 40px;
  color: var(--text-muted);
  font-size: 12px;
}
header#topbar .logout {
  position: absolute;
  right: 12px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 16px;
}
header#topbar .logout:hover { color: var(--rate-bad); }

/* ---- Filter bar (search + status) ---- */
#filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  min-height: 40px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--background);
}
#search {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  padding: 6px 10px;
  outline: none;
}
#search:focus { border-color: var(--primary); }
#filter-status {
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 55%;
}

/* ---- Movie table ---- */
#table-wrap { flex: 1; overflow-y: auto; overflow-x: auto; }
table#movies {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
#movies thead th {
  position: sticky;
  top: 0;
  background: var(--panel);
  color: var(--text);
  text-align: left;
  font-weight: 700;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
#movies tbody td {
  padding: 4px 12px;
  border-bottom: 1px solid #262626;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#movies td.title { max-width: 340px; }
#movies td.genres { max-width: 260px; color: var(--text-muted); }
#movies td.director { max-width: 200px; color: var(--text-muted); }
#movies tbody tr { cursor: pointer; }
#movies tbody tr:hover { background: var(--panel); }
#movies tbody tr.cursor {
  background: var(--primary-dark);
  color: #fff;
}
#movies tbody tr.cursor td { color: #fff; }
.gem-dot { color: var(--accent); }

/* rating cells / bars */
.r-high { color: var(--rate-high); }
.r-mid  { color: var(--rate-mid); }
.r-low  { color: var(--rate-low); }
.r-bad  { color: var(--rate-bad); }
.r-na   { color: var(--rate-na); }
.bar .fill { letter-spacing: -1px; }
.bar .empty { color: #444; letter-spacing: -1px; }

/* ---- Footer (Textual Footer key bar) ---- */
footer#keys {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  height: 30px;
  min-height: 30px;
  padding: 0 6px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  overflow: hidden;
}
.keybtn {
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 4px 8px;
  cursor: pointer;
}
.keybtn:hover { background: var(--panel-light); }
.keybtn .k {
  color: var(--background);
  background: var(--accent);
  padding: 0 5px;
  margin-right: 5px;
  border-radius: 2px;
  font-weight: 700;
}
.keybtn.active { background: var(--primary-dark); }

/* ---- Modal scaffolding ---- */
#scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
#scrim.show { display: flex; }
.modal {
  background: var(--surface);
  width: 95%;
  max-width: 1100px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border: 3px solid var(--primary);
}
.modal.accent { border-color: var(--accent); }
.modal-body { padding: 14px 20px; overflow-y: auto; }
.modal-keys {
  background: var(--panel);
  color: var(--text);
  text-align: center;
  padding: 5px;
  border-top: 1px solid var(--border);
}
.modal-keys .k { color: var(--accent); font-weight: 700; }

/* ---- Detail screen ---- */
.detail-title { font-size: 20px; font-weight: 700; text-align: center; }
.detail-ratings { text-align: center; margin: 8px 0; }
.detail-ratings .seg { margin: 0 10px; }
.detail-meta { text-align: center; color: var(--text-muted); margin-bottom: 12px; }
.detail-cols { display: grid; grid-template-columns: 240px 1fr; gap: 20px; }
.detail-poster img { width: 100%; border: 1px solid var(--border); display: block; }
.detail-poster .noposter {
  aspect-ratio: 2/3; display: flex; align-items: center; justify-content: center;
  background: var(--panel); color: var(--text-muted);
}
.ascii-poster {
  font-size: 0;
  line-height: 0;
  background: #000;
  border: 1px solid var(--border);
  width: 240px;
  max-width: 100%;
}
.ascii-poster > div { white-space: nowrap; height: 16px; }
.ascii-poster i { display: inline-block; width: 8px; height: 16px; vertical-align: top; }
.ascii-loading {
  width: 240px; max-width: 100%; aspect-ratio: 2 / 3;
  display: flex; align-items: center; justify-content: center;
  background: #000; border: 1px solid var(--border);
  color: var(--text-muted); font-size: 12px;
}
.poster-toggle {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
  padding: 4px;
  cursor: pointer;
}
.poster-toggle:hover { border-color: var(--accent); color: var(--accent); }
.sec { color: var(--accent); font-weight: 700; margin: 12px 0 4px; }
.row { padding-left: 8px; margin: 2px 0; }
.row .lbl { color: var(--text-muted); }
a.person {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px dotted var(--text-muted);
}
a.person:hover { color: var(--accent); border-bottom-color: var(--accent); }
.plot { color: var(--text-muted); padding: 0 4px; line-height: 1.5; }
.kw { color: var(--text-muted); padding-left: 8px; }
.links a { color: var(--accent); text-decoration: none; display: block; padding-left: 8px; }
.links a:hover { text-decoration: underline; }
.btn {
  background: var(--primary); color: #fff; border: none; font-family: var(--mono);
  padding: 6px 14px; cursor: pointer; font-size: 13px;
}
.btn:hover { background: #0a8ae8; }
.btn.accent { background: var(--accent); color: #1e1e1e; }

/* ---- Similar / directors tables ---- */
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; color: var(--text); border-bottom: 1px solid var(--border);
  padding: 5px 10px; position: sticky; top: 0; background: var(--surface);
  cursor: pointer; user-select: none;
}
table.data td { padding: 4px 10px; border-bottom: 1px solid #262626; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: var(--panel); }
table.data td.why { color: var(--text-muted); }
.match { color: var(--accent); font-weight: 700; }

/* ---- Suggestion cards ---- */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.card { border: 1px solid var(--border); background: var(--background); display: flex; flex-direction: column; }
.card-header { text-align: center; font-weight: 700; padding: 5px; color: #fff; }
.card-num { color: rgba(255,255,255,0.6); margin-right: 6px; }
.card-body { display: grid; grid-template-columns: 92px 1fr; gap: 10px; padding: 10px; }
.card-body img { width: 92px; border: 1px solid var(--border); }
.card-title { font-weight: 700; }
.card-line { color: var(--text-muted); font-size: 13px; margin-top: 3px; }
.card-trailer a { color: #56b6c2; font-size: 12px; text-decoration: none; }
.card-reason { color: var(--accent); font-style: italic; padding: 0 10px 10px; font-size: 13px; }

/* ---- Mood grid ---- */
.mood-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.mood-card {
  border: 1px solid var(--primary); padding: 10px 12px; cursor: pointer; display: flex; gap: 10px;
}
.mood-card:hover { border-color: var(--accent); background: var(--panel); }
.mood-icon { font-size: 26px; }
.mood-name { font-weight: 700; }
.mood-desc { color: var(--text-muted); font-size: 13px; }
.mood-count { color: var(--accent); font-size: 12px; margin-top: 2px; }
.modal-title { font-weight: 700; text-align: center; font-size: 16px; margin-bottom: 12px; }

.loading { text-align: center; color: var(--text-muted); padding: 30px; }
