:root {
  color: #2f2b27;
  background: #ece5d9;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-synthesis: none;
  text-rendering: geometricPrecision;
  -webkit-font-smoothing: antialiased;
  --red: #8f271f;
  --ink: #312c28;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
}

button {
  font: inherit;
}

.app-shell {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100dvh;
  padding: 0;
  background:
    linear-gradient(90deg, rgba(48, 43, 38, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(48, 43, 38, 0.055) 1px, transparent 1px),
    radial-gradient(circle at 75% 20%, rgba(255, 255, 255, 0.9), transparent 34%),
    linear-gradient(135deg, #f8f5ed 0%, #d7cec0 58%, #b8ad9d 100%);
  background-size: 72px 72px, 72px 72px, 100% 100%, 100% 100%;
}

.game-frame {
  width: 100vw;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 0;
  background: rgba(246, 242, 233, 0.78);
  box-shadow: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 62px;
  padding: 9px clamp(14px, 2.4vw, 28px);
  border-bottom: 1px solid rgba(60, 54, 49, 0.16);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.74), rgba(255, 255, 255, 0.42)),
    linear-gradient(180deg, rgba(143, 39, 31, 0.08), transparent);
}

.brand-block {
  min-width: 0;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(28px, 3.5vw, 42px);
  line-height: 0.95;
  letter-spacing: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid rgba(52, 46, 41, 0.22);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.58);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.74);
  cursor: pointer;
}

.icon-button:hover {
  border-color: rgba(143, 39, 31, 0.36);
  color: var(--red);
  background: rgba(255, 255, 255, 0.72);
}

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

.audio-off {
  display: none;
}

.audio-muted .audio-on {
  display: none;
}

.audio-muted .audio-off {
  display: block;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #eee7dc;
}

.game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

.game-canvas:active {
  cursor: grabbing;
}

/* ---------- Overlays, menus, leaderboard ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(
    circle at 50% 40%,
    rgba(244, 240, 231, 0.62),
    rgba(216, 208, 192, 0.86)
  );
  backdrop-filter: blur(2px);
  z-index: 5;
}

.overlay.hidden {
  display: none;
}

.card {
  width: min(440px, 92%);
  max-height: 92%;
  overflow: auto;
  padding: 26px 26px 22px;
  text-align: center;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(248, 244, 235, 0.92));
  border: 1px solid rgba(143, 39, 31, 0.22);
  border-radius: 14px;
  box-shadow:
    0 18px 50px rgba(40, 34, 28, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.card-title {
  margin: 0 0 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(24px, 4vw, 32px);
  color: var(--red);
}

.card-sub {
  margin: 4px 0;
  font-size: 14px;
}

.card-sub .big {
  font-size: 26px;
}

.muted {
  color: rgba(60, 54, 49, 0.62);
}

.small {
  font-size: 12px;
}

.card-levels {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 14px 0 4px;
}

.chip {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(143, 39, 31, 0.08);
  border: 1px solid rgba(143, 39, 31, 0.2);
  border-radius: 999px;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

.btn {
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(52, 46, 41, 0.26);
  border-radius: 9px;
  cursor: pointer;
}

.btn:hover {
  border-color: rgba(143, 39, 31, 0.4);
  color: var(--red);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  color: #fff;
  background: var(--red);
  border-color: var(--red);
}

.btn-primary:hover {
  color: #fff;
  background: #7c2019;
}

.name-form {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 16px 0 6px;
}

.name-input {
  flex: 1 1 auto;
  max-width: 220px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid rgba(52, 46, 41, 0.3);
  border-radius: 9px;
}

.name-input:focus {
  outline: none;
  border-color: var(--red);
}

.board {
  margin: 8px 0 4px;
  text-align: left;
}

.board-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-bottom: 1px solid rgba(60, 54, 49, 0.12);
}

.board-row .rank {
  font-weight: 700;
  color: rgba(60, 54, 49, 0.6);
}

.board-row .who {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-row .sc {
  font-weight: 800;
  color: var(--red);
}

.board-row.hot {
  background: rgba(143, 39, 31, 0.1);
  border-radius: 7px;
}

.toast {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translate(-50%, -14px);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: rgba(60, 44, 40, 0.82);
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 6;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 720px) {
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100%;
    height: auto;
    padding: 0;
  }

  .game-frame {
    width: 100%;
    min-height: 100dvh;
    height: 100dvh;
    border: 0;
  }

  .topbar {
    min-height: 58px;
    padding: 9px 12px;
  }

  h1 {
    font-size: 30px;
  }

  .topbar-actions {
    gap: 7px;
  }

  .icon-button {
    width: 39px;
    height: 39px;
  }
}
