:root {
  --bg-ice: #dff5ff;
  --ink: #142a33;
  --hud-bg: rgba(255, 255, 255, 0.92);
  --red: #d62828;
  --yellow: #fcbf49;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
}

body {
  position: relative;
  background:
    linear-gradient(180deg, rgba(185, 220, 239, 0.18), rgba(159, 208, 232, 0.18)),
    url("images/ice.png") center / cover no-repeat fixed;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(8, 32, 48, 0.3) 100%);
}

canvas {
  display: block;
  background: transparent !important;
}

.title-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: url("images/title-screen.png") center / cover no-repeat;
  overflow: hidden;
}

.title-screen::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 78%;
  width: min(44vw, 520px);
  height: min(9vw, 96px);
  transform: translate(-50%, -50%);
  z-index: 1;
  pointer-events: none;
  border-radius: 999px;
  background:
    radial-gradient(ellipse at center, rgba(255, 255, 255, 0.98) 0%, rgba(205, 238, 255, 0.72) 42%, rgba(150, 205, 245, 0.24) 64%, rgba(255, 255, 255, 0) 84%);
  box-shadow:
    0 0 28px rgba(195, 231, 255, 0.84),
    0 0 56px rgba(165, 216, 250, 0.62);
  animation: titlePromptPulse 1.7s ease-in-out infinite;
}

.title-screen::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 78%;
  width: clamp(48px, 7vw, 98px);
  height: clamp(48px, 7vw, 98px);
  transform: translate(-50%, -50%);
  z-index: 2;
  background: url("images/red-stone.png") center / contain no-repeat;
  filter: drop-shadow(0 3px 8px rgba(18, 52, 72, 0.56));
  pointer-events: none;
  animation:
    titlePromptPulse 1.7s ease-in-out infinite,
    titleStoneSpin 6.5s linear infinite;
}

@keyframes titlePromptPulse {
  0% { opacity: 0.18; }
  28% { opacity: 1; }
  66% { opacity: 1; }
  100% { opacity: 0.18; }
}

@keyframes titleStoneSpin {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(360deg); }
}

.title-screen.hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms ease;
}


.hud {
  position: fixed;
  top: 24px;
  left: 12px;
  width: 520px;
  max-width: calc(100vw - 24px);
  z-index: 5;
  background:
    linear-gradient(180deg, rgba(247, 253, 255, 0.88), rgba(233, 246, 252, 0.84)),
    url("images/ice.png") center / cover no-repeat;
  border: 2px solid #79aac3;
  border-radius: 14px;
  padding: 14px clamp(8px, 1.2vw, 16px);
  box-shadow: 0 12px 28px rgba(8, 52, 74, 0.22);
  backdrop-filter: blur(2px);
  text-transform: uppercase;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateX(-30px);
  pointer-events: none;
  transition: opacity 400ms ease, transform 400ms ease;
}

/* Consistent vertical spacing on left HUD sections. */
.hud > .stones-table-wrap { margin-top: 10px; }
.hud > .mode-toggle {
  margin-top: 14px;
}

.hud.ready {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.hud-logo {
  text-align: center;
  margin-bottom: 4px;
}

.hud-logo img {
  display: block;
  width: 90%;
  height: auto;
  margin: 0 auto;
  border-radius: 8px;
}

.end-indicator {
  text-align: center;
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  font-size: clamp(14px, 1.5vw, 18px);
  font-weight: 800;
  color: #5e6972;
  letter-spacing: 0.3px;
  margin: 8px 0 6px;
}

.hammer-badge {
  display: inline-block;
  font-size: clamp(11px, 1.2vw, 14px);
  font-weight: 700;
  color: #f5c542;
  margin-left: 8px;
  vertical-align: middle;
}

.title-credit {
  position: absolute;
  left: 50%;
  top: 88%;
  transform: translateX(-50%);
  z-index: 3;
  font-size: clamp(14px, 1.8vw, 20px);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
  letter-spacing: 0.5px;
  pointer-events: none;
}

.title-version {
  position: absolute;
  right: 14px;
  bottom: 12px;
  z-index: 3;
  font-size: 14px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.75);
  text-shadow: 0 1px 5px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}


.stones-table-wrap {
  margin-top: 0;
  border: 1px solid #9ec0d2;
  border-radius: 12px;
  background: transparent;
  overflow: hidden;
}

.mode-toggle {
  text-align: center;
  padding: 6px 10px;
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(90, 140, 175, 0.35), rgba(70, 120, 160, 0.3));
  font-size: clamp(11px, 1.2vw, 13px);
  font-weight: 700;
  color: rgba(220, 245, 245, 0.85);
  text-transform: none;
}

.stones-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 14px;
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  color: #58646d;
}

.stones-table th,
.stones-table td {
  padding: 10px clamp(6px, 1vw, 10px);
  border-bottom: 1px solid rgba(148, 181, 199, 0.5);
  text-align: left;
  vertical-align: middle;
  background: transparent;
}

