/*
 * App styles: everything Bootstrap does not already provide.
 */

/* ---- Animations --------------------------------------------------------------------------
   Hand-written rather than pulling in a library for seven keyframes. All of them are disabled
   under prefers-reduced-motion -- the question prompt pulses continuously, which is exactly
   the kind of thing that setting exists to stop. */

.animated {
  animation-duration: 1s;
  animation-fill-mode: both;
}

.animated.animate-slow  { animation-duration: 2s; }
.animated.animate-quick { animation-duration: 0.5s; }
.animated.infinite      { animation-iteration-count: infinite; }

/* Staggered entrances on the landing page. */
.ani-s2 { animation-delay: 1s; }
.ani-s3 { animation-delay: 1.1s; }
.ani-s4 { animation-delay: 1.2s; }
.ani-s5 { animation-delay: 1.5s; }

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.fadeIn { animation-name: fadeIn; }

@keyframes fadeInUp {
  from { opacity: 0; transform: translate3d(0, 100%, 0); }
  to   { opacity: 1; transform: none; }
}
.fadeInUp { animation-name: fadeInUp; }

@keyframes fadeInDown {
  from { opacity: 0; transform: translate3d(0, -100%, 0); }
  to   { opacity: 1; transform: none; }
}
.fadeInDown { animation-name: fadeInDown; }

@keyframes fadeInLeft {
  from { opacity: 0; transform: translate3d(-100%, 0, 0); }
  to   { opacity: 1; transform: none; }
}
.fadeInLeft { animation-name: fadeInLeft; }

@keyframes slideInLeft {
  from { transform: translate3d(-100%, 0, 0); visibility: visible; }
  to   { transform: translate3d(0, 0, 0); }
}
.slideInLeft { animation-name: slideInLeft; }

@keyframes slideOutRight {
  from { transform: translate3d(0, 0, 0); }
  to   { visibility: hidden; transform: translate3d(100%, 0, 0); }
}
.slideOutRight { animation-name: slideOutRight; }

@keyframes pulse {
  from { transform: scale3d(1, 1, 1); }
  50%  { transform: scale3d(1.05, 1.05, 1.05); }
  to   { transform: scale3d(1, 1, 1); }
}
.pulse { animation-name: pulse; }

@media (prefers-reduced-motion: reduce) {
  .animated {
    animation: none !important;
    transition: none !important;
  }
  /* slideOutRight ends on visibility:hidden, so without its animation the outgoing question
     must be hidden some other way or it would stay on screen. */
  .slideOutRight { visibility: hidden; }
}

/* ---- Hero ------------------------------------------------------------------------------- */

:root {
  --hero-padding-y: 3rem;
}

.hero {
  padding-top: var(--hero-padding-y);
  padding-bottom: var(--hero-padding-y);
  margin-bottom: 0;
  background-color: var(--bs-body-bg);
}

@media (min-width: 768px) {
  .hero {
    padding-top: calc(var(--hero-padding-y) * 1.6);
    padding-bottom: calc(var(--hero-padding-y) * 1.6);
  }
}

.hero .container { max-width: 40rem; }
.hero p:last-child { margin-bottom: 0; }
.hero-heading { font-weight: 300; }

