/* Shared components: departure board, level switch, panels and tables, speaker button, exercises, score box */

/* Split-flap departure board */
.flapboard {
  background: var(--board);
  color: var(--flap-ink);
  border-radius: 16px;
  padding: 14px 16px 15px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    var(--shadow);
}
.fb-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
  font: 600 17px/1 var(--cond);
}
.fb-head span:first-child {
  color: #8b6900;
}
.fb-clock {
  font-variant-numeric: tabular-nums;
  opacity: 0.75;
}
.clock-digit {
  display: inline-block;
}
.fb-cq {
  container-type: inline-size;
}
.flaps {
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  gap: 3px;
}
.cell {
  position: relative;
  aspect-ratio: 5/8;
  perspective: 420px;
  font-family: var(--cond);
  font-weight: 600;
  font-size: calc((100cqw - (var(--n) - 1) * 3px) / var(--n) * 1.2);
}
.cell > span {
  position: absolute;
  left: 0;
  right: 0;
  height: 50%;
  overflow: hidden;
  background: var(--flap);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
/* each half has a faint gradient, like light falling on a real flap */
.cell > .t {
  top: 0;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(180deg, color-mix(in srgb, var(--flap) 88%, #fff), var(--flap));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.cell > .b {
  bottom: 0;
  border-radius: 0 0 3px 3px;
  background: linear-gradient(180deg, var(--flap), color-mix(in srgb, var(--flap) 90%, #000));
}
.cell > span > i {
  position: absolute;
  left: 0;
  right: 0;
  height: 200%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-style: normal;
  line-height: 1;
}
.cell > .t > i {
  top: 0;
}
.cell > .b > i {
  bottom: 0;
}
.cell > .lt {
  transform-origin: 50% 100%;
  z-index: 2;
}
.cell > .lb {
  transform-origin: 50% 0;
  z-index: 2;
  transform: rotateX(90deg);
}
.cell::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: calc(50% - 0.5px);
  height: 1px;
  background: rgba(22, 35, 63, 0.16);
  z-index: 3;
}
.fb-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
  font-size: 15px;
  opacity: 0.78;
}

/* Level switch (A1 / A2 / B1) and heading rows that hold it */
.line-head,
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
}
.page-head {
  margin-bottom: 0.5em;
}
.page-head h1 {
  margin: 0;
}
.lvswitch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 12px;
  background: var(--sunken);
}
.lvswitch a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 9px;
  font: 700 18px/1 var(--cond);
  text-decoration: none;
  color: var(--muted);
  transition:
    background-color 0.2s,
    color 0.2s;
}
.lvswitch a:hover {
  color: var(--text);
}
.lvswitch a[aria-current="true"] {
  background: var(--signal);
  color: var(--on-signal);
}
/* with JavaScript, a yellow pill slides to the chosen level */
.lvswitch {
  position: relative;
}
.lvswitch a {
  position: relative;
  z-index: 1;
}
.lvswitch.has-pill a[aria-current="true"] {
  background: transparent;
}
.lvswitch .pill {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 0;
  border-radius: 9px;
  background: var(--signal);
  box-shadow: 0 1px 2px rgba(22, 35, 63, 0.18);
  pointer-events: none;
}

/* Panels and grammar tables */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: var(--highlight), var(--shadow-1);
}
.panel h2 {
  margin-bottom: 12px;
}
.tbl {
  overflow-x: auto;
}
table {
  border-collapse: collapse;
  width: 100%;
  min-width: 300px;
  font-size: 16px;
}
th,
td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}
tr:last-child td {
  border-bottom: 0;
}
th {
  font-weight: 600;
  color: var(--muted);
}
@media (max-width: 480px) {
  .panel {
    padding: 18px 16px;
  }
  table {
    min-width: 0;
  }
  th,
  td {
    padding: 8px 9px;
  }
}

/* Speaker button */
.spk {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition:
    border-color 0.2s,
    background-color 0.2s;
}
.spk {
  position: relative;
  transition:
    border-color 0.2s,
    background-color 0.2s,
    scale 0.3s var(--ease-out);
}
.spk:hover {
  border-color: var(--text);
  scale: 1.06;
}
.spk:active {
  scale: 0.95;
}
/* while a sentence is read aloud, its button glows and sends out a ring */
.spk.is-playing {
  border-color: var(--signal);
  background: color-mix(in srgb, var(--signal) 20%, transparent);
}
.spk.is-playing::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 2px solid var(--signal);
  animation: ring-out 1.3s var(--ease-out) infinite;
  pointer-events: none;
}
@keyframes ring-out {
  from {
    transform: scale(1);
    opacity: 0.9;
  }
  to {
    transform: scale(1.7);
    opacity: 0;
  }
}
.spk svg {
  width: 16px;
  height: 16px;
}
.spk.big {
  width: 48px;
  height: 48px;
}
.spk.big svg {
  width: 20px;
  height: 20px;
}

