:root {
  --bg: #0f1115;
  --panel: #1a1f29;
  --panel-2: #222937;
  --text: #f2f5f9;
  --muted: #aeb7c5;
  --accent: #7bd3ff;
  --accent-2: #65f0b5;
  --danger: #ff7f7f;
  --border: rgba(255,255,255,0.08);
  --shadow: 0 10px 30px rgba(0,0,0,0.3);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: system-ui, sans-serif;
  background:
    radial-gradient(circle at top, #1b2230 0%, var(--bg) 40%),
    var(--bg);
  color: var(--text);
  overflow: hidden;
}

.page {
  width: min(900px, calc(100vw - 24px));
  min-height: 100dvh;
  margin: 0 auto;
  padding: clamp(10px, 2vh, 24px) 0;
  display: flex;
  flex-direction: column;
}

.page.narrow {
  width: min(680px, calc(100vw - 24px));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: clamp(8px, 1.6vh, 20px);
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(1.35rem, 3.2vw, 2rem);
  line-height: 1.1;
}

h2 {
  font-size: 1.1rem;
  margin-bottom: 14px;
}

.card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: clamp(12px, 1.8vh, 18px);
  box-shadow: var(--shadow);
  margin-bottom: 0;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

button,
.link-btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 1rem;
  cursor: pointer;
  background: var(--accent);
  color: #07131d;
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.08s ease, opacity 0.2s ease;
}

button:hover,
.link-btn:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

button.secondary {
  background: #d0d7e2;
}

.muted {
  color: var(--muted);
}

.centered {
  text-align: center;
}

.centered-controls {
  justify-content: center;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.game-card {
  min-height: calc(100dvh - clamp(24px, 4vh, 48px) - clamp(44px, 8vh, 72px));
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  align-content: stretch;
  gap: clamp(6px, 1vh, 10px);
}

.dial-wrap {
  display: grid;
  place-items: center;
  margin: clamp(6px, 1.5vh, 18px) 0 clamp(6px, 1.2vh, 14px);
  min-height: 0;
}

.dial {
  position: relative;
  width: min(62vw, 52dvh, 360px);
  height: min(62vw, 52dvh, 360px);
  border-radius: 50%;
  background: radial-gradient(circle at center, #1d2532 0%, #111722 72%);
  border: 2px solid rgba(255,255,255,0.08);
  box-shadow:
    inset 0 0 0 8px rgba(255,255,255,0.02),
    0 16px 30px rgba(0,0,0,0.3);
  touch-action: none;
  user-select: none;
}

.dial::before {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  border: 1px dashed rgba(255,255,255,0.12);
}

.dial-center {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  transform: translate(-50%, -50%);
  background: var(--accent-2);
  border-radius: 50%;
  box-shadow: 0 0 16px rgba(101, 240, 181, 0.45);
  z-index: 3;
}

.arrow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 70%;
  height: 70%;
  transform: translate(-50%, -50%) rotate(0deg);
  transform-origin: 50% 50%;
  z-index: 2;
  pointer-events: none;
}

.arrow::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 50%;
  transform: translate(-50%, -100%);
  background: linear-gradient(180deg, var(--accent) 0%, #cfeeff 100%);
  border-radius: 999px;
}

.arrow::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -4%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 16px solid transparent;
  border-right: 16px solid transparent;
  border-bottom: 24px solid #dff5ff;
  filter: drop-shadow(0 0 10px rgba(123,211,255,0.28));
}

.answer-arrow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 70%;
  height: 70%;
  transform: translate(-50%, -50%) rotate(0deg);
  transform-origin: 50% 50%;
  z-index: 1;
  opacity: 0.95;
  pointer-events: none;
}

.answer-arrow::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 42%;
  transform: translate(-50%, -100%);
  background: rgba(255, 120, 120, 0.95);
  border-radius: 999px;
  box-shadow: 0 0 12px rgba(255, 120, 120, 0.25);
}

