/* Gloshjälpen: linjerat papper, kulspetsblått, rättningspenna och överstrykningspenna. */

:root {
  --desk: #e9eef6;
  --paper: #fdfeff;
  --paper-fold: #f4f7fd;
  --rule: #d6e1f1;
  --rule-strong: #adc0de;
  --margin: #eea3ae;
  --ink: #1b2559;
  --ink-soft: #56628f;
  --pen: #2445d6;
  --pen-hover: #1b35b0;
  --pen-tint: #e6ecff;
  --on-pen: #ffffff;
  --green: #0f7d47;
  --green-tint: #e2f4e9;
  --red: #c4223a;
  --red-tint: #fce8eb;
  --marker: #ffe45c;
  --marker-soft: #fff1a3;
  --marker-ink: #1b2559;
  --note: #fff6c4;
  --shadow: 0 1px 0 rgba(27, 37, 89, 0.06), 0 12px 28px -18px rgba(27, 37, 89, 0.4);
  --hand: 'Shantell Sans', 'Segoe Print', 'Comic Sans MS', cursive;
  --text: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --desk: #0d1330;
    --paper: #161f43;
    --paper-fold: #1b2552;
    --rule: #27335f;
    --rule-strong: #3d4d86;
    --margin: #8a4157;
    --ink: #e9edfb;
    --ink-soft: #a6b0d6;
    --pen: #8ea4ff;
    --pen-hover: #aabaff;
    --pen-tint: #26346c;
    --on-pen: #0d1330;
    --green: #5fd59a;
    --green-tint: #173d33;
    --red: #ff8090;
    --red-tint: #48202f;
    --marker-soft: rgba(255, 228, 92, 0.4);
    --note: #2f2c1d;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 14px 30px -18px rgba(0, 0, 0, 0.8);
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--desk);
  color: var(--ink);
  font: 400 1.125rem/1.5 var(--text);
}

a {
  color: var(--pen);
}

:focus-visible {
  outline: 3px solid var(--pen);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Ram ---------- */

.topbar,
main {
  max-width: 44rem;
  margin: 0 auto;
  padding-inline: max(1rem, env(safe-area-inset-left)) max(1rem, env(safe-area-inset-right));
}

.topbar {
  padding-top: 1rem;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--ink);
  font: 700 1.4rem/1 var(--hand);
  text-decoration: none;
}

main {
  padding-top: 0.5rem;
  padding-bottom: 4rem;
  outline: none;
}

h1,
h2 {
  margin: 0 0 0.5em;
  line-height: 1.2;
}

h2 {
  font-size: 1.25rem;
}

.page-title {
  margin: 1rem 0 0.5rem;
  font: 700 2.25rem/1.15 var(--hand);
}

.lead {
  max-width: 34em;
  color: var(--ink-soft);
}

.muted {
  color: var(--ink-soft);
}

.small {
  font-size: 0.95rem;
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.35rem 0;
  color: var(--ink-soft);
  font-weight: 700;
  text-decoration: none;
}

.back svg {
  width: 1.15em;
  height: 1.15em;
}

.back:hover {
  color: var(--pen);
}

/* ---------- Papper ---------- */

.sheet {
  position: relative;
  margin: 1rem 0 1.5rem;
  padding: 1.25rem;
  background: var(--paper);
  border-radius: 3px;
  box-shadow: var(--shadow);
}

/* Den röda marginallinjen, som i ett skrivhäfte */
.ruled::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 2rem;
  border-left: 2px solid var(--margin);
  pointer-events: none;
}

/* ---------- Knappar ---------- */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.55rem 1.1rem;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font: 700 1rem/1.2 var(--text);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.btn svg {
  flex: none;
  width: 1.25em;
  height: 1.25em;
}

.btn:hover {
  background: var(--paper-fold);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  border-color: var(--pen);
  background: var(--pen);
  color: var(--on-pen);
}

.btn-primary:hover {
  border-color: var(--pen-hover);
  background: var(--pen-hover);
}

.btn-big {
  min-height: 3.25rem;
  padding: 0.75rem 1.4rem;
  font-size: 1.1rem;
}

.btn-small {
  min-height: 2.5rem;
  padding: 0.4rem 0.85rem;
  font-size: 0.95rem;
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--pen);
}

.btn-ghost:hover {
  background: var(--pen-tint);
}

.btn.danger {
  color: var(--red);
}

.btn.danger:hover {
  background: var(--red-tint);
}

.file-btn input {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  cursor: pointer;
}

