/* ── Reset & base ─────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

:root {
  --bg:          #1b1209;
  --bg2:         #261a0e;
  --bg3:         #31210f;
  --card-bg:     #2a1c10;
  --card-hover:  #342213;
  --border:      #4a3020;
  --accent:      #f5a623;
  --accent2:     #e07b28;
  --teal:        #3dbcb0;
  --teal-dark:   #2a9890;
  --text:        #f0e6d6;
  --text-muted:  #9e8060;
  --danger:      #e05555;
  --radius:      10px;
  --shadow:      0 4px 20px rgba(0,0,0,.5);
}

html { font-size: 16px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────────────── */

.site-header {
  background: var(--bg2);
  border-bottom: 2px solid var(--border);
  padding: 1.5rem 1rem;
  text-align: center;
}

.header-inner { max-width: 860px; margin: 0 auto; }

.header-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: .55rem;
}

.logo {
  font-size: clamp(2rem, 6vw, 3.2rem);
  font-weight: 800;
  letter-spacing: .04em;
  color: var(--accent);
  text-shadow: 2px 2px 0 rgba(0,0,0,.6);
}

.logo-link {
  color: inherit;
  text-decoration: none;
}

.logo-link:hover {
  color: #ffc657;
}

.tagline {
  color: var(--text-muted);
  font-size: .95rem;
  margin-top: .25rem;
}

.header-link {
  color: var(--teal);
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  padding: .35rem .75rem;
  font-size: .85rem;
  font-weight: 700;
  transition: border-color .15s, color .15s, background .15s;
}

.header-link:hover {
  color: #1b1209;
  background: var(--teal);
  border-color: var(--teal);
}

.header-link-button {
  background: transparent;
  cursor: pointer;
  font-family: inherit;
}

.page-actions {
  width: fit-content;
  margin: 0 auto 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
}

.gif-day-panel {
  max-width: 860px;
  margin: 0 auto 1rem;
  padding: 1rem;
  background: linear-gradient(180deg, rgba(245,166,35,.08), rgba(61,188,176,.06));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.gif-day-title {
  font-size: .82rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
}

.gif-day-image {
  margin-top: .7rem;
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg3);
}

.gif-day-text {
  margin-top: .7rem;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.45;
}

.gif-day-meta {
  margin-top: .25rem;
  color: var(--text-muted);
  font-size: .88rem;
}

/* ── Search ──────────────────────────────────────────────────────────── */

main { max-width: 860px; margin: 0 auto; padding: 2rem 1rem 4rem; }

.search-wrap { position: relative; }

.search-input {
  width: 100%;
  padding: .9rem 1.2rem;
  font-size: 1.15rem;
  background: var(--bg3);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
  transition: border-color .2s;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }

.search-hint {
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: .5rem;
  min-height: 1.2em;
  text-align: right;
}

/* ── Results grid ────────────────────────────────────────────────────── */

.results-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.5rem;
}

/* ── Card ────────────────────────────────────────────────────────────── */

.result-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  transition: border-color .2s, background .2s;
}
.result-card:hover { background: var(--card-hover); border-color: var(--accent2); }

/* Main body row: left content + right thumbnail */
.card-body {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  cursor: pointer;
}

.card-body-main {
  flex: 1;
  min-width: 0; /* prevent text overflow escaping flex container */
}

.ep-thumbnail {
  width: 120px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg3);
}
.ep-thumbnail[src=""] { display: none; }

.card-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: .5rem;
}

