/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */

/* Dark mode scrollbars */
@media (prefers-color-scheme: dark) {
  * {
    scrollbar-color: #4b5563 #1f2937;
  }
}

/* Hide Alpine x-cloak elements until Alpine initializes */
[x-cloak] { display: none !important; }

/* Flash toast countdown progress bar */
@keyframes toast-progress {
  from { width: 100%; }
  to { width: 0%; }
}

/* Furigana visibility: hidden by default, revealed on hover/click or toggle */
.furigana-hide rt {
  visibility: hidden;
}

@media (hover: hover) {
  .furigana-hide ruby:hover rt {
    visibility: visible;
  }
}

.furigana-hide ruby.furigana-revealed rt {
  visibility: visible;
}

.furigana-show rt {
  visibility: visible;
}

/* Tango/grammar clickable links in article body */
.tango-link {
  color: #1d4ed8; /* blue-700 */
  cursor: pointer;
}

@media (prefers-color-scheme: dark) {
  .tango-link {
    color: #60a5fa; /* blue-400 */
  }
}

/* Selected tango/grammar highlight (sidebar click) */
.tango-link.tango-selected {
  background-color: #fef08a; /* yellow-200 */
  border-radius: 0.125rem;
  padding: 0 0.125rem;
}

@media (prefers-color-scheme: dark) {
  .tango-link.tango-selected {
    background-color: #854d0e; /* yellow-800 */
  }
}

/* Lazy turbo-frame: visible while empty (for IntersectionObserver),
   then contents once loaded so children flow as grid items */
turbo-frame.lazy-turbo-frame:empty {
  display: block;
  grid-column: 1 / -1;
  height: 1px;
}

turbo-frame.lazy-turbo-frame:not(:empty) {
  display: contents;
}

/* Furigana pill editor */
.furigana-editor__surface {
  line-height: 1.9;
  font-size: 1.125rem;
}

.furigana-editor[data-mode="inline"] .furigana-editor__surface {
  min-height: 3rem;
  line-height: 1.8;
  font-size: 1.5rem;
  font-weight: 600;
}

.fe-text {
  outline: none;
  white-space: pre-wrap;
}

.fe-text:empty {
  display: inline-block;
  min-width: 1ch;
  min-height: 1em;
}

.fe-text:focus {
  background-color: #f0f9ff; /* sky-50 */
  border-radius: 0.125rem;
}

@media (prefers-color-scheme: dark) {
  .fe-text:focus {
    background-color: #0c4a6e; /* sky-900 */
  }
}

/* Display pill: native <ruby> styled to look like a button */
.fe-pill {
  cursor: pointer;
  background-color: #fef3c7; /* amber-100 */
  border: 1px solid #fcd34d; /* amber-300 */
  border-radius: 0.25rem;
  padding: 0 0.25rem;
  margin: 0 0.05rem;
  ruby-position: over;
  transition: background-color 0.1s;
}

.fe-pill:hover {
  background-color: #fde68a; /* amber-200 */
}

.fe-pill rt {
  color: #92400e; /* amber-800 */
  font-size: 0.55em;
  font-weight: 500;
  position: relative;
  top: -4px;
}

@media (prefers-color-scheme: dark) {
  .fe-pill {
    background-color: rgba(120, 53, 15, 0.4); /* amber-900/40 */
    border-color: rgba(180, 83, 9, 0.6); /* amber-700 */
  }
  .fe-pill:hover {
    background-color: rgba(146, 64, 14, 0.6);
  }
  .fe-pill rt {
    color: #fde68a; /* amber-200 */
  }
}

/* Active pill (popover open) */
.fe-pill-wrap {
  position: relative;
  display: inline-block;
}

.fe-pill--active {
  background-color: #fde68a; /* amber-200 */
  border-color: #d97706;     /* amber-600 */
}

@media (prefers-color-scheme: dark) {
  .fe-pill--active {
    background-color: rgba(180, 83, 9, 0.7);
    border-color: #f59e0b;
  }
}

/* Popover anchored to the clicked pill */
.fe-popover {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: inline-flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 11rem;
  padding: 0.75rem;
  background: #ffffff;
  border: 1px solid #3b82f6;
  border-radius: 0.5rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
  text-align: left;
  line-height: 1.3;
  font-size: 0.95rem;
  font-weight: 400;
}

.fe-popover__label {
  font-size: 0.7rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.fe-popover__input {
  padding: 0.25rem 0.5rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.25rem;
  outline: none;
  background: #ffffff;
  color: #0f172a;
  font-size: 1rem;
  font-family: inherit;
}

.fe-popover__input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.fe-popover__actions {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.fe-popover__remove,
.fe-popover__done {
  border-radius: 0.25rem;
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: inherit;
}

.fe-popover__remove {
  background: transparent;
  color: #dc2626;
  border: 1px solid #fca5a5;
}

.fe-popover__remove:hover {
  background: #fee2e2;
}

.fe-popover__done {
  background: #3b82f6;
  color: #ffffff;
  border: 1px solid #3b82f6;
}

.fe-popover__done:hover {
  background: #2563eb;
}

@media (prefers-color-scheme: dark) {
  .fe-popover {
    background: #1e293b;
    border-color: #3b82f6;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  }
  .fe-popover__label { color: #94a3b8; }
  .fe-popover__input {
    background: #0f172a;
    color: #e2e8f0;
    border-color: #475569;
  }
  .fe-popover__remove:hover { background: rgba(153, 27, 27, 0.3); }
}

/* Floating popover anchored to a text selection (viewport-relative). */
.fe-add-ruby-popover {
  position: fixed;
  z-index: 100;
  display: inline-flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 13rem;
  padding: 0.75rem;
  background: #ffffff;
  border: 1px solid #10b981; /* emerald-500 */
  border-radius: 0.5rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
  text-align: left;
  line-height: 1.3;
  font-size: 0.95rem;
  font-weight: 400;
}

.fe-add-ruby-popover__header {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.fe-add-ruby-popover__preview {
  font-size: 1.05rem;
  color: #0f172a;
}

@media (prefers-color-scheme: dark) {
  .fe-add-ruby-popover {
    background: #1e293b;
    border-color: #10b981;
  }
  .fe-add-ruby-popover__preview { color: #e2e8f0; }
}