.file-btn:focus-within {
  outline: 3px solid var(--pen);
  outline-offset: 2px;
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--pen);
  font: inherit;
  font-size: 0.95rem;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- Startsidan ---------- */

.start-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1.25rem 0 1.75rem;
}

.start-actions .btn {
  flex: 1 1 13rem;
}

.shelf-sheet {
  padding: 0;
}

.shelf {
  margin: 0;
  padding: 0;
  list-style: none;
}

.shelf-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 1rem;
  padding: 0.9rem 1rem 0.9rem 2.9rem;
  border-bottom: 1px solid var(--rule);
  color: inherit;
  text-decoration: none;
}

.shelf li:last-child .shelf-item {
  border-bottom: 0;
}

.shelf-item:hover {
  background: var(--paper-fold);
}

.shelf-name {
  font: 700 1.35rem/1.25 var(--hand);
  overflow-wrap: anywhere;
}

.shelf-meta {
  grid-column: 1;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.shelf-item .marker {
  grid-column: 2;
  grid-row: 1 / span 2;
}

/* Överstrykningspenna: ojämna kanter och lite snett, som när man drar med pennan */
.marker {
  display: inline-block;
  padding: 0.1em 0.55em;
  border-radius: 0.3em 0.75em 0.35em 0.8em;
  background: var(--marker);
  color: var(--marker-ink);
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  transform: rotate(-1.5deg);
}

/* ---------- En glosa ---------- */

.list-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1.25rem;
  margin: 0.5rem 0 1rem;
}

.title-input {
  flex: 1 1 16rem;
  min-width: 0;
  padding: 0.15rem 0;
  border: 0;
  border-bottom: 2px dashed var(--rule-strong);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: 700 2rem/1.2 var(--hand);
}

.title-input:focus {
  outline: none;
  border-bottom: 3px solid var(--pen);
}

.lang-picker {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
}

select {
  min-height: 2.75rem;
  padding: 0.4rem 0.6rem;
  border: 2px solid var(--rule-strong);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}

.choice {
  margin: 0 0 1.1rem;
  padding: 0;
  border: 0;
}

.choice legend {
  margin-bottom: 0.45rem;
  padding: 0;
  font-weight: 700;
}

.choice-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.choice-options label {
  position: relative;
}

.choice-options input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
}

.choice-options span {
  display: block;
  padding: 0.5em 1em;
  border: 2px solid var(--rule-strong);
  border-radius: 999px;
  cursor: pointer;
}

.choice-options input:checked + span {
  border-color: var(--pen);
  background: var(--pen-tint);
  color: var(--ink);
  font-weight: 700;
}

.choice-options input:focus-visible + span {
  outline: 3px solid var(--pen);
  outline-offset: 2px;
}

.choice-options input:disabled + span {
  opacity: 0.45;
  cursor: not-allowed;
}

.practice-setup .btn-primary {
  margin-top: 0.25rem;
}

/* Glosboken: två kolumner med en vikningslinje emellan */
.glosbok {
  padding: 1rem 0 1.25rem;
}

.glosbok-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 1rem 0.75rem 2.75rem;
}

.glosbok-top h2 {
  margin: 0;
}

.scan-panel {
  padding: 0 1rem 0 2.75rem;
}

.cols-head,
.row {
  display: grid;
  grid-template-columns: 1fr 1fr 2.75rem;
}

.cols-head {
  margin-left: 2.25rem;
  border-bottom: 2px solid var(--rule-strong);
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 700;
}

.cols-head span {
  padding: 0.35rem 0.75rem;
}

.rows {
  margin: 0 0 0 2.25rem;
  padding: 0;
  list-style: none;
}

.row {
  position: relative;
  border-bottom: 1px solid var(--rule);
}

.cell {
  width: 100%;
  min-width: 0;
  padding: 0.7rem 0.75rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1.1rem;
}

.cell + .cell {
  border-left: 2px dashed var(--rule-strong);
}

.cell:focus {
  outline: none;
  background: var(--pen-tint);
  box-shadow: inset 0 -3px 0 var(--pen);
}

.row.needs-check .cell:not(:focus) {
  background: linear-gradient(transparent 48%, var(--marker-soft) 48%, var(--marker-soft) 80%, transparent 80%);
}

.row.is-new {
  animation: arrive 1.6s ease-out;
}

@keyframes arrive {
  from {
    background: var(--marker-soft);
  }
}

