/* Look of the original trails.edrahor.com search page; the results got columns, context and filters. */
:root {
  --bg-color: #f5f5f5; --container-bg: #ffffff; --text-color: #333; --form-bg: #f9f9f9; --border-color: #ddd;
  --highlight-bg: #ffeb3b; --original-bg: #fffde7; --found-border: #4CAF50; --result-border: #4CAF50;
  --button-bg: #4CAF50; --button-hover: #45a049; --button-text: #fff; --error-bg: #ffebee; --error-color: #c62828;
  --success-bg: #e8f5e9; --shadow-color: rgba(0,0,0,0.1); --meta-color: #777; --link: #2e7d32; --code: #9e9e9e;
}
.dark-theme {
  --bg-color: #121212; --container-bg: #1e1e1e; --text-color: #e0e0e0; --form-bg: #2d2d2d; --border-color: #444;
  --highlight-bg: #5a5016; --original-bg: #32302a; --found-border: #2e7d32; --result-border: #2e7d32;
  --button-bg: #2e7d32; --button-hover: #1b5e20; --button-text: #e0e0e0; --error-bg: #4a1c1c; --error-color: #ff6b6b;
  --success-bg: #1b3a20; --shadow-color: rgba(0,0,0,0.3); --meta-color: #aaa; --link: #81c784; --code: #777;
}
* { box-sizing: border-box; }
html { background-color: var(--bg-color); }
body {
  font-family: Arial, sans-serif; margin: 0; padding: 20px; background-color: var(--bg-color); color: var(--text-color);
  transition: background-color .3s ease, color .3s ease; overflow-x: hidden;
}
.container {
  max-width: 1200px; margin: 0 auto; background-color: var(--container-bg); padding: 20px; border-radius: 5px;
  box-shadow: 0 2px 5px var(--shadow-color); position: relative;
}
h1 { text-align: center; font-weight: normal; font-size: 2em; margin: .4em 0 .2em; }
.intro { text-align: center; color: var(--meta-color); font-size: 14px; margin: 0 0 1.2em; }
h2 { font-weight: normal; margin: 0 0 10px; }
/* top right corner of the card: interface languages and the books link, small and muted */
.corner { position: absolute; top: 6px; right: 8px; display: flex; align-items: baseline; gap: 10px; font-size: 12.5px; }
.tools-link { text-decoration: none; color: var(--meta-color); padding: .2rem .4rem; border-radius: 3px; }
.tools-link:hover { color: var(--link); background: rgba(76, 175, 80, .1); }
.lang-switch { display: flex; align-items: baseline; gap: 1px; }
.lang-switch a {
  background: transparent; color: var(--meta-color); padding: 2px 5px; border-radius: 3px; text-decoration: none;
  opacity: .75;
}
.lang-switch a:hover { background: rgba(76, 175, 80, .1); color: var(--link); opacity: 1; }
.lang-switch a.current { color: var(--text-color); font-weight: bold; opacity: 1; cursor: default; }
.lang-switch a.current:hover { background: transparent; }
/* where the round theme button (fixed to the window) would cover the corner */
@media (max-width: 1320px) { .corner { right: 56px; } }

.search-form { margin-bottom: 20px; padding: 15px; background-color: var(--form-bg); border-radius: 5px; }
.form-group { margin-bottom: 10px; }
.form-group > label { display: block; margin-bottom: 5px; font-weight: bold; }
.game-selection > label:first-child, .search-options > label { display: inline-block; font-weight: normal; margin-right: 15px; }
.game-selection label.game { display: inline-block; margin: 0 15px 8px 0; font-weight: normal; cursor: pointer; }
.game-selection label.game.off { color: var(--meta-color); cursor: default; }
.search-options div { margin-bottom: 5px; }
.search-options div label { cursor: pointer; }
input[type=text] {
  width: 100%; padding: 8px; border: 1px solid var(--border-color); background-color: var(--container-bg);
  color: var(--text-color); border-radius: 4px; font: inherit;
}
button {
  background-color: var(--button-bg); color: var(--button-text); padding: 10px 15px; border: none; border-radius: 4px;
  cursor: pointer; font: inherit;
}
button:hover { background-color: var(--button-hover); }

