/* Entrelinhas: interface em risografia. Ver DESIGN.md. */

/* ---------- Fontes (hospedadas no app) ---------- */

@font-face {
  font-family: "Anybody";
  src: url("fonts/anybody-latin.woff2") format("woff2");
  font-weight: 400 900;
  font-stretch: 50% 150%;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("fonts/atkinson-next-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- Tokens ---------- */

:root {
  --paper: #ebebe6;
  --card: #f7f7f4;
  --text: #262624;
  --muted: #5d5d58;
  --rule: #cfcfc8;
  --ink: #262624;
  --on-ink: #f7f7f4;

  --display: "Anybody", "Arial Narrow", sans-serif;
  --body: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, sans-serif;

  --gutter: 16px;
  --card-w: min(80vw, 340px);
  --ease: cubic-bezier(0.25, 0.8, 0.25, 1);

  /* Ruído de papel, desenhado uma vez em SVG. */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1e1e1c;
    --text: #e9e9e4;
    --muted: #a6a69f;
    --rule: #3a3a36;
    color-scheme: dark;
  }
}

/* Marcas da tinta impressas sobre papel claro: escurecidas para que tintas
   claras (amarelo, girassol) continuem visíveis. Calculado onde --ink é definido. */
body,
dialog,
.box {
  --ink-deep: color-mix(in oklab, var(--ink) 62%, #000);
}

/* ---------- Base ---------- */

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

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

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--text);
  font-family: var(--body);
  font-size: 1.0625rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Textura de papel sobre tudo. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  background-image: var(--grain);
  opacity: 0.16;
  mix-blend-mode: multiply;
}

/* Dentro de um baralho, a página inteira é a mesa pintada com a tinta. */
body[data-view="deck"] {
  background: var(--ink);
  color: var(--on-ink);
}

main {
  flex: 1;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) var(--gutter) 48px;
  outline: none;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
}

svg {
  display: block;
}

:focus-visible {
  outline: 3px solid currentColor;
  outline-offset: 3px;
}

main:focus-visible {
  outline: none;
}

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

.skip {
  position: absolute;
  left: var(--gutter);
  top: -100px;
  z-index: 40;
  padding: 8px 14px;
  background: var(--text);
  color: var(--paper);
}

.skip:focus {
  top: 12px;
}

/* ---------- Botões e links ---------- */

.text-button,
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 5px;
  cursor: pointer;
}

.back-link {
  text-decoration: none;
}

.back-link svg,
.icon-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.solid-button {
  min-height: 52px;
  padding: 0 26px;
  border: 0;
  border-radius: 6px;
  background: var(--text);
  color: var(--paper);
  font-weight: 700;
  font-size: 1.0625rem;
  cursor: pointer;
}

.solid-button:active {
  transform: translateY(1px);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-right: -10px;
  border: 0;
  background: none;
  cursor: pointer;
}

.outline-button {
  min-height: 44px;
  padding: 0 18px;
  border: 2px solid currentColor;
  border-radius: 6px;
  background: none;
  font-weight: 700;
  cursor: pointer;
}

/* ---------- Início ---------- */

.home {
  display: grid;
  gap: 36px;
}

.masthead .text-button {
  white-space: nowrap;
}

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  font-family: var(--display);
  font-weight: 800;
  font-stretch: 140%;
  font-size: clamp(1.9rem, 1.2rem + 3vw, 2.6rem);
  line-height: 1;
  letter-spacing: -0.02em;
}

.intro {
  margin-top: 14px;
  max-width: 30rem;
  font-size: 1.125rem;
  line-height: 1.45;
}

.intro + .intro {
  margin-top: 10px;
  color: var(--muted);
  font-size: 1rem;
}

@media (min-width: 900px) {
  .home {
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 64px;
    padding-top: 24px;
  }

  .home-side {
    position: sticky;
    top: 40px;
    align-self: start;
  }

  .masthead {
    flex-direction: column;
    gap: 0;
  }

  .masthead .text-button {
    order: 3;
    margin-top: 20px;
  }

  .brand {
    font-size: 2.35rem;
    font-stretch: 125%;
  }
}

.shelf + .shelf {
  margin-top: 32px;
}

.shelf-title {
  margin-bottom: 10px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
}

.shelf-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

/* Cada baralho é uma caixa vista de lado, pintada com a tinta dele. */
.box {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 4px 16px;
  min-height: 92px;
  padding: 16px 18px 14px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--on-ink);
  text-decoration: none;
  overflow: hidden;
  transition: transform 220ms var(--ease);
}

.box::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--grain);
  opacity: 0.22;
  mix-blend-mode: multiply;
  pointer-events: none;
}

.box:hover,
.box:focus-visible {
  transform: translateX(10px);
}

.box:focus-visible {
  outline-color: var(--text);
}