/* Rättningsmarkering i marginalen för ord man missade senast */
.miss-mark {
  position: absolute;
  top: 50%;
  left: -1.55rem;
  width: 0.6rem;
  height: 0.6rem;
  margin-top: -0.3rem;
  border-radius: 50%;
  background: var(--red);
}

.row-del {
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}

.row-del svg {
  width: 1.1rem;
  height: 1.1rem;
}

.row-del:hover {
  color: var(--red);
}

.glosbok-foot {
  padding: 0.75rem 1rem 0 2.75rem;
}

.glosbok-foot > .btn-ghost {
  margin-left: -0.75rem;
}

.paste {
  margin: 0.75rem 0;
}

.paste summary {
  color: var(--pen);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.paste label {
  display: block;
  margin: 0.5rem 0 0.35rem;
}

textarea {
  display: block;
  width: 100%;
  margin-bottom: 0.6rem;
  padding: 0.6rem 0.75rem;
  border: 2px solid var(--rule-strong);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}

.hint {
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.list-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  margin-left: -0.85rem;
}

/* Lapp: meddelanden om bildinläsningen ser ut som en gul lapp på sidan */
.note {
  margin: 0 0 1rem;
  padding: 0.85rem 1rem;
  border-radius: 2px;
  background: var(--note);
  box-shadow: 0 6px 14px -10px rgba(27, 37, 89, 0.5);
}

.note p {
  margin: 0 0 0.6rem;
}

.note p:last-child {
  margin-bottom: 0;
}

.note.error {
  background: var(--red-tint);
}

.note.working {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.scan-image {
  margin-bottom: 0.75rem;
}

.scan-image summary {
  color: var(--pen);
  font-weight: 700;
  cursor: pointer;
}

.scan-image img {
  display: block;
  max-width: 100%;
  margin-top: 0.5rem;
  border-radius: 2px;
}

.spinner {
  flex: none;
  width: 1.3rem;
  height: 1.3rem;
  border: 3px solid var(--rule-strong);
  border-top-color: var(--pen);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Övningen ---------- */

.practice-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0.25rem 0 1rem;
}

.progress {
  flex: 1;
  height: 0.6rem;
  overflow: hidden;
  border-radius: 99px;
  background: var(--rule);
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 0.3s ease;
}

.progress-count {
  color: var(--ink-soft);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.card {
  margin-bottom: 1.25rem;
  border-radius: 3px;
  background: var(--paper);
  box-shadow: var(--shadow);
  perspective: 1200px;
}

.card-prompt {
  --line: 2.25rem;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 12rem;
  padding: 1rem 1.25rem 1.5rem 3rem;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--line) - 1px),
    var(--rule) calc(var(--line) - 1px),
    var(--rule) var(--line)
  );
}

.card-prompt::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 2rem;
  border-left: 2px solid var(--margin);
}

.card-lang {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
  font-weight: 700;
}

.card-word {
  margin: 0.2rem 0 0;
  font: 700 clamp(2.1rem, 9vw, 3.4rem)/1.15 var(--hand);
  overflow-wrap: anywhere;
}

.speak {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.5rem;
  padding: 0.35rem 0.85rem;
  border: 2px solid var(--rule-strong);
  border-radius: 999px;
  background: var(--paper);
  color: var(--pen);
  font: 700 0.95rem/1 var(--text);
  cursor: pointer;
}

.speak svg {
  width: 1.15rem;
  height: 1.15rem;
}

.speak:hover,
.speak.is-speaking {
  border-color: var(--pen);
  background: var(--pen-tint);
}

.card-prompt .speak {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
}

/* Den vikta delen av papperet fälls ner när man har svarat */
.fold {
  padding: 1rem 1.25rem 1.1rem 3rem;
  border-top: 2px dashed var(--rule-strong);
  background: var(--paper-fold);
  opacity: 0;
  transform: rotateX(-90deg);
  transform-origin: top center;
  transition: transform 0.5s cubic-bezier(0.2, 0.9, 0.25, 1.05), opacity 0.2s ease;
}

.fold:empty {
  display: none;
}

.fold.open {
  opacity: 1;
  transform: none;
}

.fold p {
  margin: 0 0 0.4rem;
}

.verdict {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font: 700 1.75rem/1.2 var(--hand);
}

.verdict svg {
  width: 1.6rem;
  height: 1.6rem;
  stroke-width: 3;
}

.verdict.ok {
  color: var(--green);
}

.verdict.bad {
  color: var(--red);
}

.right-answer {
  font-size: 1.1rem;
}

.ans {
  font: 700 1.5rem/1.3 var(--hand);
}

