/* ══════════════════════════════════════════════════════════════
   chessmate — korespondenční šachy
   papír · inkoust · pečetní vosk
   ══════════════════════════════════════════════════════════════ */

:root {
  --paper:       #F3ECDD;
  --paper-deep:  #E9DEC6;
  --card:        #FBF6EA;
  --ink:         #2A2119;
  --ink-soft:    #6E5F4B;
  --ink-faint:   rgba(42, 33, 25, .38);
  --wax:         #8F2430;
  --wax-deep:    #6B1822;
  --brass:       #A8842F;
  --board-light: #EFE2C0;
  --board-dark:  #A57D4E;
  --hl:          rgba(168, 132, 47, .42);
  --sel:         rgba(143, 36, 48, .55);
  --radius:      14px;
  --shadow-card: 0 1px 3px rgba(42,33,25,.10), 0 10px 28px -14px rgba(42,33,25,.30);
  --serif-disp:  'Fraunces', 'Georgia', serif;
  --serif-body:  'Literata', 'Georgia', serif;
  --mono:        'Courier Prime', 'Courier New', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* atribut hidden musí vyhrát i nad display:flex */
[hidden] { display: none !important; }

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

body {
  font-family: var(--serif-body);
  color: var(--ink);
  background-color: var(--paper);
  /* zrno papíru */
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.16 0 0 0 0 0.13 0 0 0 0 0.10 0 0 0 0.045 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
  min-height: 100dvh;
  line-height: 1.55;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 14px calc(28px + env(safe-area-inset-bottom));
}

/* ─── Hlavička ─── */

.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 2px 14px;
}

.wordmark {
  font-family: var(--serif-disp);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: baseline;
}
.wordmark em { font-style: normal; color: var(--wax); }
.seal-dot {
  width: 8px; height: 8px;
  margin-left: 4px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #B03642, var(--wax-deep));
  align-self: center;
  box-shadow: 0 1px 2px rgba(42,33,25,.35);
}

.chip {
  font-family: var(--mono);
  font-size: 12.5px;
  letter-spacing: .02em;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--ink-faint);
  color: var(--ink-soft);
  white-space: nowrap;
}
.chip.my-turn {
  border-color: var(--wax);
  background: var(--wax);
  color: var(--card);
  box-shadow: 0 2px 8px -2px rgba(143,36,48,.5);
}
.chip.over { border-style: dashed; }

/* ─── Domů / hero ─── */

.hero { text-align: center; padding: 22px 0 26px; }
.hero-knight img {
  width: 56px; height: 56px;
  opacity: .85;
  transform: rotate(-7deg);
}
.hero h1 {
  font-family: var(--serif-disp);
  font-weight: 600;
  font-size: clamp(40px, 11vw, 52px);
  letter-spacing: -0.02em;
  line-height: 1.05;
}
.hero h1 em { font-style: normal; color: var(--wax); }
.tagline {
  font-family: var(--serif-disp);
  font-style: italic;
  font-weight: 500;
  font-size: 19px;
  color: var(--ink-soft);
  margin-top: 6px;
}
.sub {
  font-size: 14.5px;
  color: var(--ink-soft);
  margin-top: 14px;
}

/* postupné objevení při načtení */
.hero > * , .form-card, #mygames {
  animation: rise .55s cubic-bezier(.2,.7,.2,1) backwards;
}
.hero > :nth-child(1) { animation-delay: .05s }
.hero > :nth-child(2) { animation-delay: .12s }
.hero > :nth-child(3) { animation-delay: .2s }
.hero > :nth-child(4) { animation-delay: .28s }
.form-card { animation-delay: .36s }
#mygames { animation-delay: .44s }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* ─── Karty ─── */

.card {
  background: var(--card);
  border: 1px solid rgba(42,33,25,.09);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 20px 18px;
  margin-bottom: 18px;
}
.card h2 {
  font-family: var(--serif-disp);
  font-weight: 600;
  font-size: 20px;
  margin-bottom: 14px;
}

/* ─── Formulář ─── */

form label {
  display: block;
  font-size: 13.5px;
  color: var(--ink-soft);
  margin-bottom: 12px;
}
form input[type="text"], form input:not([type]) {
  display: block;
  width: 100%;
  margin-top: 4px;
  font-family: var(--serif-body);
  font-size: 17px;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1.5px solid var(--ink-faint);
  border-radius: 0;
  padding: 6px 2px;
  outline: none;
}
form input:focus { border-bottom-color: var(--wax); }

.color-toggle {
  border: none;
  display: flex;
  gap: 10px;
  margin: 16px 0 18px;
}
.color-toggle legend {
  font-size: 13.5px;
  color: var(--ink-soft);
  margin-bottom: 8px;
}
.color-toggle label {
  flex: 1;
  margin: 0;
  cursor: pointer;
}
.color-toggle input { position: absolute; opacity: 0; }
.color-toggle span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-family: var(--serif-body);
  font-size: 15.5px;
  color: var(--ink);
  padding: 10px 8px;
  border: 1.5px solid var(--ink-faint);
  border-radius: 10px;
  transition: border-color .15s, background-color .15s, box-shadow .15s;
}
.color-toggle input:checked + span {
  border-color: var(--wax);
  background: rgba(143,36,48,.06);
  box-shadow: inset 0 0 0 1px var(--wax);
}
.color-toggle input:focus-visible + span { outline: 2px solid var(--brass); outline-offset: 2px; }

