/* The tablet game. Sizes follow the shorter side of the screen (vmin) so
   the same layout works on any tablet, landscape or portrait. */
html,
body.tablet {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body.tablet {
  position: fixed;
  inset: 0;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  background:
    radial-gradient(120vmax 80vmax at 50% -20%, rgba(230, 0, 0, 0.14), transparent 60%),
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px) 0 0 / 5vmin 5vmin,
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px) 0 0 / 5vmin 5vmin,
    var(--bg);
}

body.tablet input,
body.tablet textarea {
  user-select: text;
  -webkit-user-select: text;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: max(10vmin, env(safe-area-inset-top)) max(3vmin, env(safe-area-inset-right)) max(3vmin, env(safe-area-inset-bottom))
    max(3vmin, env(safe-area-inset-left));
}

#app > section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.logo {
  position: fixed;
  z-index: 30;
  top: max(2.4vmin, env(safe-area-inset-top));
  left: max(2.4vmin, env(safe-area-inset-left));
  width: 7vmin;
  height: 7vmin;
  padding: 0;
  border: 0;
  background: none;
}

.logo img {
  display: block;
  width: 100%;
  height: 100%;
}

.event-tag {
  position: fixed;
  z-index: 30;
  top: max(4.2vmin, env(safe-area-inset-top));
  right: max(3vmin, env(safe-area-inset-right));
  font-family: var(--mono);
  font-size: 1.9vmin;
  color: var(--dim);
}

.sync-dot {
  position: fixed;
  z-index: 30;
  right: 1.2vmin;
  bottom: 1.2vmin;
  width: 1.1vmin;
  height: 1.1vmin;
  border-radius: 50%;
  background: var(--dim);
  opacity: 0.7;
}

.sync-dot[data-state='ok'] {
  background: var(--ok);
}

.sync-dot[data-state='pending'] {
  background: var(--warn);
}

.sync-dot[data-state='error'] {
  background: var(--red);
}

.tablet .term {
  border-radius: 2.4vmin;
}

.tablet .term-bar {
  gap: 1vmin;
  padding: 1.6vmin 2.2vmin;
  font-size: 1.8vmin;
}

.tablet .term-bar i {
  width: 1.4vmin;
  height: 1.4vmin;
}

.tablet .btn {
  font-size: 2.8vmin;
}

.cursor {
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  margin-left: 0.08em;
  background: var(--text);
  vertical-align: -0.15em;
  animation: blink 1s steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* Countdown bar */
.bar {
  flex: 1;
  height: 1.2vmin;
  background: var(--panel-2);
  border-radius: 1vmin;
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  background: var(--red);
  transform-origin: left center;
}

/* ---- Attract ---------------------------------------------------------- */
.attract {
  align-items: center;
  justify-content: center;
  gap: 3.5vmin;
  text-align: center;
  cursor: pointer;
}

.attract .term {
  width: min(92vw, 112vmin);
  text-align: left;
}

.attract .term-body {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 2vmin 4vmin;
  padding: 3.5vmin 4.5vmin 4vmin;
}

.attract-line {
  grid-column: 1 / -1;
  margin: 0;
  font-family: var(--mono);
  font-size: 5vmin;
  font-weight: 700;
}

.attract-sprite svg {
  display: block;
  width: 30vmin;
  height: 30vmin;
}

.attract-guess {
  margin: 0;
  font-family: var(--mono);
  font-size: 2.6vmin;
  color: var(--muted);
}

.attract-guess b {
  display: block;
  margin-top: 1vmin;
  font-family: var(--font);
  font-size: 6vmin;
  font-weight: 800;
  line-height: 1.05;
  color: var(--text);
}

.cta {
  font-size: 3.6vmin !important;
  padding: 2.6vmin 6vmin;
  box-shadow: 0 1.2vmin 4vmin rgba(230, 0, 0, 0.35);
  animation: pulse 2s ease-in-out infinite;
}

.attract-sub {
  margin: -1vmin 0 0;
  font-family: var(--mono);
  font-size: 2.2vmin;
  color: var(--dim);
}

@keyframes pulse {
  50% {
    transform: scale(1.04);
  }
}

/* ---- Questions -------------------------------------------------------- */
.q-top,
.ch-top {
  display: flex;
  align-items: center;
  gap: 2.4vmin;
  padding: 0 1vmin 2.4vmin;
}

.q-count {
  font-family: var(--mono);
  font-size: 2.6vmin;
  color: var(--muted);
  min-width: 6ch;
}

.q-stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr minmax(0, 1.5fr) 1fr;
  align-items: stretch;
  gap: 3vmin;
}