.ans mark {
  padding: 0 0.04em;
  border-radius: 3px;
  background: var(--marker);
  color: var(--marker-ink);
}

.you-wrote s {
  text-decoration-color: var(--red);
  text-decoration-thickness: 2px;
}

.why {
  font-weight: 700;
}

.fold-actions {
  margin-top: 0.6rem !important;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.answer-label {
  display: block;
  margin: 0 0 0.5rem;
  color: var(--ink-soft);
  font-weight: 700;
}

.options {
  display: grid;
  gap: 0.6rem;
}

@media (min-width: 34rem) {
  .options {
    grid-template-columns: 1fr 1fr;
  }
}

.option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 3.5rem;
  padding: 0.75rem 1rem;
  border: 2px solid var(--rule-strong);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font: 400 1.2rem/1.3 var(--text);
  text-align: left;
  cursor: pointer;
}

.option:hover:not(:disabled) {
  border-color: var(--pen);
}

.option .key {
  display: grid;
  flex: none;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 6px;
  background: var(--paper-fold);
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 700;
}

@media (hover: none) {
  .option .key {
    display: none;
  }
}

.option-text {
  overflow-wrap: anywhere;
}

.option:disabled {
  cursor: default;
}

.options.answered .option:not(.is-right):not(.is-wrong) {
  opacity: 0.5;
}

.option.is-right {
  border-color: var(--green);
  background: var(--green-tint);
}

.option.is-wrong {
  border-color: var(--red);
  background: var(--red-tint);
}

.option.is-wrong .option-text {
  text-decoration: line-through;
  text-decoration-color: var(--red);
}

.spell-input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 2px solid var(--rule-strong);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font: 400 1.6rem/1.3 var(--text);
}

.spell-input:focus {
  outline: none;
  border-color: var(--pen);
  box-shadow: 0 0 0 3px var(--pen-tint);
}

.spell-input.is-right {
  border-color: var(--green);
}

.spell-input.is-wrong {
  border-color: var(--red);
}

.charpad {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.char {
  min-width: 2.75rem;
  height: 2.75rem;
  border: 2px solid var(--rule-strong);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: 400 1.2rem/1 var(--text);
  cursor: pointer;
}

.char:hover {
  border-color: var(--pen);
}

.spell-actions,
.next-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

/* ---------- Resultat ---------- */

.results {
  padding: 1.5rem 1.25rem 1.75rem;
}

/* Poängen ringas in med grön penna, som på ett rättat glosförhör */
.score {
  position: relative;
  display: inline-block;
  margin: 0.5rem 0 1.25rem 0.4rem;
  padding: 0.12em 0.55em;
  color: var(--green);
  font: 700 3.25rem/1 var(--hand);
}

.score::after {
  content: '';
  position: absolute;
  inset: -0.12em -0.2em;
  border: 3px solid currentColor;
  border-radius: 52% 46% 55% 45% / 58% 50% 52% 46%;
  transform: rotate(-5deg);
}

.results h1 {
  font: 700 2rem/1.2 var(--hand);
}

.missed-list {
  margin: 0 0 1.5rem;
  padding: 0;
  border-top: 1px solid var(--rule);
  list-style: none;
}

.missed-list li {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--rule);
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

/* ---------- Ändra glosa ---------- */

dialog {
  width: min(28rem, calc(100vw - 2rem));
  padding: 1.25rem;
  border: 0;
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(13, 19, 48, 0.5);
}

dialog label {
  display: block;
  margin-bottom: 0.85rem;
  font-weight: 700;
}

dialog input {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.6rem 0.75rem;
  border: 2px solid var(--rule-strong);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-weight: 400;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* ---------- Smala skärmar ---------- */

@media (max-width: 30rem) {
  .sheet:not(.glosbok):not(.shelf-sheet) {
    padding: 1rem;
  }

  .page-title {
    font-size: 2rem;
  }

  .title-input {
    font-size: 1.7rem;
  }

  .cell {
    padding: 0.65rem 0.5rem;
    font-size: 1.05rem;
  }

}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }

  .fold {
    transform: none;
  }
}

/* ---------- Uppläsning vid rättning och bland missade ord ---------- */

.listen-row {
  margin-top: 0.6rem !important;
}

.missed-list li {
  grid-template-columns: 1fr 1fr auto;
  align-items: center;
}

.missed-list .speak {
  min-height: 2.25rem;
  padding: 0.25rem 0.65rem;
}

@media (max-width: 30rem) {
  .missed-list .speak span {
    display: none;
  }
}