/* ─── Tlačítka ─── */

.btn-wax, .btn-ink, .btn-ghost, .btn-quiet {
  font-family: var(--serif-body);
  font-size: 16px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: transform .12s, box-shadow .15s, background-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-wax {
  display: block;
  width: 100%;
  padding: 13px 20px;
  border: none;
  color: #FBF3E4;
  background: linear-gradient(160deg, #A12B38, var(--wax) 55%, var(--wax-deep));
  box-shadow: 0 3px 10px -3px rgba(107,24,34,.55), inset 0 1px 0 rgba(255,255,255,.18);
  font-weight: 600;
  letter-spacing: .01em;
}
.btn-wax:active { transform: scale(.97); }
.btn-wax:disabled { opacity: .55; cursor: default; transform: none; }

.btn-ink {
  display: inline-block;
  padding: 11px 20px;
  border: none;
  background: var(--ink);
  color: var(--card);
  font-weight: 600;
}
.btn-ink:active { transform: scale(.97); }

.btn-ghost {
  display: inline-block;
  background: transparent;
  border: 1.5px solid var(--ink-faint);
  color: var(--ink-soft);
  padding: 10px 18px;
}
.btn-ghost.small { font-size: 13.5px; padding: 5px 12px; }
.btn-ghost:active { transform: scale(.97); }

.btn-quiet {
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 14px;
  padding: 8px 12px;
}

/* pečeť na odesílacím tlačítku */
.btn-seal {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.btn-seal .seal {
  width: 20px; height: 20px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255,255,255,.35), transparent 45%),
    radial-gradient(circle at 60% 65%, var(--wax-deep), #57121A);
  box-shadow: inset 0 0 0 2.5px rgba(251,243,228,.55);
  flex: none;
}
.btn-seal:active .seal { transform: scale(1.25) rotate(-8deg); transition: transform .1s; }

/* ─── Sdílení odkazů ─── */

.share-note { font-size: 14.5px; color: var(--ink-soft); margin-bottom: 10px; }
.share-note.small { font-size: 13px; }
.share-row {
  background: var(--paper);
  border: 1px dashed var(--ink-faint);
  border-radius: 8px;
  padding: 9px 11px;
  margin-bottom: 10px;
  overflow-x: auto;
}
.share-row code {
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: nowrap;
  color: var(--ink);
}
.share-actions { display: flex; gap: 10px; margin-bottom: 4px; }
.share-actions > * { flex: 1; }
.rule {
  border: none;
  border-top: 1px solid rgba(42,33,25,.12);
  margin: 18px 0 14px;
}

/* ─── Seznam partií ─── */

#mygames { margin-top: 26px; }
.feed-title {
  font-family: var(--serif-disp);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 10px;
  padding-left: 4px;
}
#mygames-list { list-style: none; }
#mygames-list a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  background: var(--card);
  border: 1px solid rgba(42,33,25,.09);
  border-radius: 10px;
  box-shadow: var(--shadow-card);
  padding: 12px 14px;
  margin-bottom: 8px;
  text-decoration: none;
  color: var(--ink);
  font-size: 15.5px;
}
#mygames-list .when {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-faint);
  white-space: nowrap;
}

/* ─── Šachovnice ─── */

.board-frame {
  background: var(--card);
  border: 1px solid rgba(42,33,25,.12);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 10px;
  margin: 2px auto 12px;
  max-width: 500px;
}

#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  overflow: hidden;
  touch-action: manipulation;
}

.sq {
  position: relative;
  border: none;
  padding: 0;
  background: var(--board-light);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sq.dark { background: var(--board-dark); }
.sq:focus-visible { outline: 2px solid var(--brass); outline-offset: -2px; z-index: 1; }

.sq .piece {
  width: 88%;
  height: 88%;
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgba(42,33,25,.25));
}

/* souřadnice */
.sq .coord {
  position: absolute;
  font-family: var(--mono);
  font-size: 9px;
  line-height: 1;
  pointer-events: none;
  opacity: .7;
}
.sq .coord.file { right: 3px; bottom: 2px; }
.sq .coord.rank { left: 3px; top: 2px; }
.sq .coord      { color: var(--board-dark); }
.sq.dark .coord { color: var(--board-light); }