.q-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 5vmin;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 3.2vmin;
  box-shadow: 0 3vmin 7vmin rgba(0, 0, 0, 0.45);
  touch-action: none;
  cursor: grab;
  transition: transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.26s ease;
}

.q-card.dragging {
  transition: none;
  cursor: grabbing;
}

.q-card.fly-left {
  transform: translateX(-120%) rotate(-14deg) !important;
  opacity: 0;
}

.q-card.fly-right {
  transform: translateX(120%) rotate(14deg) !important;
  opacity: 0;
}

.q-card.fly-timeout {
  transform: translateY(-14%) scale(0.92) !important;
  opacity: 0;
}

.q-comment {
  margin: 0 0 2vmin;
  font-size: 2.2vmin;
  color: var(--dim);
}

.q-text {
  margin: 0;
  font-size: 7vmin;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.01em;
}

.q-hint {
  margin: 3vmin 0 0;
  font-size: 2.4vmin;
  color: var(--muted);
}

.answer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.6vmin;
  padding: 2vmin;
  border: 0.35vmin solid var(--line);
  border-radius: 3.2vmin;
  background: var(--panel);
  font-size: 4.4vmin;
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
  transition: background-color 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
}

.answer .arrow {
  order: -1;
  font-family: var(--mono);
  font-size: 6vmin;
  color: var(--red);
}

.answer.lean,
.answer.chosen {
  background: var(--red);
  border-color: var(--red);
}

.answer.lean .arrow,
.answer.chosen .arrow {
  color: #fff;
}

.answer.chosen {
  transform: scale(1.04);
}

.timed-out {
  position: absolute;
  inset: auto 0 2.4vmin;
  margin: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 2.4vmin;
  color: var(--warn);
}

@media (orientation: portrait) {
  .q-stage {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr auto;
  }
  .q-card {
    grid-column: 1 / -1;
    grid-row: 1;
  }
  .answer {
    flex-direction: row;
    min-height: 20vmin;
    grid-row: 2;
  }
  .answer.right .arrow {
    order: 1;
  }
}

/* ---- Challenges ------------------------------------------------------- */
.ch-top {
  flex-wrap: wrap;
  padding-bottom: 2vmin;
}

.ch-title {
  margin: 0;
  font-size: 5.6vmin;
  font-weight: 800;
}

.ch-hint {
  margin: 0 0 0 auto;
  font-family: var(--mono);
  font-size: 2.3vmin;
  color: var(--muted);
}

.ch-top .bar {
  flex-basis: 100%;
}

.ch-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border-radius: 3.2vmin;
  background:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px) 0 0 / 4vmin 4vmin,
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px) 0 0 / 4vmin 4vmin,
    var(--panel);
  border: 1px solid var(--line);
  touch-action: none;
}

.ch-target {
  position: absolute;
  display: grid;
  place-items: end center;
  border: 0.4vmin dashed rgba(255, 255, 255, 0.45);
  border-radius: 1.2vmin;
  font-size: 1.9vmin;
  color: var(--muted);
  padding-bottom: 1vmin;
  pointer-events: none;
}

.ch-target::before,
.ch-target::after {
  content: '';
  position: absolute;
  background: rgba(255, 255, 255, 0.35);
}

.ch-target::before {
  left: 50%;
  top: 30%;
  bottom: 30%;
  width: 0.3vmin;
  transform: translateX(-50%);
}

.ch-target::after {
  top: 50%;
  left: 30%;
  right: 30%;
  height: 0.3vmin;
  transform: translateY(-50%);
}

.ch-box {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  border-radius: 1.2vmin;
  background: var(--red);
  box-shadow: 0 1.4vmin 3vmin rgba(0, 0, 0, 0.45);
  font-size: 3vmin;
  font-weight: 700;
  color: #fff;
  touch-action: none;
  cursor: grab;
}

