:root {
  --accent-color: #00ff9f;
  --accent-dim: #00cc7f;
  --error-color: #ff6b6b;
  --warning-color: #ffd93d;
  --background-color: #fff;
  --font-color: #222;
  --secondary-color: #555;
  --reader-font-size: 16px;
}

body.dark {
  --background-color: #1a1a1a;
  --font-color: #e0e0e0;
  --secondary-color: #888;
}

@keyframes blink-dim {
  0%, 50% {
    opacity: 1;
  }
  51%, 100% {
    opacity: 0.3;
  }
}
@keyframes blink-off {
  0%, 50% {
    opacity: 1;
  }
  51%, 100% {
    opacity: 0;
  }
}
.container {
  max-width: 800px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body {
  background-color: var(--background-color);
  color: var(--font-color);
  transition: background-color 0.3s, color 0.3s;
}
body.terminal {
  font-size: 16px;
  line-height: 1.8;
}

header {
  margin-bottom: 1rem;
}
header h1 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  color: var(--accent-color);
}

.error-alert {
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid var(--error-color);
  color: var(--error-color);
  padding: 1rem;
  margin: 1rem 0;
}

.loading-text {
  color: var(--secondary-color);
  font-style: italic;
}

.divider {
  border: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--secondary-color), transparent);
  margin: 2em 0;
  opacity: 0.5;
}

.build-info {
  text-align: center;
  font-size: 0.6rem;
  opacity: 0.4;
  padding: 0.4rem 0 0.3rem;
  margin-top: auto;
  color: var(--secondary-color);
}
.build-info svg {
  width: 0.55rem;
  height: 0.55rem;
  vertical-align: middle;
}

.nav-buttons {
  display: flex;
  justify-content: space-between;
  margin: 1rem 0;
  gap: 1rem;
}

.nav-btn {
  padding: 0.5rem 1.25rem;
  background: transparent;
  border: 1px solid var(--secondary-color);
  color: var(--font-color);
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}
.nav-btn:hover:not(:disabled) {
  border-color: var(--accent-color);
  color: var(--accent-color);
}
.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.provider-buttons {
  display: flex;
  gap: 0.5rem;
  justify-self: end;
}

.provider-btn {
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid var(--secondary-color);
  color: var(--font-color);
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.9rem;
}
.provider-btn:hover:not(:disabled) {
  border-color: var(--accent-color);
  color: var(--accent-color);
}
.provider-btn.active {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: var(--background-color);
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--secondary-color);
  color: var(--font-color);
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}
.icon-btn:hover:not(:disabled) {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

button.retranslate-btn {
  display: inline;
  padding: 0.05em 0.2em;
  margin-left: 0.5em;
  background: var(--secondary-color);
  border: none;
  border-radius: 0.15em;
  color: var(--background-color);
  font-family: inherit;
  font-size: 0.75em;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
  opacity: 0.4;
  transition: opacity 0.2s;
}
button.retranslate-btn:hover {
  opacity: 0.7;
}

button.retranslate-line-btn {
  display: inline;
  padding: 0.05em 0.15em;
  margin-left: 0.25em;
  background: var(--secondary-color);
  border: none;
  border-radius: 0.15em;
  color: var(--background-color);
  font-family: inherit;
  font-size: 1em;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
  opacity: 0.35;
  transition: opacity 0.2s;
}
button.retranslate-line-btn:hover {
  opacity: 0.6;
}
button.retranslate-line-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.add-key-btn {
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid var(--accent-color);
  color: var(--accent-color);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  align-self: flex-start;
}
.add-key-btn:hover {
  background: var(--accent-color);
  color: var(--background-color);
}

.back-btn {
  padding: 0.5rem 1.25rem;
  text-decoration: none;
  display: inline-block;
  background: transparent;
  border: 1px solid var(--secondary-color);
  color: var(--font-color);
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}
.back-btn:hover:not(:disabled) {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.toggle-btn {
  background: transparent;
  border: 1px solid var(--secondary-color);
  color: var(--font-color);
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}
.toggle-btn:hover:not(:disabled) {
  border-color: var(--accent-color);
  color: var(--accent-color);
}
.toggle-btn.active {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: var(--background-color);
}

.btn {
  background: transparent;
  border: 1px solid var(--secondary-color);
  color: var(--font-color);
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}
.btn:hover:not(:disabled) {
  border-color: var(--accent-color);
  color: var(--accent-color);
}
.btn--primary {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: var(--background-color);
}
.btn--primary:hover:not(:disabled) {
  opacity: 0.85;
}
.btn--secondary {
  background: transparent;
  border-color: var(--secondary-color);
  color: var(--font-color);
}
.btn--danger {
  border-color: var(--error-color);
  color: var(--error-color);
}
.btn--danger:hover:not(:disabled) {
  background: var(--error-color);
  color: var(--background-color);
}
.btn--small {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
}
.btn--medium {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}
.btn--large {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
}

.url-input-group {
  display: flex;
  gap: 0.5rem;
}
.url-input-group input {
  flex: 1;
  background: transparent;
  border: 1px solid var(--secondary-color);
  padding: 0.75rem 1rem;
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color 0.2s;
}
.url-input-group input:focus {
  outline: none;
  border-color: var(--accent-color);
}
.url-input-group button {
  padding: 0.75rem 1.5rem;
  background: var(--accent-color);
  color: var(--background-color);
  border: none;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  transition: opacity 0.2s;
}
.url-input-group button:hover {
  opacity: 0.85;
}

.theme-toggle {
  position: relative;
  display: inline-block;
  width: 3rem;
  height: 1.5rem;
  justify-self: end;
}
.theme-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.theme-toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--secondary-color);
  transition: 0.3s;
  border-radius: 1.5rem;
}
.theme-toggle-slider:before {
  position: absolute;
  content: "";
  height: 1.125rem;
  width: 1.125rem;
  left: 0.1875rem;
  bottom: 0.1875rem;
  background-color: var(--background-color);
  transition: 0.3s;
  border-radius: 50%;
}
.theme-toggle-slider:hover {
  background-color: var(--accent-dim);
}

