/* App-specific styling for de Lampjestoets */
/* Most styling is inherited from base.css (loaded first). */

#intro.card,
#test.card {
  width: min(640px, 100%);
  align-self: center;
}

#result-screen.card {
  /* Viewport-relative so the summary grid always lays out within the screen
     (a plain 100% lets the shrink-to-fit <main> grow to the grid's max width).
     Subtract the safe-area insets too, so the card stays clear of the notch /
     home indicator in landscape; env() is 0 where there is no safe area. */
  width: min(840px, 100vw - 1.5rem - env(safe-area-inset-left) - env(safe-area-inset-right));
  /* As a flex item the default min-width:auto would let the grid's min-content
     stretch the card past the viewport; pin it so the definite width holds. */
  min-width: 0;
  align-self: center;
}

.summary-item {
  min-width: 0;
}

#intro h2 {
  background: var(--grad-warm);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
}

.intro-text {
  color: #1f2a37;
  font-size: 1.05rem;
  margin: 0.5rem 0;
}

.intro-list {
  list-style: none;
  margin: 0.75rem 0 1.25rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.intro-list li {
  background: #f8fafc;
  border-radius: 12px;
  padding: 0.65rem 0.85rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: #334155;
}

.start-btn,
#result-restart {
  width: 100%;
  margin-top: 0.5rem;
  background: var(--grad-warm);
  color: #fff;
  font-size: 1.1rem;
  box-shadow: 0 8px 25px rgba(249, 115, 22, 0.4);
}

@media (hover: hover) and (pointer: fine) {
  .start-btn:hover,
  #result-restart:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 35px rgba(249, 115, 22, 0.5);
  }
}