.ch-box.dragging {
  cursor: grabbing;
  box-shadow: 0 2.4vmin 5vmin rgba(0, 0, 0, 0.55);
}

.ch-result {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 3vmin;
  margin: 0;
  text-align: center;
  font-size: 3.6vmin;
  font-weight: 700;
  color: var(--warn);
}

.ch-count {
  position: absolute;
  right: 2.4vmin;
  top: 2vmin;
  margin: 0;
  font-size: 2.6vmin;
  color: var(--muted);
}

.bug {
  position: absolute;
  left: 0;
  top: 0;
  width: 17vmin;
  height: 17vmin;
  margin: -8.5vmin 0 0 -8.5vmin;
  padding: 2.4vmin;
  border: 0;
  background: none;
  touch-action: none;
}

.bug svg {
  display: block;
  width: 100%;
  height: 100%;
  transform: rotate(var(--turn, 0deg));
}

.bug.squashed svg {
  transform: rotate(var(--turn, 0deg)) scale(1.3, 0.35);
  opacity: 0.35;
  filter: grayscale(1);
  transition: transform 0.12s ease, opacity 0.3s ease;
}

.bug.escaped {
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* ---- Reveal ----------------------------------------------------------- */
.compile {
  align-self: center;
  margin: auto;
  width: min(80vw, 90vmin);
}

.compile .term-body {
  padding: 4vmin;
  font-family: var(--mono);
  font-size: 3vmin;
  line-height: 1.7;
  min-height: 30vmin;
}

.compile p {
  margin: 0;
}

.compile p:first-child {
  color: var(--text);
  font-weight: 700;
}

.compile p + p {
  color: var(--muted);
}

.reveal-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  justify-items: center;
  gap: 4vmin;
}

.card-wrap {
  position: relative;
  height: min(78vh, 100%);
  aspect-ratio: 4 / 5;
  animation: card-in 0.6s cubic-bezier(0.2, 0.9, 0.25, 1.15) both;
}

.card-wrap svg {
  width: 100%;
  height: 100%;
  border-radius: 3.6%;
  box-shadow: 0 3vmin 8vmin rgba(0, 0, 0, 0.6), 0 0 0 0.3vmin rgba(255, 255, 255, 0.06);
}

.levelup {
  position: absolute;
  top: -5.5vmin;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 3.4vmin;
  letter-spacing: 0.4em;
  color: var(--warn);
  white-space: nowrap;
  animation: levelup 1.6s ease both;
}

@keyframes card-in {
  from {
    transform: translateY(6%) scale(0.86);
    opacity: 0;
  }
}

@keyframes levelup {
  0% {
    opacity: 0;
    transform: translate(-50%, 1vmin) scale(0.8);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1.08);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}

.keep {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.2vmin;
  max-width: 58vmin;
  text-align: center;
}

.keep h2 {
  margin: 0;
  font-size: 5vmin;
  font-weight: 800;
}

.qr {
  width: 30vmin;
  padding: 1.4vmin;
  border-radius: 2vmin;
  background: #fff;
}

.qr svg {
  display: block;
  width: 100%;
  height: auto;
}

.keep-title {
  margin: 0;
  font-size: 3vmin;
  font-weight: 700;
}

.keep-sub {
  margin: -1vmin 0 0;
  font-size: 2.2vmin;
  color: var(--muted);
}

.keep-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2vmin;
  margin-top: 1vmin;
}

@media (orientation: portrait) {
  .reveal-grid {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .card-wrap {
    height: 100%;
    max-height: 62vh;
    max-width: 86vw;
  }
  .keep {
    max-width: none;
    display: grid;
    grid-template-columns: auto auto;
    grid-template-areas: 'qr title' 'qr sub' 'qr actions';
    align-items: center;
    text-align: left;
    gap: 0.6vmin 3vmin;
  }
  .keep h2 {
    display: none;
  }
  .qr {
    grid-area: qr;
    width: 24vmin;
  }
  .keep-title {
    grid-area: title;
  }
  .keep-sub {
    grid-area: sub;
    margin: 0;
  }
  .keep-actions {
    grid-area: actions;
    justify-content: flex-start;
  }
}

/* ---- git commit form -------------------------------------------------- */
.commit {
  align-items: center;
}

.commit .term {
  width: min(94vw, 120vmin);
}

.commit .term-body {
  padding: 3vmin 4vmin 3.4vmin;
  font-family: var(--mono);
  font-size: 2.7vmin;
}

.git-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 0.6ch;
  margin: 0 0 1.4vmin;
  white-space: nowrap;
}