.answer-arrow::after {
  content: "";
  position: absolute;
  left: 50%;
  top: calc(8% - 2px);
  transform: translateX(-50%);
  width: 10px;
  height: 10px;
  background: rgba(255, 120, 120, 0.95);
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(255, 120, 120, 0.25);
}

.label {
  position: absolute;
  font-size: 0.95rem;
  color: var(--muted);
}

.label-top {
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
}

.label-right {
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
}

.label-bottom {
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
}

.label-left {
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
}

.guess-readout {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  margin-bottom: clamp(8px, 1.5vh, 16px);
  font-size: clamp(0.95rem, 1.8vh, 1.1rem);
}

.result-box {
  margin-top: 4px;
  padding: clamp(10px, 1.4vh, 14px);
  border-radius: 16px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  min-height: clamp(96px, 16vh, 150px);
  display: grid;
  align-content: center;
}

.result-box p {
  margin: 6px 0;
}

.result-box.good {
  outline: 2px solid rgba(101,240,181,0.35);
}

.result-box.bad {
  outline: 2px solid rgba(255,127,127,0.28);
}

.result-box.result-box--idle {
  opacity: 0.9;
}

.hidden {
  display: none;
}

.setting {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 16px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.setting label {
  font-weight: 600;
}

.setting input[type="range"] {
  grid-column: 1 / 2;
  width: 100%;
}

.setting span,
.setting select {
  grid-column: 2 / 3;
}

.checkbox-row {
  grid-template-columns: 1fr auto;
}

input[type="checkbox"] {
  width: 22px;
  height: 22px;
}

/* Landscape mobile: use width better */
@media (orientation: landscape) and (max-width: 950px) {
  .page {
    width: min(100vw - 16px, 1200px);
    padding: 8px 0;
  }

  .topbar {
    margin-bottom: 8px;
  }

  .game-card {
    flex: 1;
    min-height: 0;
    grid-template-columns: minmax(220px, 1fr) minmax(220px, 0.9fr);
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "status status"
      "dial results"
      "controls results";
    column-gap: 14px;
    row-gap: 8px;
    align-items: center;
  }

  #roundStatus {
    grid-area: status;
    margin: 0;
  }

  .dial-wrap {
    grid-area: dial;
    margin: 0;
  }

  .guess-readout {
    grid-area: dial;
    align-self: end;
    justify-self: center;
    margin-top: 8px;
    margin-bottom: 0;
    transform: translateY(6px);
  }

  .controls.centered-controls {
    grid-area: controls;
    justify-content: center;
    margin-top: 2px;
  }

  .result-box {
    grid-area: results;
    margin-top: 0;
    min-height: 100%;
    align-self: stretch;
  }

  .dial {
    width: min(44vw, 62dvh, 340px);
    height: min(44vw, 62dvh, 340px);
  }
}

@media (max-height: 760px) {
  .page {
    width: min(900px, calc(100vw - 16px));
    padding: 8px 0;
  }

  .topbar {
    margin-bottom: 8px;
  }

  h1 {
    font-size: 1.6rem;
  }

  button,
  .link-btn {
    padding: 10px 14px;
    font-size: 0.95rem;
  }

  .dial {
    width: min(52vw, 40dvh, 280px);
    height: min(52vw, 40dvh, 280px);
  }

  .result-box {
    min-height: 92px;
  }
}

@media (max-height: 620px) {
  h1 {
    font-size: 1.35rem;
  }

  .card {
    padding: 10px;
    border-radius: 18px;
  }

  .dial {
    width: min(44vw, 34dvh, 220px);
    height: min(44vw, 34dvh, 220px);
  }

  .guess-readout {
    margin-bottom: 6px;
    font-size: 0.92rem;
  }

  .controls {
    gap: 8px;
  }

  .result-box {
    min-height: 78px;
    padding: 8px 10px;
  }

  .result-box p {
    margin: 3px 0;
    font-size: 0.92rem;
  }
}