.stones-table thead th {
  font-size: clamp(14px, 1.5vw, 18px);
  font-weight: 800;
  color: #5e6972;
  background: transparent;
  letter-spacing: 0.2px;
}

.stones-table thead th:nth-child(1) { width: 28%; }
.stones-table thead th:nth-child(2) { width: 12%; }
.stones-table thead th:nth-child(3) { width: 60%; }

.stones-table tbody tr.active-turn td {
  background: rgba(30, 100, 160, 0.25);
}

.stones-table tbody tr.active-turn td.score-cell {
  background: linear-gradient(180deg, #2b6cb0, #1f5b99);
}

.stones-table tbody tr.active-turn td.team-cell {
  box-shadow: inset 4px 0 0 rgba(60, 160, 220, 0.7);
}

.stones-table tbody tr:last-child td {
  border-bottom: 0;
}

.stones-table tbody tr {
  height: 56px;
}

.stones-table td.team-cell {
  white-space: nowrap;
  font-size: clamp(16px, 2vw, 24px);
  line-height: 56px;
  font-weight: 700;
  color: #5b6670;
}

.stones-table th:nth-child(2),
.stones-table td.score-cell {
  text-align: center;
  padding-left: 8px;
  padding-right: 8px;
}

.stones-table th:nth-child(3),
.stones-table td:nth-child(3) {
  padding-left: clamp(8px, 1.8vw, 22px);
  padding-right: 8px;
  text-align: left;
  overflow: hidden;
}

.end-badge {
  display: inline-flex;
  position: relative;
  top: -2px;
  align-items: center;
  justify-content: center;
  margin-left: 7px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 800;
  color: #ffffff;
  background: radial-gradient(circle at 32% 28%, #7ee49d 0%, #2fbf62 52%, #1f8e48 100%);
  border: 1px solid rgba(24, 96, 50, 0.8);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.5),
    0 1px 2px rgba(0, 0, 0, 0.18);
}


.stones-table td.score-cell {
  font-size: clamp(16px, 1.8vw, 21px);
  line-height: 1;
  font-weight: 800;
  color: #ffffff;
  background: linear-gradient(180deg, #2b6cb0, #1f5b99);
  border-left: 1px solid rgba(123, 161, 190, 0.45);
  border-right: 1px solid rgba(123, 161, 190, 0.45);
}

.stones-table th.score-head {
  color: transparent;
}

@keyframes scorePulse {
  0% { transform: scale(1); }
  30% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.score-cell.pulse {
  animation: scorePulse 450ms ease-out;
}

.dots {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 0px;
  min-height: 46px;
  margin-left: 0;
  transform: none;
}

.dot {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 0;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  box-shadow: none;
}

.dot.red {
  background-image: url("images/red-stone.png");
}

.dot.yellow {
  background-image: url("images/yellow-stone.png");
}

.dot-spin-out {
  animation: spinOut 1.6s ease-in-out forwards;
}

@keyframes spinOut {
  0% { transform: rotate(0deg); opacity: 1; }
  85% { transform: rotate(720deg); opacity: 1; }
  100% { transform: rotate(720deg); opacity: 0; }
}

.flag {
  display: inline-block;
  width: clamp(28px, 3.5vw, 44px);
  height: auto;
  aspect-ratio: 44 / 30;
  margin-right: 8px;
  vertical-align: middle;
  border: 1px solid rgba(34, 57, 71, 0.28);
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(20, 42, 54, 0.16);
}


@media (max-width: 768px) {
  .hud {
    top: 4px;
    left: 4px;
    right: 4px;
    width: auto;
    max-width: none;
    padding: 6px 8px;
    border-radius: 10px;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }

  .title-screen {
    background-size: auto 96%;
    background-position: center center;
  }

  .hud-logo {
    display: none;
  }

  .hud > .stones-table-wrap {
    margin-top: 0;
    flex: 1;
    min-width: 0;
  }

  .hud > .mode-toggle {
    display: none;
  }

  .end-indicator {
    margin: 0;
    font-size: 12px;
    white-space: nowrap;
  }

  .stones-table tbody tr {
    height: 36px;
  }

  .stones-table td.team-cell {
    font-size: 14px;
    line-height: 36px;
  }

  .stones-table td.score-cell {
    font-size: 14px;
  }

  .stones-table th,
  .stones-table td {
    padding: 4px 4px;
  }

  .dot {
    width: 24px;
    height: 24px;
  }

  .dots {
    min-height: 28px;
    gap: 1px;
  }

  .flag {
    width: 22px;
    margin-right: 4px;
  }

  .end-badge {
    width: 20px;
    height: 20px;
    font-size: 12px;
    margin-left: 4px;
  }

  .hammer-badge {
    font-size: 10px;
    margin-left: 4px;
  }
}

kbd {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(160, 195, 220, 0.4);
  border-radius: 4px;
  padding: 1px 6px;
  color: inherit;
}