.results { margin-top: 20px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.toolbar .filters { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 13px; color: var(--meta-color); }
.toolbar .filters input[type=text] { width: 190px; padding: 4px 8px; font-size: 13px; }
.toolbar .filters input#who { width: 212px; }      /* «Кто говорит, например Ллойд» fits whole */
.toolbar label { cursor: pointer; white-space: nowrap; }

/* hint dropdown under the speaker and file fields */
.hint-wrap { position: relative; display: inline-block; }
.hints {
  position: absolute; top: 100%; left: 0; z-index: 20; margin: 2px 0 0; padding: 3px 0; list-style: none;
  min-width: 100%; width: max-content; max-width: min(460px, 90vw); max-height: 320px; overflow-y: auto;
  background: var(--container-bg); color: var(--text-color); border: 1px solid var(--border-color); border-radius: 4px;
  box-shadow: 0 4px 14px var(--shadow-color); font-size: 13px;
}
.hints li { padding: 5px 10px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hints li:hover, .hints li.active { background: var(--form-bg); color: var(--link); }
.hints .sub { color: var(--meta-color); margin-left: 8px; font-size: .92em; }
#file-hints { left: auto; right: 0; }

.result-item {
  margin-bottom: 15px; padding: 12px 15px; background-color: var(--form-bg); border-left: 4px solid var(--result-border);
}
.result-meta { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--meta-color); margin-bottom: 8px; }
.result-meta strong { color: var(--text-color); font-weight: bold; overflow-wrap: anywhere; }
.result-meta a { color: var(--link); cursor: pointer; text-decoration: none; white-space: nowrap; }
.result-meta a:hover { text-decoration: underline; }
.cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.cell {
  padding: 8px 10px; background-color: var(--container-bg); border: 1px solid var(--border-color); border-radius: 3px;
  white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.4;
}
.cell.en, .cell.jp { background-color: var(--original-bg); }
.cell.found { border: 2px solid var(--found-border); padding: 7px 9px; }
.cell .lang { display: block; font-size: 11px; font-weight: bold; color: var(--meta-color); margin-bottom: 3px; }
.cell.empty .txt { color: var(--meta-color); font-style: italic; }
/* who speaks: a small coloured label above the line, so it is never read as part of the text */
.cell .speaker { display: block; font-size: 12px; font-weight: bold; color: var(--link); margin-bottom: 3px; }
.cell .speaker::after { content: ':'; }
.cell.jp { line-height: 1.9; }
ruby { ruby-position: over; }
ruby rt { font-size: .55em; line-height: 1; color: var(--text-color); opacity: .8; font-weight: normal; text-align: center; }
.highlight { background-color: var(--highlight-bg); padding: 2px 0; font-weight: bold; }
.code { color: var(--code); font-size: .85em; }
body:not(.show-codes) .code { display: none; }

.no-results { padding: 15px; background-color: var(--success-bg); border-radius: 4px; text-align: center; }
.error { color: var(--error-color); padding: 10px; background-color: var(--error-bg); border-radius: 4px; margin-bottom: 15px; }
.pager { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; margin-top: 14px; }
.pager button {
  min-width: 38px; padding: 7px 11px; background: var(--container-bg); color: var(--text-color);
  border: 1px solid var(--border-color);
}
.pager button:hover:not(:disabled) { background: var(--form-bg); border-color: var(--button-bg); }
.pager button.current { background: var(--button-bg); color: var(--button-text); border-color: var(--button-bg); cursor: default; }
.pager button:disabled { opacity: .45; cursor: default; }
.pager .gap { color: var(--meta-color); padding: 0 2px; }
.execution-time { text-align: center; font-style: italic; font-size: 14px; color: var(--meta-color); margin-top: 20px; }

footer {
  max-width: 800px; margin: 1rem auto 0; text-align: center; font-size: .8em; color: var(--meta-color);
  padding: 1rem 0; border-top: 1px solid var(--border-color);
}
footer p { margin: .2em 0; }
footer .links { display: flex; justify-content: center; gap: 20px; margin-bottom: .6em; font-size: 1.1em; }
footer .links a { display: inline-flex; align-items: center; gap: 6px; color: var(--meta-color); text-decoration: none; }
footer .links a:hover { color: var(--text-color); }
footer .links svg { width: 17px; height: 17px; fill: currentColor; }
.updated { font-size: .9em; opacity: .8; }
/* taps for the hidden counter (stats.js), no tap flash and no double-tap zoom */
footer .credits { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

.theme-toggle {
  position: fixed; top: 20px; right: 20px; width: 36px; height: 36px; padding: 0; border-radius: 50%; z-index: 10;
  background-color: var(--form-bg); border: 1px solid var(--border-color); display: flex; align-items: center;
  justify-content: center; box-shadow: 0 2px 5px var(--shadow-color); transition: transform .2s ease;
}
.theme-toggle:hover { transform: scale(1.1); background-color: var(--form-bg); }
.theme-toggle svg { width: 20px; height: 20px; fill: var(--text-color); }
.theme-toggle .sun, .dark-theme .theme-toggle .moon { display: none; }
.dark-theme .theme-toggle .sun { display: block; }

dialog {
  width: min(1300px, 96vw); max-height: 90vh; padding: 0; border: 1px solid var(--border-color); border-radius: 6px;
  background: var(--container-bg); color: var(--text-color); box-shadow: 0 4px 20px var(--shadow-color);
}
dialog::backdrop { background: rgba(0,0,0,.5); }
.ctx-head {
  position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 15px; background: var(--form-bg); border-bottom: 1px solid var(--border-color); font-size: 14px;
}
.ctx-head a { color: var(--link); margin-right: 14px; }
.ctx-head button { background: transparent; color: var(--text-color); padding: 0 6px; font-size: 18px; }
#ctx-body { padding: 12px 15px; }
#ctx-body .result-item { margin-bottom: 8px; border-left-color: var(--border-color); }
#ctx-body .result-item.current { border-left-color: var(--result-border); box-shadow: 0 0 0 2px var(--found-border); }

@media (max-width: 768px) {
  body { padding: 10px; }
  .container { padding: 14px; }
  h1 { font-size: 1.5em; margin-top: 1.2em; }
  .cols { grid-template-columns: 1fr; }
  .theme-toggle { top: 10px; right: 10px; width: 32px; height: 32px; }
  .corner { right: 46px; gap: 4px; }
}

/* hidden visit counter (F1), see stats.js */
.stats-panel {
  position: fixed; right: 16px; bottom: 16px; z-index: 1000; width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto; overscroll-behavior: contain;
  background: var(--container-bg); color: var(--text-color); border: 1px solid var(--border-color);
  border-radius: 6px; box-shadow: 0 6px 24px var(--shadow-color); font-size: 13px;
}
.stats-head {
  position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 8px 12px;
  background: var(--form-bg); border-bottom: 1px solid var(--border-color);
}
.stats-head button { background: transparent; color: var(--meta-color); padding: 2px 6px; font-size: 14px; }
.stats-head button:hover { background: transparent; color: var(--text-color); }
.stats-body { padding: 10px 12px; }
.stats-body table { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
.stats-body th, .stats-body td { padding: 3px 6px; text-align: right; border-bottom: 1px solid var(--border-color); }
.stats-body th:first-child { text-align: left; font-weight: normal; color: var(--meta-color); }
.stats-body thead th { font-weight: normal; color: var(--meta-color); }
.stats-body .note { color: var(--meta-color); font-size: 12px; margin: 10px 0 4px; }
.stats-body .cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 4px 16px; }
.stats-body h4 { margin: 8px 0 3px; font-size: 12px; font-weight: bold; color: var(--meta-color); }
.stats-body ul { list-style: none; margin: 0; padding: 0; }
.stats-body li { overflow-wrap: anywhere; line-height: 1.45; }
.stats-body li .n { display: inline-block; min-width: 3.2em; color: var(--link); font-variant-numeric: tabular-nums; }
.stats-body li.empty { color: var(--meta-color); font-style: italic; }
@media (max-width: 768px) {
  .stats-panel { right: 8px; bottom: 8px; width: calc(100vw - 16px); max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); }
  .stats-head button { padding: 6px 10px; font-size: 18px; }
  .stats-body { padding: 8px 10px; }
  .stats-body th, .stats-body td { padding: 3px 4px; }
}
