:root {
  --paper: #f8f9f6;
  --paper-soft: #e8eeea;
  --ink: #171515;
  --ink-soft: #4d4640;
  --quiet: #6f7772;
  --line: rgba(23, 21, 21, 0.13);
  --wine: #7b1e2f;
  --wine-deep: #42121c;
  --sage: #89977c;
  --rose: #b56a78;
  --cream: #fffaf1;
  --gold: #d2a64e;
  --text: #171515;
  --muted: #6f7772;
  --hud-height: clamp(48px, 6.4dvh, 56px);
  --pad-height: clamp(132px, 20dvh, 174px);
  --pad-width: clamp(214px, 62vw, 260px);
  --button-size: clamp(54px, 8dvh, 66px);
  --gap: clamp(6px, 1.2dvh, 10px);
  --outer-pad-x: clamp(10px, 2.6vw, 18px);
  --outer-pad-y: clamp(10px, 1.6dvh, 16px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(23, 21, 21, 0.045) 1px, transparent 1px),
    radial-gradient(circle at 18% 4%, rgba(137, 151, 124, 0.24), transparent 30%),
    radial-gradient(circle at 88% 68%, rgba(181, 106, 120, 0.22), transparent 32%),
    linear-gradient(180deg, var(--paper) 0%, #f3f5f1 55%, var(--paper-soft) 100%);
  background-size: 58px 58px, auto, auto, auto;
  color: var(--text);
  font-family: "Avenir Next", "Helvetica Neue", ui-sans-serif, system-ui, sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(115deg, rgba(255, 255, 255, 0.5), transparent 36%),
    radial-gradient(circle at 45% 18%, rgba(123, 30, 47, 0.09), transparent 34%);
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.shell {
  width: 100%;
  height: 100dvh;
  padding:
    max(var(--outer-pad-y), env(safe-area-inset-top))
    var(--outer-pad-x)
    max(var(--outer-pad-y), env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
}

.game-card {
  position: relative;
  width: min(100%, 478px);
  height: 100%;
  display: grid;
  grid-template-rows: var(--hud-height) minmax(0, 1fr) var(--pad-height);
  gap: var(--gap);
}

.hud-mark {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.game-mark {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.16), transparent 42%),
    var(--ink);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}

.game-mark::before {
  content: "";
  width: 15px;
  height: 15px;
  display: block;
  margin: 6px auto 0;
  background: var(--paper);
  clip-path: polygon(12% 58%, 40% 18%, 88% 24%, 72% 68%, 26% 82%);
}

.hud {
  min-width: 0;
  padding: 0 13px 0 10px;
  display: grid;
  grid-template-columns: 34px 22px minmax(96px, 1fr) 46px 40px;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.74);
  background: rgba(248, 249, 246, 0.78);
  border-radius: 14px;
  box-shadow: 0 18px 52px rgba(61, 46, 38, 0.14);
  backdrop-filter: blur(18px);
}

.level {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(123, 30, 47, 0.08);
  color: var(--wine);
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0;
}

.meter {
  position: relative;
  height: 13px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(23, 21, 21, 0.11);
  box-shadow: inset 0 1px 3px rgba(23, 21, 21, 0.11);
}

.meter-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--wine-deep), var(--wine), var(--rose));
  transition: width 180ms ease-out;
}

.meter-target {
  position: absolute;
  top: -5px;
  bottom: -5px;
  width: 3px;
  border-radius: 999px;
  background: var(--ink);
  box-shadow: 0 0 0 3px rgba(248, 249, 246, 0.72);
}

.reveal {
  width: 46px;
  text-align: right;
  color: var(--wine);
  font-weight: 900;
  font-size: 18px;
}

.passes {
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 18px;
  font-weight: 900;
}

.passes span {
  color: var(--rose);
  font-size: 20px;
  line-height: 1;
}

.board-wrap {
  min-height: 0;
  display: grid;
  place-items: center;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 18px;
  filter: drop-shadow(0 28px 70px rgba(66, 18, 28, 0.16));
}

.pad {
  position: relative;
  width: var(--pad-width);
  height: var(--pad-height);
  justify-self: center;
}