.theme-toggle input:checked + .theme-toggle-slider {
  background-color: var(--accent-color);
}
.theme-toggle input:checked + .theme-toggle-slider:before {
  transform: translateX(1.5rem);
}

.api-key-row {
  display: flex;
  gap: 0.5rem;
}
.api-key-row input {
  flex: 1;
}
.api-key-row button {
  padding: 0.5rem 0.75rem;
  background: transparent;
  border: 1px solid var(--error-color);
  color: var(--error-color);
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}
.api-key-row button:hover {
  background: var(--error-color);
  color: var(--background-color);
}

.reader-card {
  background: transparent;
  padding: 1rem 0;
  margin: 0.5rem 0;
}
.reader-card h2 {
  font-size: 1.25rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--secondary-color);
}

.settings-card {
  background: transparent;
  border: 1px solid var(--secondary-color);
  padding: 1.5rem;
}

.settings-fab,
.fab-link {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
  text-decoration: none;
}
.settings-fab button,
.fab-link button {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  background: var(--background-color);
  border: 1px solid var(--secondary-color);
  color: var(--font-color);
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.settings-fab button:hover,
.fab-link button:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
  box-shadow: 0 4px 12px rgba(0, 255, 159, 0.2);
}

.preload-stack {
  position: fixed;
  top: 0.5rem;
  right: 4rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  align-items: flex-end;
}

.preload-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--secondary-color);
  white-space: nowrap;
}

.preload-progress-bar {
  width: 60px;
  height: 4px;
  background: var(--secondary-color);
  border-radius: 2px;
  overflow: hidden;
}

.preload-progress-fill {
  height: 100%;
  background: var(--accent-color);
  transition: width 0.2s;
}

.preload-text {
  min-width: 40px;
  text-align: right;
}

.translation-content {
  font-size: var(--reader-font-size);
  line-height: 2;
}

.translation-block {
  margin-bottom: 0.5em;
}

.translated-line {
  cursor: pointer;
  padding: 0.25em 0;
  transition: color 0.2s;
  text-indent: 1em;
  margin: 0;
  background: transparent;
  border: none;
  font: inherit;
  color: inherit;
  text-align: left;
  width: 100%;
  display: block;
}
.translated-line:hover {
  color: var(--accent-color);
}
.translated-line.retranslating {
  opacity: 0.6;
}