/* Test header: timer on its own row so the counter never shifts. */
.test-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.test-subhead {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.timer {
  font-size: 1.6rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: var(--grad-info);
  padding: 0.35rem 1.1rem;
  border-radius: 999px;
  box-shadow: 0 4px 15px rgba(79, 172, 254, 0.4);
  text-align: center;
  white-space: nowrap;
}

.timer.overtime {
  background: var(--grad-danger);
  box-shadow: 0 4px 15px rgba(245, 87, 108, 0.45);
  animation: pop 300ms ease;
}

.progress-pill {
  font-weight: 700;
  color: #475569;
  background: #f1f5f9;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.test-subhead .link-button {
  width: auto;
  flex-shrink: 0;
}

/* The OK key on the on-screen keypad submits the answer */
.keyboard button.key-ok {
  background: var(--grad-success);
  color: #fff;
  border-color: transparent;
  font-size: 1rem;
}

.keyboard button.key-ok:active {
  background: linear-gradient(135deg, #2bd66a 0%, #25e0c2 100%);
  transform: translateY(3px) scale(0.98);
}

@media (hover: hover) and (pointer: fine) {
  .keyboard button.key-ok:hover {
    background: linear-gradient(135deg, #2bd66a 0%, #25e0c2 100%);
    color: #fff;
    border-color: transparent;
  }
}

/* Result statistics */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  margin: 0.75rem 0 1rem;
}

@media (min-width: 640px) {
  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.75rem 0.5rem;
  border-radius: 16px;
  color: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0.95;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.stat-time {
  background: var(--grad-primary);
}

.stat-score {
  background: var(--grad-success);
}

.stat-within {
  background: var(--grad-info);
}

.stat-late {
  background: var(--grad-warm);
}

.overview-title {
  color: #1f2a37;
  font-size: 1.2rem;
  margin: 0.5rem 0 0.5rem;
}

/* Per-exercise overview.
   One shared grid (via subgrid) keeps every badge in the same column,
   regardless of how many digits the answer/time has. */
.summary-list {
  list-style: none;
  counter-reset: q;
  margin: 0;
  padding: 0.25rem;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  gap: 0.4rem 0.5rem;
  max-height: 48vh;
  overflow-y: auto;
  overflow-x: hidden;
  /* Don't chain the list's scroll to the page (no rubber-band / pull-to-refresh
     when scrolling past the top or bottom of the overview). */
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

.summary-item {
  counter-increment: q;
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  align-items: center;
  column-gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  background: #f8fafc;
  border-left: 5px solid #cbd5e1;
  font-size: 0.98rem;
}

.summary-item::before {
  content: counter(q) ".";
  color: #94a3b8;
  font-weight: 700;
  text-align: right;
  min-width: 1.6rem;
  font-variant-numeric: tabular-nums;
}

.summary-item.correct {
  border-left-color: #43e97b;
}

.summary-item.incorrect {
  border-left-color: #f5576c;
}

.summary-item.late {
  background: #fff7ed;
}

.s-eq {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  min-width: 0;
}

.s-sum {
  font-weight: 700;
  color: #1f2a37;
}

.s-answer {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.summary-item.correct .s-answer,
.summary-item.correct .s-mark {
  color: #059669;
}

.summary-item.incorrect .s-answer,
.summary-item.incorrect .s-mark {
  color: #e11d48;
}

.s-mark {
  font-weight: 800;
}

.s-correct,
.s-late,
.s-time {
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
}

.s-correct {
  color: #475569;
  background: #e2e8f0;
  justify-self: start;
}

.s-late {
  color: #b45309;
  background: #fef3c7;
  justify-self: start;
}

.s-time {
  color: #475569;
  background: #eef2f7;
  justify-self: end;
  font-variant-numeric: tabular-nums;
}

.summary-item.late .s-time {
  color: #b45309;
  background: #fff0d6;
}

/* Placeholder cells reserve the column so badges stay aligned. */
.s-empty {
  background: transparent;
  padding: 0;
}

/* Confirmation modal (native <dialog>) */
.modal {
  border: none;
  padding: 0;
  margin: auto;
  /* A <dialog> lives in the top layer, positioned against the viewport and
     unaffected by the body's safe-area padding — so inset it explicitly to keep
     it clear of the notch in landscape. */
  width: min(420px, calc(100vw - 2rem - env(safe-area-inset-left) - env(safe-area-inset-right)));
  border-radius: 20px;
  background: #fff;
  color: #1f2a37;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
}

.modal::backdrop {
  background: rgba(31, 42, 55, 0.55);
}

.modal[open] {
  animation: modalIn 0.18s ease;
}

.modal[open]::backdrop {
  animation: backdropIn 0.18s ease;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes backdropIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-card {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.modal-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: #1f2a37;
}

.modal-message {
  font-size: 1rem;
  color: #475569;
  font-weight: 500;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.modal-actions button {
  flex: 1;
}

.modal-danger {
  background: var(--grad-danger);
  color: #fff;
  box-shadow: 0 8px 25px rgba(245, 87, 108, 0.4);
}

@media (hover: hover) and (pointer: fine) {
  .modal-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 35px rgba(245, 87, 108, 0.5);
  }
}

@media (max-width: 360px) {
  .modal-actions {
    flex-direction: column;
  }
}

@media (max-width: 540px) {
  .timer {
    font-size: 1.4rem;
  }

  .summary-list {
    max-height: 52vh;
    column-gap: 0.35rem;
  }

  .summary-item {
    font-size: 0.9rem;
    padding: 0.5rem 0.55rem;
    column-gap: 0.35rem;
  }

  .summary-item::before {
    min-width: 1.4rem;
  }

  .s-correct,
  .s-late,
  .s-time {
    font-size: 0.78rem;
    padding: 0.1rem 0.4rem;
  }
}

/* Short landscape (e.g. phone on its side): put the prompt/input beside the
   keypad so the whole test fits without scrolling. */
@media (max-height: 480px) and (orientation: landscape) {
  #test.card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "header keyboard"
      "prompt keyboard"
      "answer keyboard";
    align-items: start;
    column-gap: 1.25rem;
    row-gap: 0.4rem;
  }

  .test-header {
    grid-area: header;
  }

  #prompt {
    grid-area: prompt;
    margin: 0.4rem 0;
  }

  #answer-form {
    grid-area: answer;
  }

  #onscreen-keyboard {
    grid-area: keyboard;
    margin-top: 0;
    align-self: center;
  }

  .keyboard {
    gap: 0.4rem;
  }

  .keyboard button {
    /* Keep keys tappable for small hands even on short landscape screens. */
    min-height: 44px;
    padding: 0.45rem 0;
  }

  .timer {
    font-size: 1.25rem;
  }

  /* Compact the start screen so it fits a short landscape viewport. */
  #intro.card {
    padding: 0.9rem 1.2rem;
  }

  #intro h2 {
    font-size: 1.4rem;
    margin-bottom: 0.2rem;
  }

  .intro-text {
    font-size: 0.95rem;
    margin: 0.25rem 0;
  }

  .intro-list {
    margin: 0.4rem 0 0.6rem;
    gap: 0.3rem;
  }

  .intro-list li {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
  }

  .start-btn {
    font-size: 1rem;
    padding: 0.6rem 1rem;
  }
}
