*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:      #0a0a0a;
  --surface: #161616;
  --border:  #2a2a2a;
  --accent:  #e8a020;
  --text:    #e8e8e8;
  --muted:   #888;
  --radius:  10px;
  --sidebar: 280px;
}

html, body { height: 100%; background: var(--bg); color: var(--text);
             font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }

/* ── Screens ── */
.screen { display: none; min-height: 100dvh; flex-direction: column; }
.screen.active { display: flex; }

/* ── Login ── */
#screen-login { align-items: center; justify-content: center; padding: 2rem; }
#screen-login h1 { font-size: 1.8rem; margin-bottom: 2rem; color: var(--accent); letter-spacing: .04em; }
.login-box { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 1rem; }
.login-box input {
  padding: .85rem 1rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 1rem;
}
.login-box button {
  padding: .85rem; background: var(--accent); border: none;
  border-radius: var(--radius); color: #000; font-size: 1rem;
  font-weight: 700; cursor: pointer;
}

/* ── Search screen ── */
#screen-search {
  flex-direction: row;   /* sidebar + main on desktop */
}

/* Left sidebar (vocab) — hidden on mobile, visible on desktop */
#vocab-sidebar {
  width: var(--sidebar); flex-shrink: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 1.25rem 1rem;
}
#vocab-sidebar h2 { font-size: 1rem; color: var(--muted); margin-bottom: .75rem; }
#vocab-sidebar .vd-actions { display: flex; gap: .5rem; margin-bottom: .75rem; }
#vocab-list { flex: 1; overflow-y: auto; }
.vocab-item {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: .6rem 0; border-bottom: 1px solid var(--border); gap: .5rem;
}
.vocab-item .vi-word  { font-weight: 700; font-size: .9rem; }
.vocab-item .vi-trans { color: var(--accent); font-size: .82rem; }
.vocab-item .vi-del   { background: none; border: none; color: var(--muted);
                        font-size: 1rem; cursor: pointer; flex-shrink: 0; }

/* Main content area */
#search-main {
  flex: 1; display: flex; flex-direction: column;
  padding: 1.25rem; overflow: hidden;
}

.search-form { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1rem; }

.search-row { display: flex; gap: .5rem; }
.search-row input[type="text"] {
  flex: 1; padding: .75rem 1rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 1rem;
}


.cat-row { display: flex; gap: .4rem; }
.cat-btn {
  padding: .4rem .85rem; border: 1px solid var(--border); border-radius: 20px;
  background: none; color: var(--muted); font-size: .82rem; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.cat-btn:hover { color: var(--text); border-color: var(--text); }
.cat-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(232,160,32,.08); }

#btn-clear-search {
  padding: .75rem .6rem; border: none; border-radius: var(--radius);
  background: none; color: var(--muted); font-size: 1rem;
  cursor: pointer; flex-shrink: 0; line-height: 1;
}
#btn-clear-search:hover { color: var(--text); }

.btn {
  padding: .75rem 1.1rem; border: none; border-radius: var(--radius);
  background: var(--accent); color: #000; font-weight: 700;
  cursor: pointer; white-space: nowrap; font-size: .95rem;
}
.btn-ghost {
  padding: .6rem 1rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: none; color: var(--text); font-size: .85rem; cursor: pointer;
}

#results { flex: 1; overflow-y: auto; }
.result-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: .6rem;
  cursor: pointer; transition: border-color .15s;
}
.result-item:hover, .result-item:active { border-color: var(--accent); }
.result-item .r-title { font-size: .95rem; margin-bottom: .3rem; line-height: 1.3; }
.result-item .r-meta  { font-size: .78rem; color: var(--muted); }

.status { padding: 1rem 0; color: var(--muted); font-size: .9rem; text-align: center; }

/* ── Player screen ── */
#screen-player { background: #000; position: relative; overflow: hidden; }

.player-layout {
  display: flex; flex-direction: column; height: 100dvh;
}