.box-name {
  grid-column: 1;
  font-family: var(--display);
  font-weight: 800;
  font-stretch: 125%;
  font-size: clamp(1.55rem, 1.1rem + 2vw, 2.1rem);
  line-height: 1;
  letter-spacing: -0.015em;
}

.box-tagline {
  grid-column: 1;
  font-size: 0.9375rem;
  line-height: 1.35;
}

.box-count {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: start;
  font-size: 0.9375rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- Baralho ---------- */

.deck-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.deck-layout {
  display: grid;
  grid-template-areas: "title" "table" "info";
  gap: 28px;
}

.deck-title {
  grid-area: title;
  font-family: var(--display);
  font-weight: 800;
  font-stretch: 150%;
  font-size: clamp(2.4rem, 1.2rem + 6vw, 4.75rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
  overflow-wrap: anywhere;
}

.deck-info {
  grid-area: info;
  max-width: 34rem;
}

.deck-layout > .table {
  grid-area: table;
}

@media (min-width: 900px) {
  .deck-layout {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto 1fr;
    grid-template-areas: "title table" "info table";
    column-gap: 72px;
    row-gap: 24px;
    min-height: calc(100dvh - 160px);
  }

  .deck-title {
    align-self: end;
  }

  .deck-layout > .table {
    align-self: center;
  }
}

.deck-about {
  line-height: 1.55;
}

.deck-note {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 2px solid currentColor;
  font-weight: 700;
  line-height: 1.5;
}

.refs {
  margin-top: 18px;
  font-size: 0.9375rem;
}

.refs summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.refs summary::-webkit-details-marker {
  display: none;
}

.refs summary::after {
  content: "+";
  font-size: 1.25rem;
  line-height: 1;
}

.refs[open] summary::after {
  content: "–";
}

.refs ul {
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
  line-height: 1.4;
}

/* Mesa: pilha de folhas, a carta por cima e as ações embaixo. */
.table {
  display: grid;
  justify-items: center;
  gap: 24px;
}

.table > .pile,
.table > .card {
  grid-area: 1 / 1;
}

.pile {
  position: relative;
  width: var(--card-w);
  aspect-ratio: 5 / 7;
}

.pile span {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.08);
}

.pile span:nth-child(1) {
  transform: translate(7px, 6px) rotate(3.5deg);
  filter: brightness(0.9);
}

.pile span:nth-child(2) {
  transform: translate(-4px, 4px) rotate(-2deg);
  filter: brightness(0.95);
}

.card {
  --tilt: 0deg;
  position: relative;
  width: var(--card-w);
  aspect-ratio: 5 / 7;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: none;
  color: #262624; /* a carta é papel claro também no modo escuro */
  perspective: 1400px;
  cursor: pointer;
  transform: rotate(var(--tilt));
  transition: transform 520ms var(--ease);
}

.card.is-flipped {
  cursor: default;
}

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 520ms var(--ease);
}

.card.is-flipped .card-inner {
  transform: rotateY(180deg);
}

.card:not(.is-flipped):hover .card-inner {
  transform: translateY(-6px);
}

.card-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 12px;
  background: var(--card);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.08);
}

.card-face::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--grain);
  opacity: 0.18;
  mix-blend-mode: multiply;
  pointer-events: none;
}

/* Verso: o nome do baralho impresso na lombada. O bloco de tinta fica um
   pouco fora do centro, como um registro desalinhado de risografia. */
.card-back {
  display: grid;
  grid-template-rows: 1fr auto;
  padding: 14px;
}

.back-spine {
  position: relative;
  overflow: hidden;
  border-radius: 3px;
  background: var(--ink);
  transform: translate(2px, -1px) rotate(0.4deg);
}

.back-spine span {
  position: absolute;
  left: 50%;
  top: 50%;
  font-family: var(--display);
  font-weight: 900;
  font-stretch: 62%;
  /* Quanto mais curto o nome, maior a letra, até ocupar a lombada. */
  font-size: min(calc(var(--card-w) * 1.25 / (var(--len) * 0.5)), calc(var(--card-w) * 0.58));
  line-height: 0.82;
  white-space: nowrap;
  letter-spacing: -0.01em;
  color: var(--card);
  transform: translate(-50%, -50%) rotate(-90deg);
}

.back-foot {
  display: flex;
  justify-content: space-between;
  padding: 12px 4px 0;
  font-size: 0.875rem;
  font-weight: 700;
}

/* Frente: papel com a pergunta. */
.card-front {
  transform: rotateY(180deg);
  display: flex;
  flex-direction: column;
  padding: 22px 22px 18px;
  text-align: left;
}

.front-kind {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9375rem;
  font-weight: 700;
}

.front-kind .kind-glyph {
  color: var(--ink-deep);
}