.pad-button {
  position: absolute;
  width: var(--button-size);
  height: var(--button-size);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: clamp(18px, 2.5dvh, 22px);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.62), rgba(248, 249, 246, 0.2)),
    linear-gradient(145deg, var(--cream), #e0d1c8);
  box-shadow:
    0 16px 34px rgba(66, 18, 28, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.72);
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.pad-button::before {
  content: "";
  position: absolute;
  inset: calc(var(--button-size) * 0.265);
  background: var(--wine);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  filter: drop-shadow(0 1px 2px rgba(66, 18, 28, 0.18));
}

.pad-button:active {
  transform: translateY(2px) scale(0.98);
  box-shadow:
    0 8px 18px rgba(66, 18, 28, 0.13),
    inset 0 2px 8px rgba(66, 18, 28, 0.1);
}

.up {
  left: calc((var(--pad-width) - var(--button-size)) / 2);
  top: 0;
}

.down {
  left: calc((var(--pad-width) - var(--button-size)) / 2);
  bottom: 0;
}

.down::before {
  transform: rotate(180deg);
}

.left {
  left: calc(var(--button-size) * 0.265);
  top: calc((var(--pad-height) - var(--button-size)) / 2);
}

.left::before {
  transform: rotate(-90deg);
}

.right {
  right: calc(var(--button-size) * 0.265);
  top: calc((var(--pad-height) - var(--button-size)) / 2);
}

.right::before {
  transform: rotate(90deg);
}

.modal {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: max(16px, env(safe-area-inset-bottom));
  max-width: 470px;
  margin: 0 auto;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: 16px;
  background: rgba(248, 249, 246, 0.94);
  box-shadow: 0 24px 70px rgba(61, 46, 38, 0.2);
  backdrop-filter: blur(18px);
}

@media (max-width: 430px) {
  :root {
    --pad-height: 124px;
    --button-size: 58px;
    --gap: 6px;
  }

  .game-card {
    height: auto;
    max-height: 100%;
    grid-template-rows: var(--hud-height) auto var(--pad-height);
    align-content: center;
  }

  .board-wrap {
    width: min(100%, 356px);
    justify-self: center;
    aspect-ratio: 54 / 78;
  }

  .modal {
    grid-template-columns: 1fr;
  }

  .modal-actions {
    justify-content: stretch;
  }

  .modal button {
    flex: 1;
  }
}

.start-screen {
  position: fixed;
  inset: 0;
  padding:
    max(14px, env(safe-area-inset-top))
    16px
    max(14px, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 30% 18%, rgba(137, 151, 124, 0.25), transparent 30%),
    radial-gradient(circle at 76% 72%, rgba(123, 30, 47, 0.18), transparent 34%),
    linear-gradient(180deg, rgba(248, 249, 246, 0.74), rgba(232, 238, 234, 0.96));
  backdrop-filter: blur(14px);
  z-index: 5;
}

.start-screen.hidden {
  display: none;
}

.start-panel {
  width: min(100%, 420px);
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 18px;
  background: rgba(248, 249, 246, 0.82);
  box-shadow: 0 28px 80px rgba(61, 46, 38, 0.2);
  backdrop-filter: blur(18px);
}

.creator {
  margin: 0 0 8px;
  color: var(--wine);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.start-panel h1 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-weight: 500;
  font-size: clamp(28px, 8vw, 40px);
  line-height: 1;
}

.start-copy {
  margin: 12px 0 20px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
  font-weight: 700;
}

.start-actions {
  display: grid;
  gap: 10px;
}

.start-button {
  width: 100%;
  min-height: 54px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 950;
  font-size: 18px;
  box-shadow: 0 18px 36px rgba(66, 18, 28, 0.18);
  transition: transform 160ms ease, background 160ms ease;
}

.start-button:hover {
  background: var(--wine);
  transform: translateY(-1px);
}

.leave-button {
  min-height: 46px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(66, 18, 28, 0.16);
  border-radius: 999px;
  color: var(--wine);
  background: rgba(255, 255, 255, 0.42);
  text-decoration: none;
  font-weight: 900;
  transition: transform 160ms ease, background 160ms ease;
}

.leave-button:hover {
  background: rgba(255, 255, 255, 0.68);
  transform: translateY(-1px);
}

.modal.hidden {
  display: none;
}

.modal h1 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-weight: 500;
  font-size: 20px;
  line-height: 1.1;
}

.modal p {
  margin: 4px 0 0;
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
}

.modal-actions {
  display: flex;
  gap: 8px;
}

.modal button {
  min-width: 72px;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 999px;
  font-weight: 900;
}

.primary {
  background: var(--sage);
  color: var(--paper);
}

.secondary {
  background: rgba(23, 21, 21, 0.1);
  color: var(--ink);
}

.accent {
  background: var(--wine);
  color: var(--paper);
}

@media (max-width: 360px) {
  :root {
    --pad-height: 116px;
    --pad-width: clamp(202px, 62vw, 238px);
    --button-size: 54px;
  }

  .shell {
    padding-left: 6px;
    padding-right: 6px;
  }

  .hud {
    grid-template-columns: 32px 20px minmax(70px, 1fr) 42px 36px;
    gap: 6px;
    padding: 0 10px;
  }

  .level {
    width: 20px;
    height: 20px;
    font-size: 12px;
  }
}