.git-line input {
  flex: 1;
  min-width: 16ch;
  padding: 0.6vmin 0.4ch;
  border: 0;
  border-bottom: 0.3vmin solid var(--line);
  border-radius: 0;
  background: transparent;
  outline: none;
  font-family: var(--mono);
  font-size: 3vmin;
  color: var(--warn);
}

.git-line input:focus {
  border-bottom-color: var(--red);
}

.git-line input::placeholder {
  color: #565b60;
}

.field-error {
  margin: -0.6vmin 0 1.4vmin 2.2ch;
  font-family: var(--font);
  font-size: 2.3vmin;
  color: #ff6b6b;
}

.opt {
  display: flex;
  align-items: flex-start;
  gap: 1.6vmin;
  margin: 2.2vmin 0 1.4vmin;
  font-family: var(--font);
  font-size: 2.7vmin;
  color: var(--soft);
}

.opt input {
  flex: none;
  width: 3.6vmin;
  height: 3.6vmin;
  margin: 0;
  accent-color: var(--red);
}

.privacy {
  margin: 0 0 2.6vmin;
  font-family: var(--font);
  font-size: 2vmin;
  line-height: 1.4;
  color: var(--dim);
  white-space: normal;
}

.commit-actions {
  display: flex;
  gap: 2vmin;
  flex-wrap: wrap;
}

.commit-actions .btn-red {
  font-family: var(--mono);
  font-size: 2.6vmin;
}

.committed .term-body {
  font-size: 3.2vmin;
  line-height: 1.6;
}

.committed .ok {
  color: var(--ok);
}

/* ---- Hidden menu -------------------------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.75);
}

.menu {
  width: min(92vw, 90vmin);
  max-height: 92vh;
  overflow: auto;
  padding: 4vmin;
  border-radius: 2.4vmin;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 2.6vmin;
}

.menu h2 {
  margin: 0 0 2vmin;
  font-size: 3.4vmin;
}

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2vmin;
  padding: 1.6vmin 0;
  border-bottom: 1px solid var(--line);
}

.menu-row input {
  flex: 1;
  min-width: 0;
  padding: 1.2vmin 1.6vmin;
  border: 1px solid var(--line);
  border-radius: 1vmin;
  background: var(--bg);
}

.menu .btn {
  font-size: 2.4vmin;
  padding: 1.4vmin 2.6vmin;
}

.menu-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 2vmin;
  margin-top: 3vmin;
}

.seg {
  display: inline-flex;
  border-radius: 999px;
  box-shadow: inset 0 0 0 2px var(--line);
}

.seg button {
  padding: 1.2vmin 2.8vmin;
  border: 0;
  border-radius: 999px;
  background: none;
  font-weight: 700;
}

.seg button[aria-pressed='true'] {
  background: var(--red);
}

.pinpad {
  width: min(70vw, 56vmin);
  padding: 4vmin;
  border-radius: 2.4vmin;
  background: var(--panel);
  text-align: center;
}

.pin-title {
  margin: 0 0 2vmin;
  font-size: 2.6vmin;
  color: var(--muted);
}

.menu-note {
  margin: 0;
  padding: 1vmin 0 1.6vmin;
  font-size: 2.2vmin;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.pin-dots {
  margin: 0 0 3vmin;
  font-family: var(--mono);
  font-size: 5vmin;
  letter-spacing: 0.4em;
}

.pin-keys {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2vmin;
}

.pin-keys button {
  padding: 2.4vmin 0;
  border: 0;
  border-radius: 1.6vmin;
  background: var(--panel-2);
  font-size: 3.6vmin;
  font-weight: 700;
}

.shake {
  animation: shake 0.3s ease;
}

@keyframes shake {
  25% {
    transform: translateX(-2vmin);
  }
  75% {
    transform: translateX(2vmin);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cta,
  .cursor,
  .card-wrap,
  .levelup {
    animation: none;
  }
  .q-card,
  .answer {
    transition: none;
  }
}