.ep-badge {
  background: var(--accent);
  color: #1b1209;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .05em;
  padding: .15em .55em;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.ep-title {
  color: var(--text-muted);
  font-size: .88rem;
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.matched-text {
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: .75rem;
  line-height: 1.4;
}

.matched-text mark {
  background: transparent;
  color: var(--accent);
  font-weight: 700;
}

/* ── Expand button ───────────────────────────────────────────────────── */

.btn-expand {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--teal);
  cursor: pointer;
  font-size: .85rem;
  padding: .3em .8em;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-expand:hover { background: var(--teal); color: #1b1209; border-color: var(--teal); }
.btn-expand[aria-expanded="true"] { background: var(--bg3); color: var(--text-muted); }

/* ── GIF panel ───────────────────────────────────────────────────────── */

.gif-panel {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

/* Line selector */
.line-selector {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  margin-bottom: 1rem;
}

.line-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: .6rem;
  padding: .4rem .6rem;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
  cursor: pointer;
}
.line-row:hover { background: var(--bg3); }
.line-row.selected { border-color: var(--teal-dark); background: rgba(61,188,176,.1); }
.line-row.anchor   { border-color: var(--accent2);   background: rgba(245,166,35,.08); }

.line-row input[type="checkbox"] {
  accent-color: var(--teal);
  width: 1rem;
  height: 1rem;
  cursor: pointer;
  flex-shrink: 0;
}
.line-row .line-text { font-size: .92rem; }
.line-row .line-time { font-size: .72rem; color: var(--text-muted); white-space: nowrap; }

/* Duration bar */
.duration-bar-wrap {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: .9rem;
}

.duration-bar {
  flex: 1;
  height: 6px;
  background: var(--bg3);
  border-radius: 99px;
  overflow: hidden;
}

.duration-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--teal);
  transition: width .25s, background .25s;
}
.duration-fill.warn { background: var(--accent); }
.duration-fill.over { background: var(--danger); }

.duration-label { font-size: .8rem; color: var(--text-muted); white-space: nowrap; }

/* Generate button */
.gif-toolbar {
  display: flex;
  align-items: stretch;
  gap: .6rem;
}

.btn-generate {
  display: block;
  flex: 1;
  padding: .6rem;
  background: var(--teal);
  border: none;
  border-radius: 8px;
  color: #1b1209;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn-generate:hover:not(:disabled) { background: var(--teal-dark); }
.btn-generate:disabled { opacity: .5; cursor: wait; }

.subtitle-position-controls {
  display: flex;
  gap: .35rem;
}

.btn-position {
  min-width: 2.4rem;
  padding: .55rem .7rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}

.btn-position:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.btn-position.is-active {
  background: rgba(61,188,176,.12);
  border-color: var(--teal);
  color: var(--teal);
}

.btn-pad {
  padding: .55rem .8rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: .88rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}

.btn-pad:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-pad.is-active {
  background: rgba(245,166,35,.1);
  border-color: var(--accent);
  color: var(--accent);
}

/* GIF output */
.gif-output {
  margin-top: 1rem;
  text-align: center;
}

.gif-preview {
  max-width: 100%;
  border-radius: 8px;
  border: 2px solid var(--border);
  display: block;
  margin: 0 auto;
}

.gif-actions {
  display: flex;
  justify-content: center;
  gap: .75rem;
  margin-top: .75rem;
  flex-wrap: wrap;
}

.btn-download {
  background: var(--accent);
  color: #1b1209;
  padding: .4em 1.1em;
  border-radius: 6px;
  font-weight: 700;
  font-size: .9rem;
  text-decoration: none;
  transition: background .15s;
}
.btn-download:hover { background: var(--accent2); }

.btn-copy-link {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .4em 1.1em;
  border-radius: 6px;
  font-size: .9rem;
  cursor: pointer;
  transition: border-color .15s;
}
.btn-copy-link:hover { border-color: var(--teal); color: var(--teal); }

.gif-error {
  color: var(--danger);
  font-size: .88rem;
  margin-top: .75rem;
  padding: .5rem .75rem;
  background: rgba(224,85,85,.1);
  border-radius: 6px;
  border: 1px solid rgba(224,85,85,.3);
}

/* ── Feedback modal ─────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}

.modal-card {
  width: min(100%, 560px);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}

.modal-title {
  font-size: 1.1rem;
  color: var(--accent);
}

.modal-close {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  width: 2rem;
  height: 2rem;
  font-size: 1.2rem;
  cursor: pointer;
}

.modal-copy {
  margin-top: .8rem;
  color: var(--text);
}

.modal-note {
  margin-top: .35rem;
  color: var(--text-muted);
  font-size: .88rem;
}

.feedback-form {
  margin-top: .9rem;
}

.feedback-textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: .85rem;
  font: inherit;
}

.feedback-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.feedback-actions {
  margin-top: .75rem;
  display: flex;
  justify-content: flex-end;
}

.feedback-status {
  min-height: 1.4rem;
  margin-top: .75rem;
  color: var(--text-muted);
  font-size: .9rem;
}

/* Loading spinner inside generate button */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 2px solid rgba(0,0,0,.3);
  border-top-color: #1b1209;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
  margin-right: .4em;
}

/* Load more */
.load-more-wrap { text-align: center; margin-top: 1.5rem; }
.btn-load-more {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .55em 2em;
  border-radius: 8px;
  font-size: .95rem;
  cursor: pointer;
  transition: border-color .15s;
}
.btn-load-more:hover { border-color: var(--teal); color: var(--teal); }

/* ── Empty / loading state ───────────────────────────────────────────── */

.state-msg {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
  font-size: 1.05rem;
}

/* ── Stats page ──────────────────────────────────────────────────────── */

.stats-main {
  max-width: 980px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1.25rem;
}

.stats-card,
.stats-list-card,
.stats-highlight {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.stats-label {
  color: var(--text-muted);
  font-size: .8rem;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.stats-value {
  margin-top: .35rem;
  color: var(--accent);
  font-size: clamp(1.4rem, 3.2vw, 2.1rem);
  font-weight: 800;
}

.stats-highlight {
  margin-top: 1rem;
}

.highlight-title {
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
}

.highlight-line {
  margin-top: .5rem;
  font-size: 1.1rem;
  color: var(--text);
}

.highlight-meta {
  margin-top: .4rem;
  color: var(--text-muted);
  font-size: .9rem;
}

.stats-lists {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.stats-list-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--teal);
  margin-bottom: .6rem;
}

.stats-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .45rem;
}

.stats-list li {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  border-bottom: 1px solid rgba(255,255,255,.05);
  padding-bottom: .35rem;
}

.stats-list .item-label {
  min-width: 0;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-list .item-count {
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
}

@media (max-width: 820px) {
  .stats-grid,
  .stats-lists {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .logo {
    font-size: clamp(1.35rem, 6.8vw, 1.95rem);
    letter-spacing: .01em;
    line-height: 1.1;
  }

  .page-actions {
    width: 100%;
    justify-content: center;
  }

  .gif-day-panel {
    margin: 0 1rem 1rem;
  }
}
