:root {
  --paper: rgba(251, 243, 226, 0.93);
  --ink: #3a4231;
  --ink-soft: #6b7259;
  --green: #6a9a55;
  --green-dark: #58824a;
  --amber: #e8a13d;
}

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

html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 750px at 72% 18%, rgba(64, 118, 106, 0.55) 0%, transparent 62%),
    radial-gradient(950px 700px at 15% 85%, rgba(43, 84, 100, 0.6) 0%, transparent 58%),
    linear-gradient(160deg, #29474d 0%, #1d3540 55%, #152833 100%);
  user-select: none;
  -webkit-user-select: none;
}

/* зерно поверх фона */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.06;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="220" height="220"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.85" numOctaves="2"/></filter><rect width="220" height="220" filter="url(%23n)"/></svg>');
}

/* виньетка */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(8, 18, 22, 0.5) 100%);
}

#board {
  position: fixed;
  inset: 0;
  touch-action: none;
  cursor: pointer;
}
#board.grabbing { cursor: grabbing; }

/* --- панели ----------------------------------------------------------- */

.panel {
  position: fixed;
  z-index: 5;
  background: var(--paper);
  border: 1px solid rgba(120, 100, 60, 0.22);
  border-radius: 18px;
  box-shadow:
    0 12px 32px rgba(8, 22, 18, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(6px);
  padding: 14px 18px;
}

#hud-left {
  top: 18px;
  left: 18px;
  min-width: 178px;
  animation: drop-in 0.6s 0.1s cubic-bezier(0.2, 0.9, 0.3, 1.2) backwards;
}

.title {
  font-family: 'Prata', serif;
  font-size: 19px;
  letter-spacing: 0.03em;
  color: #4c5a3c;
  margin-bottom: 4px;
}

.score-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

#score {
  font-family: 'Prata', serif;
  font-size: 38px;
  line-height: 1.1;
  color: var(--ink);
  display: inline-block;
}
#score.bump { animation: bump 0.35s ease; }

.score-label { color: var(--ink-soft); font-size: 14px; }
.sub { color: var(--ink-soft); font-size: 13px; margin-bottom: 10px; }

#hud-right {
  top: 18px;
  right: 18px;
  width: 216px;
  animation: drop-in 0.6s 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.2) backwards;
}

.panel-caption {
  font-family: 'Prata', serif;
  font-size: 15px;
  color: #4c5a3c;
  margin-bottom: 8px;
}

.quest {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
}
.quest:last-child { margin-bottom: 0; }
.qdot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(60, 70, 50, 0.35);
  flex: none;
}
.qname { flex: 1; }
.qprog { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.quest-empty { color: var(--ink-soft); font-size: 12.5px; line-height: 1.4; }

/* --- док с текущим тайлом --------------------------------------------- */

#dock {
  bottom: 34px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  animation: rise-in 0.6s 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2) backwards;
}

.tilebox { position: relative; }
#cur { width: 120px; height: 120px; display: block; cursor: pointer; }
#next { width: 60px; height: 60px; display: block; opacity: 0.9; }

.nextbox {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--ink-soft);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.deck-badge {
  position: absolute;
  top: -6px;
  right: -8px;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border-radius: 15px;
  background: var(--amber);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 8px rgba(120, 70, 0, 0.35);
}

#hint {
  position: fixed;
  z-index: 5;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(240, 245, 230, 0.55);
  font-size: 12px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* --- кнопки ------------------------------------------------------------ */

.btn {
  border: none;
  border-radius: 12px;
  background: var(--green);
  color: #fff;
  font-family: inherit;
  font-weight: 800;
  font-size: 14px;
  padding: 9px 16px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--green-dark);
  transition: transform 0.1s, box-shadow 0.1s, filter 0.15s;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--green-dark); }

.btn-round {
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(20, 35, 30, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  transition: transform 0.15s ease;
}
.btn-round:hover { transform: rotate(20deg) scale(1.08); }
#rot-l:hover { transform: rotate(-20deg) scale(1.08); }

#btn-mute {
  position: fixed;
  z-index: 5;
  right: 18px;
  bottom: 18px;
  background: rgba(251, 243, 226, 0.85);
}

/* --- оверлей ------------------------------------------------------------ */

#overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(9, 20, 18, 0.55);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
}
#overlay.hidden { display: none; }

.modal {
  position: static;
  text-align: center;
  padding: 30px 44px;
  animation: rise-in 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.25) backwards;
}
.modal h2 {
  font-family: 'Prata', serif;
  font-size: 28px;
  color: #4c5a3c;
  margin-bottom: 10px;
}
.modal p { font-size: 17px; line-height: 1.5; margin-bottom: 18px; }

/* --- анимации ------------------------------------------------------------ */

@keyframes drop-in {
  from { opacity: 0; transform: translateY(-24px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes rise-in {
  from { opacity: 0; transform: translate(-50%, 24px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.modal { animation-name: rise-in-center; }
@keyframes rise-in-center {
  from { opacity: 0; transform: translateY(24px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes bump {
  40% { transform: scale(1.22); color: #a8730f; }
}

/* --- мобильная вёрстка ---------------------------------------------------- */

@media (max-width: 640px) {
  #hud-left { min-width: 0; padding: 10px 12px; max-width: 46vw; }
  .title { font-size: 14px; }
  #score { font-size: 26px; }
  .score-label { font-size: 12px; }
  .sub { font-size: 11.5px; margin-bottom: 8px; }
  #btn-new { padding: 7px 12px; font-size: 12px; }

  #hud-right { width: 46vw; padding: 10px 12px; }
  .panel-caption { font-size: 13px; }
  .quest { font-size: 12px; padding: 5px 6px; }
  .quest-empty { font-size: 11px; }

  #dock { gap: 10px; padding: 10px 12px; bottom: 16px; }
  #cur { width: 84px; height: 84px; }
  #next { width: 46px; height: 46px; }
  .btn-round { width: 40px; height: 40px; font-size: 18px; }
  .deck-badge { min-width: 26px; height: 26px; font-size: 13px; }

  #hint { display: none; }
  #btn-mute { bottom: 132px; right: 12px; }
  .modal { padding: 22px 26px; margin: 0 16px; }
}