/* stavové vrstvy polí */
.sq.last::before {
  content: '';
  position: absolute; inset: 0;
  background: var(--hl);
}
.sq.selected::before {
  content: '';
  position: absolute; inset: 0;
  box-shadow: inset 0 0 0 3px var(--sel);
}
.sq.target::after {
  content: '';
  position: absolute;
  width: 26%; height: 26%;
  border-radius: 50%;
  background: rgba(42,33,25,.28);
}
.sq.target.capture::after {
  width: 88%; height: 88%;
  background: none;
  border: 3.5px solid rgba(143,36,48,.6);
}
.sq.check {
  background-image: radial-gradient(circle, rgba(143,36,48,.65) 0%, rgba(143,36,48,.25) 55%, transparent 75%);
}
.sq.staged-to::before {
  content: '';
  position: absolute; inset: 0;
  box-shadow: inset 0 0 0 3px var(--brass);
}

/* ─── Stavy partie ─── */

.banner {
  font-family: var(--serif-disp);
  font-size: 17px;
  text-align: center;
  background: var(--ink);
  color: var(--card);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 12px;
  animation: rise .4s cubic-bezier(.2,.7,.2,1) backwards;
}
.banner.win { background: linear-gradient(160deg, #A12B38, var(--wax-deep)); }

.hint {
  font-size: 14px;
  font-style: italic;
  color: var(--ink-soft);
  text-align: center;
  padding: 4px 10px 10px;
}

.viewbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-soft);
  padding: 2px 0 10px;
}
.viewbar button {
  background: none;
  border: 1.5px solid var(--ink-faint);
  border-radius: 8px;
  color: var(--ink);
  font-size: 16px;
  line-height: 1;
  padding: 4px 12px;
  cursor: pointer;
}

/* ─── Psaní dopisu ─── */

.compose {
  background: var(--card);
  border: 1px solid rgba(42,33,25,.09);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 14px 16px 16px;
  margin-bottom: 18px;
  animation: rise .35s cubic-bezier(.2,.7,.2,1) backwards;
}
.compose-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.compose-move { font-size: 14.5px; color: var(--ink-soft); }
.compose-move b {
  font-family: var(--mono);
  font-size: 16px;
  color: var(--ink);
}

#message {
  display: block;
  width: 100%;
  font-family: var(--serif-body);
  font-size: 16px;
  color: var(--ink);
  background:
    repeating-linear-gradient(
      transparent, transparent 27px,
      rgba(42,33,25,.14) 27px, rgba(42,33,25,.14) 28px
    );
  line-height: 28px;
  border: none;
  outline: none;
  resize: vertical;
  min-height: 86px;
  margin-bottom: 14px;
  padding: 0 2px;
}
#message::placeholder { color: var(--ink-faint); font-style: italic; }

/* ─── Dopisy ─── */

.letters { padding: 4px 0 6px; }

.letter {
  background: var(--card);
  border: 1px solid rgba(42,33,25,.09);
  border-radius: 4px 14px 14px 14px;
  box-shadow: var(--shadow-card);
  padding: 12px 15px 10px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: box-shadow .15s;
}
.letter:nth-child(odd)  { transform: rotate(-.35deg); }
.letter:nth-child(even) { transform: rotate(.3deg); }
.letter.mine {
  background: var(--paper-deep);
  border-radius: 14px 4px 14px 14px;
}
.letter.new { animation: arrive .6s cubic-bezier(.2,.7,.2,1) backwards; }
@keyframes arrive {
  from { opacity: 0; transform: translateY(-12px) rotate(1.2deg); }
}
.letter.viewing { box-shadow: 0 0 0 2px var(--brass), var(--shadow-card); }

.letter-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
.letter-move {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 15px;
}
.letter-when {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-faint);
  white-space: nowrap;
}
.letter-body {
  font-size: 15.5px;
  line-height: 1.6;
  margin: 6px 0 2px;
  white-space: pre-wrap;
  word-break: break-word;
}
.letter-sign {
  font-family: var(--serif-disp);
  font-style: italic;
  font-size: 14px;
  color: var(--ink-soft);
  text-align: right;
}
.letter.slim { padding: 8px 15px; }
.letter.slim .letter-sign { display: none; }

.letters-empty {
  text-align: center;
  font-style: italic;
  color: var(--ink-soft);
  font-size: 14.5px;
  padding: 18px 10px;
}

.game-foot { text-align: center; padding: 8px 0 4px; }

/* ─── Proměna pěšce ─── */

.promo-overlay {
  position: fixed; inset: 0;
  background: rgba(42,33,25,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.promo-box {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 18px 20px;
  text-align: center;
}
.promo-box p {
  font-family: var(--serif-disp);
  font-size: 16px;
  margin-bottom: 12px;
}
.promo-pieces { display: flex; gap: 8px; }
.promo-pieces button {
  background: var(--paper);
  border: 1.5px solid var(--ink-faint);
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
}
.promo-pieces img { width: 44px; height: 44px; display: block; }

/* ─── Toast ─── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--card);
  font-size: 14.5px;
  border-radius: 999px;
  padding: 10px 20px;
  box-shadow: 0 6px 24px -6px rgba(42,33,25,.5);
  z-index: 60;
  max-width: 90vw;
  text-align: center;
  animation: rise .25s backwards;
}

/* ─── Drobnosti ─── */

@media (min-width: 561px) {
  .top { padding-top: 14px; }
}

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