/* Exercises: options, inputs, word chips, feedback */
.task {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 14px;
  box-shadow: var(--highlight), var(--shadow-1);
  transition:
    box-shadow 0.4s var(--ease-out),
    border-color 0.3s;
}
.task:hover {
  border-color: color-mix(in srgb, var(--text) 14%, var(--line));
  box-shadow: var(--highlight), var(--shadow-2);
}
.task .kind {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 6px;
}
.task .q {
  font-weight: 600;
  margin-bottom: 12px;
}
.opts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.opt {
  position: relative;
  border: 2px solid var(--line);
  background: var(--bg);
  border-radius: 10px;
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 500;
  min-height: 44px;
  transition:
    border-color 0.2s,
    background-color 0.2s,
    box-shadow 0.3s var(--ease-out),
    translate 0.3s var(--ease-out),
    scale 0.3s var(--ease-out);
}
.opt:hover:not(:disabled) {
  border-color: var(--text);
  translate: 0 -1px;
  box-shadow: var(--shadow-1);
}
.opt:active:not(:disabled) {
  translate: 0 0;
  scale: 0.97;
  transition-duration: 0.08s;
}
.opt:disabled {
  cursor: default;
}
.opt.right {
  border-color: var(--ok);
  background: var(--ok-bg);
}
/* a green tick badge pops onto the right answer */
.opt.right::after {
  content: "";
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ok)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.8 8.4l2.7 2.7L12.2 5.4' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    center / 12px no-repeat;
  box-shadow: 0 0 0 2px var(--surface);
  animation: badge-pop 0.5s var(--ease-spring) both;
}
@keyframes badge-pop {
  from {
    transform: scale(0);
  }
}
.opt.wrong {
  border-color: var(--err);
  background: var(--err-bg);
}
.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 12px;
}
input.fill,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  width: 100%;
  max-width: 320px;
  transition:
    border-color 0.2s,
    background-color 0.2s,
    box-shadow 0.35s var(--ease-out);
}
input.fill:focus,
textarea:focus {
  border-color: var(--text);
  outline: none;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--signal) 32%, transparent);
}
input.fill.is-ok {
  border-color: var(--ok);
  background: var(--ok-bg);
}
input.fill.is-no {
  border-color: var(--err);
}
textarea {
  max-width: 100%;
  min-height: 110px;
  resize: vertical;
}
.built {
  min-height: 50px;
  border: 2px dashed var(--line);
  border-radius: 10px;
  padding: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.built:empty::before {
  content: "Tap the words in order";
  color: var(--muted);
  font-size: 15px;
  padding: 6px;
}
.chip {
  border: 2px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-weight: 500;
  transition:
    border-color 0.2s,
    box-shadow 0.3s var(--ease-out);
}
.chip:hover:not(:disabled) {
  border-color: var(--text);
  box-shadow: var(--shadow-1);
}
.fb {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 16px;
}
.fb.ok {
  background: var(--ok-bg);
  color: var(--ok);
}
.fb.no {
  background: var(--err-bg);
  color: var(--err);
}
.fb.info {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
}
.fb .spk {
  display: inline-grid;
  vertical-align: middle;
  margin-left: 6px;
  width: 32px;
  height: 32px;
}

/* Score box and stamp */
.score {
  box-shadow: var(--shadow-2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  background: var(--signal);
  color: var(--on-signal);
  border-radius: 14px;
  padding: 18px 22px;
  margin: 26px 0;
}
.score strong {
  font: 700 44px/1 var(--cond);
  display: block;
  margin-bottom: 6px;
}
.score p {
  margin-bottom: 12px;
}
.stamp {
  display: inline-block;
  border: 3px solid currentColor;
  color: var(--stamp);
  font: 700 23px/1 var(--cond);
  padding: 8px 13px 6px;
  border-radius: 6px;
  transform: rotate(-10deg);
  text-align: center;
  opacity: 0.88;
  mix-blend-mode: multiply;
}
.stamp small {
  display: block;
  font: 600 12px/1.3 var(--sans);
  margin-top: 2px;
}

/* Spotlight: a soft light follows the pointer across .spot surfaces (see js/ui/effects.js) */
.spot {
  position: relative;
  isolation: isolate;
}
.spot::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s var(--ease-out);
  background: radial-gradient(
    420px circle at var(--mx, 50%) var(--my, 50%),
    var(--spot),
    transparent 62%
  );
}
.spot:hover::before {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .spk.is-playing::after,
  .opt.right::after {
    animation: none;
  }
  .btn,
  .opt,
  .spk {
    transition: none;
  }
}