.box-shadow { box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.05); }
.qs { box-shadow: 0 0 5px 0 #ccc; }

footer {
  padding-top: 3rem;
  padding-bottom: 3rem;
}
footer p { margin-bottom: 0.25rem; }

/* ---- Dashboard --------------------------------------------------------------------------- */

.card-header {
  font-size: 15px;
  padding-top: 5px;
  padding-bottom: 5px;
  text-transform: uppercase;
  font-weight: bold;
  letter-spacing: 1.3px;
  color: #6f6f6f;
}

.activity-card .card-text { flex-grow: 1; }
.activity-card .card-body { display: flex; flex-direction: column; }

/* ---- Question box ------------------------------------------------------------------------ */

/* overflow is clipped only on the live card, where the question slides in and out. */
.question-box { overflow: hidden; }

/* A question row appears twice: in the live card, and again in every answered card below it.
   These rules are deliberately not scoped to .question-box so that an archived question keeps
   the colour that says whether it was got right. */
.question {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  font-size: 1.5em;
}

.question .question-part { text-shadow: 0 0 7px #bdbdbd; }
.question .question-part.desired { color: #666; transition: color 0.6s; }
.question .question-part.desired.correctAnswer { color: var(--bs-primary); }
.question .question-part.desired.incorrectAnswer { color: #ff0500; }

.question-box input {
  transition: background-color 0.6s, color 0.6s;
}
.question-box input.correctAnswer {
  background-color: var(--bs-primary);
  color: #fff;
}
.question-box input.incorrectAnswer {
  background-color: #ff0500;
  color: #fff;
}

.incorrectAnswer { color: #ff0500; }
.words-right { color: var(--bs-primary); }

/* Small labels tucked into the corners of the question card. */
.trackedLabel {
  font-size: 12px;
  font-style: italic;
  color: #636363;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  position: absolute;
}
.trackedLabel.questionLabel  { left: 10px; top: 10px; }
.trackedLabel.questionTiming { right: 10px; top: 10px; }

.clock-icon {
  width: 0.85em;
  height: 0.85em;
  vertical-align: -0.1em;
}

/* On a phone the two corner labels would sit on top of the question text. */
@media (max-width: 575.98px) {
  .trackedLabel { position: static; display: block; text-align: center; }
  .question { font-size: 1.15em; }
}

#history .card { margin-bottom: 12px; }

/* An archived card carries the same corner labels as the live one, so it needs room for them
   above the question. */
[data-history] .card-body { padding-top: 1.75rem; }

.historyElement { margin-bottom: 15px; }
.historyElement .historyValue p {
  font-size: 3.5rem;
  line-height: 100%;
}

/* ---- Word list --------------------------------------------------------------------------- */

.wordlist-table { font-variant-numeric: tabular-nums; }
.accuracy-unknown { color: var(--bs-secondary-color); }

/* ---- Dictionary -------------------------------------------------------------------------- */

.defList .definition { margin: 10px; }
.definition .answerDef { white-space: pre-wrap; font-family: var(--bs-font-monospace); }

/* ---- Offline indicator ------------------------------------------------------------------- */

/* Shown while guesses are queued and failing to reach the server.
   The two-class selector is deliberate: this element also carries [data-tip], and the
   tooltip rule below sets `position: relative`. At equal specificity that rule would win on
   source order and drop the indicator into the page flow at the top of the document. */
.network.trackedLabel {
  color: #aaa;
  bottom: 1em;
  right: 1em;
  top: auto;
  left: auto;
  position: fixed;
  display: none;
  z-index: 20;
  background: var(--bs-body-bg);
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.15);
}
.network.trackedLabel.is-visible { display: block; }

/* ---- CSS-only tooltip -------------------------------------------------------------------
   Pure CSS, so tooltips cost no JavaScript. Shown on hover, on keyboard focus, and while a
   .tip-open class is set -- touch devices have no hover, so the dictionary's help button
   toggles that class instead. */

[data-tip] { position: relative; }

[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  width: max-content;
  max-width: min(280px, 70vw);
  padding: 0.4rem 0.6rem;
  border-radius: 0.3rem;
  background: #000;
  color: #fff;
  font-size: 0.8rem;
  font-style: normal;
  text-transform: none;
  letter-spacing: normal;
  line-height: 1.35;
  text-align: left;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s;
  pointer-events: none;
  z-index: 30;
}

[data-tip]:hover::after,
[data-tip]:focus-visible::after,
[data-tip].tip-open::after {
  opacity: 1;
  visibility: visible;
}

/* The dictionary's "why is this hard to read?" button. */
.uglyfloat {
  font-size: 1.5em;
  position: fixed;
  right: 1em;
  bottom: 1em;
  background-color: #343a40;
  border: 0;
  border-radius: 50%;
  width: 1.5em;
  height: 1.5em;
  line-height: 1;
  text-align: center;
  color: rgba(255, 255, 255, 0.7);
  box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.66);
  cursor: pointer;
  z-index: 20;
}

/* ---- Utilities --------------------------------------------------------------------------- */

.hidden { display: none !important; }
.flex-spacer { width: 5px; }
.activity-btn { height: calc(2.25rem + 2px); }

/* ---- Dialog -----------------------------------------------------------------------------
   Styled here rather than with Bootstrap's .modal-* classes: those read their padding from
   --bs-modal-* custom properties declared on a .modal ancestor, which a bare <dialog> does
   not have, so the header and footer collapse to zero padding. */

dialog::backdrop { background: rgba(0, 0, 0, 0.5); }

dialog.app-dialog {
  border: 0;
  border-radius: 0.5rem;
  padding: 0;
  max-width: 32rem;
  width: calc(100% - 2rem);
  color: var(--bs-body-color);
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.3);
}

.app-dialog .dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  border-bottom: 1px solid var(--bs-border-color);
}

.app-dialog .dialog-header h2 { margin: 0; }

.app-dialog .dialog-body { padding: 1rem; }

.app-dialog .dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem;
  border-top: 1px solid var(--bs-border-color);
}

.app-dialog .historyElement { margin-bottom: 0; }
.app-dialog .historyElement .historyValue p { font-size: 2.5rem; }