/* On desktop, video fills sensibly */
.player-video-wrap { position: relative; background: #000; flex-shrink: 0; }
video {
  width: 100%; display: block;
  max-height: 56.25vw;  /* 16:9 */
}
@media (min-width: 900px) {
  video { max-height: 70vh; }
}

/* Subtitle overlay */
#subtitle-overlay {
  position: absolute; bottom: 8%; left: 0; right: 0;
  text-align: center; padding: 0 3%; pointer-events: none;
}
#subtitle-overlay .sub-line {
  display: inline; background: rgba(0,0,0,.55);
  border-radius: 4px; padding: 2px 8px;
  font-size: clamp(.95rem, 3vw, 1.4rem); line-height: 1.6;
}
.word-token {
  display: inline; color: #fff; text-shadow: 1px 1px 3px #000;
  cursor: pointer; pointer-events: all; border-radius: 3px;
  padding: 0 1px; transition: background .1s;
}
.word-token:hover, .word-token:active { background: rgba(232,160,32,.45); }

/* Player controls */
#player-controls {
  padding: .6rem 1rem; background: var(--surface);
  display: flex; align-items: center; gap: .75rem; flex-shrink: 0;
}
#player-controls button {
  background: none; border: none; color: var(--text); font-size: 1.3rem; cursor: pointer;
}
#seek-bar {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 4px; background: var(--border); border-radius: 2px; outline: none; cursor: pointer;
}
#seek-bar::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px;
  border-radius: 50%; background: var(--accent);
}
#time-display { font-size: .8rem; color: var(--muted); white-space: nowrap; min-width: 80px; text-align: right; }

/* Player top bar */
#player-topbar {
  position: absolute; top: env(safe-area-inset-top, 0); left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: .5rem .75rem; z-index: 10; pointer-events: none;
}
#btn-back, #vocab-btn {
  pointer-events: all;
  border: none; cursor: pointer; border-radius: var(--radius);
  padding: .4rem .8rem; font-size: .9rem; font-weight: 700;
  background: rgba(0,0,0,.65); color: var(--text);
}
#vocab-btn { color: var(--accent); }

/* Translation popup — sheet on mobile, floating on desktop */
#popup {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface); border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  padding: 1.2rem 1.2rem calc(1.2rem + env(safe-area-inset-bottom, 0px));
  z-index: 200; transform: translateY(100%); transition: transform .25s ease;
  max-height: 50vh; overflow-y: auto;
}
@media (min-width: 700px) {
  #popup {
    left: auto; right: 1.5rem; bottom: 1.5rem;
    width: 320px; border-radius: var(--radius); border: 1px solid var(--border);
    transform: scale(.9); opacity: 0; pointer-events: none; transition: transform .2s, opacity .2s;
  }
  #popup.open { transform: scale(1); opacity: 1; pointer-events: all; }
}
#popup:not(.open) { pointer-events: none; }
#popup.open { transform: translateY(0); }
#popup .p-word        { font-size: 1.3rem; font-weight: 700; margin-bottom: .25rem; }
#popup .p-translation { font-size: 1.1rem; color: var(--accent); margin-bottom: .5rem; }
#popup .p-context     { font-size: .82rem; color: var(--muted); margin-bottom: 1rem; font-style: italic; }
#popup .p-actions     { display: flex; gap: .75rem; }
#popup .p-actions button {
  flex: 1; padding: .7rem; border: none; border-radius: var(--radius);
  font-size: .95rem; font-weight: 700; cursor: pointer;
}
#btn-save-word    { background: var(--accent); color: #000; }
#btn-close-popup  { background: var(--border); color: var(--text); }

/* ── Episode strip ── */
#episode-strip {
  display: flex; gap: .4rem; overflow-x: auto; padding: .5rem 1rem;
  background: var(--surface); border-top: 1px solid var(--border);
  flex-shrink: 0; scrollbar-width: thin;
}
#episode-strip::-webkit-scrollbar { height: 4px; }
#episode-strip::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.ep-btn {
  flex-shrink: 0; padding: .35rem .75rem;
  border: 1px solid var(--border); border-radius: 20px;
  background: none; color: var(--muted); font-size: .82rem; cursor: pointer;
  white-space: nowrap; transition: border-color .15s, color .15s;
}
.ep-btn:hover { color: var(--text); border-color: var(--text); }
.ep-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(232,160,32,.08); }

/* ── Responsive: hide sidebar on mobile ── */
@media (max-width: 700px) {
  #vocab-sidebar { display: none; }
  #search-main { padding: 1rem .9rem; }
}
