@import url("../fonts/fonts.css");

:root {
  --white: #ffffff;
  --sand: #dbad7d;
  --sand-soft: #f6ece1;
  --ink: #2b2a28;          /* fakó fekete */
  --ink-soft: #4a4844;
  --muted: #8a857e;
  --line: #ece7e0;
  --surface: #faf7f3;
  --s: min(25vw, 96px, 12.5svh);
  --display: "League Spartan", "Avenir Next", system-ui, sans-serif;
  --body: "Montserrat", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--white);
  color: var(--ink);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }

.app {
  min-height: 100svh;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 14px) 16px 0;
}

/* ---------- Fejléc ---------- */
.top { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 700; font-size: 1.45rem; letter-spacing: -.01em; padding-top: 4px; }
.brand img { border-radius: 9px; width: 30px; height: 30px; margin-top: -4px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.install-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 16px; border-radius: 999px;
  border: 0; background: var(--sand); color: var(--ink); font-weight: 600; font-size: .85rem;
  animation: rise .35s ease both;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--white); display: grid; place-items: center; color: var(--ink-soft);
}

.modes {
  margin-top: 18px; display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-radius: 999px; padding: 4px;
}
.modes button {
  border: 0; background: transparent; padding: 10px; border-radius: 999px;
  font-weight: 600; font-size: .92rem; color: var(--muted);
  transition: background .2s, color .2s;
}
.modes button[aria-selected="true"] { background: var(--ink); color: var(--white); }

.tagline { color: var(--muted); font-size: .86rem; line-height: 1.5; margin: 14px 4px 0; text-align: center; }

/* ---------- Kockák ---------- */
.board {
  flex: 1;
  display: flex; flex-wrap: wrap; justify-content: center; align-content: center;
  gap: 18px calc(var(--s) * .2);
  padding: 22px 0 6px;
  perspective: 900px;
}
.die {
  width: var(--s); display: flex; flex-direction: column; align-items: center; gap: 12px;
  background: none; border: 0; padding: 0; touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.die { position: relative; }
.die-stage { width: var(--s); height: var(--s); position: relative; transform-style: preserve-3d; will-change: transform; }
.die.flying .shadow { opacity: .4; }
.cube {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transition: transform 1.2s cubic-bezier(.2,.75,.25,1);
}
.face {
  position: absolute; inset: 0;
  display: grid; place-items: center; text-align: center;
  padding: 10%;
  background: var(--white);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 22%;
  box-shadow: inset 0 -3px 0 rgba(43,42,40,.04);
  font-family: var(--display);
  font-weight: 600;
  font-size: calc(var(--s) * .15);
  line-height: 1.05;
  hyphens: manual;
  overflow-wrap: break-word;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: background .25s, border-color .25s;
}
.face.long { font-size: calc(var(--s) * .125); }
.face.num { font-weight: 700; font-size: calc(var(--s) * .24); letter-spacing: -.02em; }
.face:nth-child(1) { transform: translateZ(calc(var(--s) / 2)); }
.face:nth-child(2) { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); }
.face:nth-child(3) { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); }
.face:nth-child(4) { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); }
.face:nth-child(5) { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); }
.face:nth-child(6) { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }

.shadow {
  transition: opacity .3s;
  position: absolute; left: 6%; right: 6%; bottom: -16%; height: 18%;
  background: radial-gradient(closest-side, rgba(43,42,40,.16), transparent);
  transform: translateZ(-1px);
}
.die-label {
  font-size: .66rem; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); font-weight: 600;
  display: flex; align-items: center; gap: 5px; white-space: nowrap;
}
.die.locked .face { background: var(--sand); border-color: var(--sand); }
.die.locked .die-label { color: #a87a4b; }
.die .lock-ico { display: none; }
.die.locked .lock-ico { display: inline-block; }
.die:focus-visible { outline: none; }
.die:focus-visible .die-stage { outline: 2px solid var(--sand); outline-offset: 6px; border-radius: 22%; }

.hint { text-align: center; color: var(--muted); font-size: .74rem; margin: 10px 0 0; line-height: 1.5; }

/* ---------- Instrukció-pakli ---------- */
.board.deck-mode { perspective: none; align-content: stretch; padding-top: 18px; }
.deck { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 22px; }
.aud { display: inline-flex; gap: 6px; padding: 4px; border: 1px solid var(--line); border-radius: 999px; }
.aud button { border: 0; background: transparent; border-radius: 999px; padding: 7px 18px; font-size: .82rem; font-weight: 600; color: var(--muted); transition: background .2s, color .2s; }
.aud button[aria-selected="true"] { background: var(--sand); color: var(--ink); }
.deck-stage { position: relative; width: min(100%, 340px); height: clamp(250px, 40svh, 330px); }
.pcard {
  position: absolute; inset: 0; border-radius: 28px; border: 1px solid var(--line); background: var(--white);
  box-shadow: 0 20px 40px -24px rgba(43,42,40,.35);
}
.pcard.b1 { transform: translateY(10px) rotate(-3.5deg) scale(.97); background: var(--sand-soft); border-color: var(--sand-soft); }
.pcard.b2 { transform: translateY(18px) rotate(4deg) scale(.94); background: var(--sand); border-color: var(--sand); opacity: .55; }
.pcard.front {
  display: flex; flex-direction: column; justify-content: center; align-items: flex-start; text-align: left;
  padding: 54px 26px 40px; cursor: grab; touch-action: pan-y; user-select: none; -webkit-user-select: none;
  color: var(--ink); overflow: hidden; font: inherit;
}
.pcard.front:active { cursor: grabbing; }
.pcard .cat {
  position: absolute; top: 20px; left: 24px; font-size: .66rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase;
  color: #a87a4b; background: var(--sand-soft); padding: 5px 10px; border-radius: 999px;
}
.pcard .qmark {
  position: absolute; right: 18px; top: -18px; font-family: var(--display); font-weight: 700; font-size: 9rem; line-height: 1;
  color: var(--sand); opacity: .35; pointer-events: none;
}
.pcard .quote {
  position: relative; margin: 18px 0 0; font-family: var(--display); font-weight: 600;
  font-size: clamp(1.2rem, 5.6vw, 1.55rem); line-height: 1.18; letter-spacing: -.01em;
}
.pcard .quote::before { content: "„"; color: var(--sand); margin-right: 1px; }
.pcard.cover .quote::before { content: ""; }
.pcard.cover .quote { color: var(--muted); }
.pcard .qend { color: var(--sand); }
.pcard .w { display: inline-block; }
.pcard.typed .w { animation: word .55s cubic-bezier(.2,.8,.2,1) both; animation-delay: calc(.42s + var(--i) * 45ms); }
.result.compact { padding: 6px 12px; background: transparent; }
.result.compact .result-actions { margin-top: 0; }
#historyList li.q { font-family: var(--display); font-weight: 600; font-size: .98rem; }
@keyframes word { from { opacity: 0; transform: translateY(10px); filter: blur(4px); } to { opacity: 1; transform: none; filter: none; } }

/* ---------- Eredmény ---------- */
.result {
  margin-top: 14px; background: var(--surface); border-radius: 20px; padding: 14px 18px;
  animation: rise .35s ease both;
}
.result ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.result li { animation: slide .45s cubic-bezier(.2,.8,.2,1) both; }
.result li:nth-child(2) { animation-delay: .06s; }
.result li:nth-child(3) { animation-delay: .12s; }
.result li:nth-child(4) { animation-delay: .18s; }
.result li:nth-child(5) { animation-delay: .24s; }
.result.rolling li { opacity: .25; filter: blur(3px); transition: opacity .2s, filter .2s; }
.result li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.result li span:first-child { color: var(--muted); font-size: .78rem; font-weight: 500; }
.result li span:last-child { font-family: var(--display); font-weight: 600; font-size: 1.05rem; text-align: right; }
.result-actions { display: flex; justify-content: center; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.ghost {
  border: 1px solid var(--line); background: var(--white); border-radius: 999px; padding: 9px 16px;
  font-weight: 600; font-size: .84rem; color: var(--ink-soft);
}
.ghost.small { padding: 7px 12px; font-size: .78rem; }
.ghost.running { border-color: var(--sand); background: var(--sand-soft); color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- Dobás gomb ---------- */
.dock {
  position: sticky; bottom: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  margin: 14px -16px 0; padding: 12px 16px calc(env(safe-area-inset-bottom) + 14px);
  background: linear-gradient(to bottom, rgba(255,255,255,0), var(--white) 30%);
}
.roll {
  width: 100%; border: 0; border-radius: 999px; padding: 17px;
  font-family: var(--display); font-size: 1.2rem; font-weight: 700; letter-spacing: .02em; padding-top: 19px;
  background: var(--ink); color: var(--white);
  transition: transform .1s, opacity .2s;
}
.roll:active { transform: scale(.985); }
.roll:disabled { opacity: .55; }

/* ---------- Előzmények ---------- */
dialog {
  width: min(480px, calc(100vw - 24px)); max-height: 80svh; border: 0; border-radius: 24px;
  background: var(--white); color: var(--ink); padding: 20px; box-shadow: 0 30px 80px -20px rgba(43,42,40,.35);
}
dialog::backdrop { background: rgba(43,42,40,.3); backdrop-filter: blur(4px); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg-head h2 { margin: 0; font-family: var(--display); font-weight: 700; font-size: 1.35rem; padding-top: 4px; }
#historyList { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 8px; }
#historyList li { background: var(--surface); border-radius: 14px; padding: 10px 14px; font-size: .86rem; line-height: 1.45; font-weight: 500; }
#historyList time { display: block; color: var(--muted); font-size: .72rem; margin-bottom: 2px; }
.empty { color: var(--muted); font-size: .9rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 96px); transform: translate(-50%, 16px);
  background: var(--ink); color: var(--white); padding: 10px 18px; border-radius: 999px; font-weight: 500; font-size: .84rem;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes slide { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .cube { transition-duration: .01s; }
  .result, .result li, .pcard.typed .w { animation: none; }
}