.original-line {
  font-size: 0.8em;
  color: var(--secondary-color);
  opacity: 0.4;
  margin: 0.25em 0 0.75em 0;
  padding-left: 1.5em;
  border-left: 2px solid var(--secondary-color);
  font-style: italic;
}

.speaker-label {
  font-weight: 500;
  font-style: normal;
  opacity: 0.8;
}

.failed-line {
  background: rgba(255, 107, 107, 0.08);
  border-left: 3px solid var(--error-color);
  padding-left: 0.5em;
  margin-left: -0.5em;
}

.original-line-failed {
  font-size: var(--reader-font-size);
  color: var(--secondary-color);
  opacity: 0.7;
  margin: 0;
  padding: 0.25em 0;
  text-indent: 1em;
  font-style: italic;
}

.retranslating-indicator {
  color: var(--accent-color);
  animation: blink-dim 1s infinite;
}

.translating-indicator {
  text-indent: 1em;
  margin: 0;
  padding: 0.25em 0;
  color: var(--secondary-color);
  font-style: italic;
}

.cursor {
  animation: blink-off 1s infinite;
  font-weight: bold;
  color: var(--accent-color);
}

.terminal-prompt {
  color: var(--accent-color);
  font-weight: bold;
}

.settings-header {
  margin-bottom: 1rem;
}
.settings-header h1 {
  color: var(--accent-color);
}

.setting-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(128, 128, 128, 0.2);
}
.setting-row:last-child {
  border-bottom: none;
}
.setting-row.full-width {
  grid-template-columns: 1fr;
}
.setting-row.full-width label {
  margin-bottom: 0.5rem;
}
.setting-row label {
  font-size: 0.9rem;
  color: var(--secondary-color);
}
.setting-row input[type=range] {
  width: 100%;
  accent-color: var(--accent-color);
}
.setting-row input[type=password],
.setting-row textarea,
.setting-row select {
  width: 100%;
  background: transparent;
  border: 1px solid var(--secondary-color);
  padding: 0.5rem;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--font-color);
}
.setting-row input[type=password]:focus,
.setting-row textarea:focus,
.setting-row select:focus {
  outline: none;
  border-color: var(--accent-color);
}
.setting-row select {
  cursor: pointer;
}

.settings-footer {
  margin-top: 2rem;
}

.preload-hint {
  font-size: 0.85rem;
  color: var(--secondary-color);
}

.api-key-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--background-color);
  overflow-y: auto;
  z-index: 1000;
}

.modal-content {
  min-height: 100vh;
  max-width: 600px;
  margin: 0 auto;
  padding: 1.5rem;
}
.modal-content .container {
  padding: 0;
  min-height: auto;
}
.modal-content .settings-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--accent-color);
}
.modal-content .settings-header h1 {
  margin-bottom: 0;
  font-size: 1.25rem;
}
.modal-content .settings-card {
  border: 1px solid rgba(128, 128, 128, 0.3);
  padding: 0.5rem 1rem;
  border-radius: 4px;
  background: rgba(128, 128, 128, 0.05);
}
.modal-content .setting-row {
  grid-template-columns: 1fr;
  padding: 0.75rem 0;
}
.modal-content .setting-row label {
  margin-bottom: 0.5rem;
  font-weight: 500;
}
.modal-content .settings-footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(128, 128, 128, 0.2);
}
.modal-content .settings-footer .back-btn {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--secondary-color);
  background: transparent;
  color: var(--font-color);
  cursor: pointer;
  transition: all 0.2s;
}
.modal-content .settings-footer .back-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.novel-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.novel-list-header {
  font-size: 1rem;
  color: var(--secondary-color);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--secondary-color);
}

.novel-list-item {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  border: 1px solid var(--secondary-color);
  transition: border-color 0.2s;
}
.novel-list-item:hover {
  border-color: var(--accent-color);
}

.novel-list-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem 1rem;
  background: transparent;
  border: none;
  color: var(--font-color);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: color 0.2s;
}
.novel-list-btn:hover {
  color: var(--accent-color);
}
.novel-list-btn:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

.novel-list-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.novel-list-title {
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.4;
}

.novel-list-info {
  font-size: 0.8rem;
  color: var(--secondary-color);
}