.front-text {
  flex: 1;
  display: flex;
  align-items: center;
  font-size: clamp(1.3rem, 1.05rem + 1.4vw, 1.55rem);
  font-weight: 500;
  line-height: 1.32;
  text-wrap: pretty;
}

.front-text.is-long {
  font-size: clamp(1.12rem, 0.98rem + 0.9vw, 1.3rem);
}

.front-hint {
  font-size: 0.875rem;
  line-height: 1.4;
  color: #5d5d58;
}

.front-source {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 2px solid var(--ink-deep);
  font-size: 0.8125rem;
  line-height: 1.35;
  color: #5d5d58;
}

.table-actions {
  grid-area: 2 / 1;
  display: grid;
  justify-items: center;
  gap: 12px;
  text-align: center;
}

.table-actions .solid-button {
  background: var(--card);
  color: #262624;
}

.table-count {
  font-size: 0.9375rem;
}

/* Glifos dos tipos de carta: a forma diz o tipo, sem depender da cor. */
.kind-glyph {
  display: inline-block;
  flex: none;
  width: 13px;
  height: 13px;
  border: 2.5px solid currentColor;
  border-radius: 50%;
}

.kind-glyph[data-kind="r"] {
  background: linear-gradient(90deg, currentColor 50%, transparent 50%);
}

.kind-glyph[data-kind="x"] {
  border-radius: 1px;
  background: currentColor;
  transform: rotate(45deg) scale(0.82);
}

/* ---------- Diálogos ---------- */

.sheet-dialog {
  width: min(560px, 100vw);
  max-height: min(86dvh, 760px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 12px 12px 0 0;
  background: var(--paper);
  color: var(--text);
}

@media (min-width: 640px) {
  .sheet-dialog {
    margin: auto;
    border-radius: 12px;
  }
}

.sheet-dialog[open] {
  display: flex;
  flex-direction: column;
  animation: sheet-in 260ms var(--ease);
}

.sheet-dialog::backdrop {
  background: rgb(20 20 18 / 0.55);
}

@keyframes sheet-in {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 24px 6px;
}

.dialog-head h2 {
  font-family: var(--display);
  font-weight: 800;
  font-stretch: 120%;
  font-size: 1.4rem;
  line-height: 1.1;
}

.dialog-body {
  overflow-y: auto;
  padding: 8px 24px max(28px, env(safe-area-inset-bottom));
}

.prose p + p,
.prose p + ul,
.prose ul + p {
  margin-top: 12px;
}

.kind-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.kind-list li {
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: baseline;
}

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

.history-item {
  display: grid;
  gap: 4px;
  padding: 14px 0;
  border-bottom: 1px solid var(--rule);
}

.history-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  font-weight: 700;
}

.history-meta .kind-glyph {
  color: var(--ink-deep);
}

@media (prefers-color-scheme: dark) {
  .history-meta .kind-glyph {
    color: var(--ink);
  }
}

.history-meta time {
  margin-left: auto;
  font-weight: 400;
  color: var(--muted);
}

.history-text {
  line-height: 1.45;
}

.reset {
  display: grid;
  justify-items: start;
  gap: 12px;
  margin-top: 28px;
  font-size: 0.9375rem;
  color: var(--muted);
}

.reset .outline-button {
  color: var(--text);
}

.reset .outline-button[data-confirm] {
  border-color: var(--text);
  background: var(--text);
  color: var(--paper);
}

.empty {
  color: var(--muted);
}

.install {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 2px solid var(--text);
  display: grid;
  justify-items: start;
  gap: 10px;
}

.install h3 {
  font-family: var(--display);
  font-weight: 800;
  font-stretch: 120%;
  font-size: 1.15rem;
}

.install-ios,
.version {
  font-size: 0.9375rem;
  color: var(--muted);
}

.version {
  margin-top: 20px;
}

/* ---------- Rodapé ---------- */

.site-footer {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px var(--gutter) max(28px, env(safe-area-inset-bottom));
  font-size: 0.875rem;
  line-height: 1.5;
}

body[data-view="home"] .site-footer {
  color: var(--muted);
}

.site-footer p {
  max-width: 40rem;
}

.site-footer p + p {
  margin-top: 6px;
}

.site-footer a {
  font-weight: 700;
  color: inherit;
}

/* ---------- Aviso de atualização ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 20;
  width: min(calc(100vw - 32px), 420px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 10px 10px 18px;
  border-radius: 6px;
  background: #262624;
  color: #f7f7f4;
  font-weight: 700;
  animation: sheet-in 260ms var(--ease);
}

.toast[hidden] {
  display: none;
}

.toast-button {
  flex: none;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 4px;
  background: #f7f7f4;
  color: #262624;
  font-weight: 700;
  cursor: pointer;
}

/* ---------- Movimento reduzido ---------- */

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