.novel-download-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  padding: 0;
  background: transparent;
  border: none;
  border-left: 1px solid var(--secondary-color);
  color: var(--secondary-color);
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
}
.novel-download-btn:hover {
  background: var(--accent-color);
  color: var(--background-color);
  border-color: var(--accent-color);
}

.novel-expand-icon {
  font-size: 0.7rem;
  color: var(--secondary-color);
}

.chapter-list {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--secondary-color);
  background: var(--background-color);
}

.chapter-item {
  padding: 0.25rem 0.5rem;
  min-width: 2.5rem;
  background: transparent;
  border: 1px solid var(--secondary-color);
  color: var(--font-color);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.chapter-item:hover, .chapter-item.last-seen {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: var(--background-color);
}
.chapter-item:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

.focus-wrapper.focus-off {
  position: static;
}
.focus-wrapper:not(.focus-off) {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--background-color);
  display: flex;
  flex-direction: column;
}

.focus-overlay {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1010;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.focus-exit-btn {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  background: var(--background-color);
  border: 1px solid var(--secondary-color);
  color: var(--font-color);
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  opacity: 0.4;
}
.focus-exit-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
  box-shadow: 0 4px 12px rgba(0, 255, 159, 0.2);
}
.focus-exit-btn:hover {
  opacity: 1;
}

.focus-settings-btn {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  background: var(--background-color);
  border: 1px solid var(--secondary-color);
  color: var(--font-color);
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  opacity: 0.4;
}
.focus-settings-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
  box-shadow: 0 4px 12px rgba(0, 255, 159, 0.2);
}
.focus-settings-btn:hover {
  opacity: 1;
}

.focus-close-overlay-btn {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  background: var(--background-color);
  border: 1px solid var(--secondary-color);
  color: var(--font-color);
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  opacity: 0.4;
}
.focus-close-overlay-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
  box-shadow: 0 4px 12px rgba(0, 255, 159, 0.2);
}
.focus-close-overlay-btn:hover {
  opacity: 1;
}

.settings-fab.focus-enter-btn {
  top: 4rem;
}

.touch-zones {
  position: fixed;
  inset: 0;
  z-index: 1005;
  display: grid;
  grid-template-columns: 33% 34% 33%;
  pointer-events: none;
}
.touch-zones > div {
  pointer-events: auto;
}
.touch-zones.center-only {
  display: flex;
  justify-content: center;
  align-items: stretch;
}
.touch-zones.center-only .zone-center {
  width: 50%;
  height: 100%;
}
.touch-zones.overlay-mode {
  z-index: 999;
}

.zone-left,
.zone-right {
  cursor: pointer;
}

.zone-center {
  cursor: pointer;
}

.page-indicator {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1010;
  font-size: 0.875rem;
  color: var(--secondary-color);
  opacity: 0.6;
  background: var(--background-color);
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
}

.focus-content {
  flex: 1;
  overflow: hidden;
}
.focus-content.paging-mode {
  overflow: hidden;
}
.focus-content.paging-mode .content-inner {
  height: 100%;
  column-width: 100vw;
  column-gap: 0;
  column-fill: auto;
  transition: transform 0.3s ease;
}
.focus-content.paging-mode .content-inner > .reader-card,
.focus-content.paging-mode .content-inner > article {
  padding: 1rem;
  box-sizing: border-box;
}
.focus-content.scroll-mode {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.focus-content.scroll-mode .content-inner {
  padding: 1rem;
}

.focus-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1010;
  padding: 1rem;
  background: linear-gradient(transparent, var(--background-color) 30%);
  display: flex;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.focus-bottom-nav.visible {
  opacity: 1;
  pointer-events: auto;
}

.focus-wrapper:not(.focus-off):not(.overlay-visible) .translated-line {
  pointer-events: none;
}

.focus-wrapper.overlay-visible .translated-line {
  pointer-events: auto;
}

.scroll-mode-nav {
  padding: 2rem 1rem;
  display: flex;
  justify-content: center;
}

@media screen and (max-width: 768px) {
  input,
  textarea,
  select {
    font-size: 16px !important;
  }
  .chapter-item {
    min-width: 2rem;
    padding: 0.2rem 0.4rem;
  }
  .chapter-list {
    gap: 0.375rem;
    padding: 0.5rem 0.75rem;
  }
}
