:root {
  --bg: #f3efe6;
  --card: #fff9ef;
  --line: #d3c4a9;
  --text: #2f2418;
  --accent: #b44f2a;
  --accent-2: #2e6f64;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Avenir Next', 'Helvetica Neue', Helvetica, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 10%, #f6d8a8 0, transparent 25%),
    radial-gradient(circle at 90% 90%, #d2eadf 0, transparent 20%),
    var(--bg);
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  gap: 1rem;
}

.card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
}

h1,
h2 {
  margin-top: 0;
}

.muted {
  opacity: 0.85;
}

.controls,
.game-input,
.stats {
  display: grid;
  gap: 0.6rem;
}

.controls > * {
  width: 100%;
}

.stats {
  gap: 0.85rem;
}

.row {
  display: grid;
  gap: 0.35rem;
  width: 100%;
}

button {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  min-height: 48px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

select {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  min-height: 48px;
}

button {
  background: linear-gradient(120deg, var(--accent), #d37952);
  color: #fff;
  border: 0;
  cursor: pointer;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  line-height: 1.2;
}

button:disabled,
select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.game-input {
  justify-items: center;
  text-align: center;
}

.numberline-wrap {
  display: grid;
  gap: 0.65rem;
}

.numberline {
  position: relative;
  height: 76px;
  border-radius: 999px;
  background:
    linear-gradient(180deg, #fcf2e1 0%, #f3e3ca 100%);
  border: 2px solid var(--line);
  overflow: hidden;
}

.numberline::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 4px;
  transform: translateY(-50%);
  background: linear-gradient(90deg, #cdb48c 0%, #e7d7bc 100%);
}

.numberline-scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  opacity: 0.8;
}

.marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  transition: left 260ms ease;
}

.marker-label {
  display: inline-flex;
  min-width: 42px;
  min-height: 42px;
  border-radius: 999px;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 900;
}

.marker-current .marker-label {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 18px rgba(180, 79, 42, 0.35);
}

.marker-target .marker-label {
  background: #ffe9a9;
  color: #6f4c00;
  border: 2px solid #ffca3a;
  box-shadow: 0 0 12px #ffca3a, 0 0 24px rgba(255, 202, 58, 0.55);
}

.win-overlay,
.loss-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 20;
  opacity: 0;
}

.start-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  pointer-events: none;
  z-index: 18;
  opacity: 0;
}

.start-card {
  position: relative;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
}

.start-image {
  width: min(86vw, 660px);
  max-width: 100%;
  max-height: min(84dvh, 760px);
  height: auto;
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 20px 46px rgba(0, 0, 0, 0.32));
}

.start-value {
  position: absolute;
  left: 50%;
  top: 39%;
  width: 42%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-size: clamp(3.8rem, 12vw, 7.8rem);
  font-weight: 900;
  line-height: 1;
  color: #c85d2f;
  text-shadow: 0 6px 14px rgba(255, 230, 184, 0.82), 0 2px 0 rgba(84, 42, 19, 0.35);
}

.start-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
  cursor: pointer;
}

.start-overlay.is-active .start-card {
  animation: start-pop 700ms cubic-bezier(0.2, 0.82, 0.2, 1) both;
}

@keyframes start-pop {
  0% {
    transform: scale(0.78);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.win-image {
  width: min(78vw, 620px);
  max-height: 84vh;
  object-fit: contain;
  transform: translate(var(--start-x, 0), var(--start-y, 0)) scale(0.04);
  opacity: 0;
  filter: drop-shadow(0 0 0 rgba(255, 212, 90, 0));
}

.win-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
  cursor: pointer;
}

.loss-overlay {
  padding: 1rem;
  background: rgba(35, 22, 14, 0.34);
  backdrop-filter: blur(4px);
}

.loss-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
  cursor: pointer;
}

.loss-image {
  width: min(82vw, 640px);
  max-height: 84vh;
  object-fit: contain;
  transform: scale(0.88) rotate(-2deg);
  opacity: 0;
  filter: drop-shadow(0 18px 38px rgba(48, 26, 18, 0.28));
}

.loss-overlay.is-active .loss-image {
  animation: loss-pop 520ms cubic-bezier(0.2, 0.82, 0.2, 1) forwards;
}

@keyframes loss-pop {
  0% {
    transform: scale(0.8) rotate(-4deg);
    opacity: 0;
  }
  100% {
    transform: scale(1) rotate(-2deg);
    opacity: 1;
  }
}

.win-overlay.is-active .win-image {
  animation:
    win-grow 1400ms cubic-bezier(0.18, 0.8, 0.2, 1) forwards,
    win-grow-continue 2000ms ease-out 1400ms forwards;
}

@keyframes win-grow {
  0% {
    transform: translate(var(--start-x, 0), var(--start-y, 0)) scale(0.04);
    opacity: 0;
    filter: drop-shadow(0 0 0 rgba(255, 212, 90, 0));
  }
  12% {
    opacity: 1;
  }
  100% {
    transform: translate(0, 0) scale(1.24);
    opacity: 1;
    filter: drop-shadow(0 0 18px rgba(255, 212, 90, 0.92)) drop-shadow(0 0 48px rgba(255, 212, 90, 0.7));
  }
}

@keyframes win-grow-continue {
  0% {
    transform: translate(0, 0) scale(1.24);
    filter: drop-shadow(0 0 18px rgba(255, 212, 90, 0.92)) drop-shadow(0 0 48px rgba(255, 212, 90, 0.7));
  }
  100% {
    transform: translate(0, 0) scale(1.42);
    filter: drop-shadow(0 0 24px rgba(255, 212, 90, 0.95)) drop-shadow(0 0 64px rgba(255, 212, 90, 0.78));
  }
}

.moves-meta {
  margin: 0;
  text-align: center;
  font-size: 0.98rem;
  font-weight: 700;
}

.input-label {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  opacity: 0.85;
}

.operator-options,
.card-options {
  width: 100%;
  display: grid;
  gap: 0.85rem;
}

.operator-options {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.card-options {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-btn {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f6ead5;
  color: var(--text);
  border: 2px solid var(--line);
  border-radius: 18px;
  transition: transform 120ms ease, border-color 120ms ease, background-color 120ms ease;
}

.choice-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.choice-btn.is-selected {
  border-color: var(--accent);
  background: #ffe4cc;
}

.operator-btn {
  font-size: 2rem;
  font-weight: 900;
  padding: 0.75rem 0.3rem;
}

.card-btn {
  min-height: 128px;
  font-size: clamp(2.8rem, 8vw, 4rem);
  font-weight: 900;
  padding: 1.2rem 0.4rem;
}

@media (max-width: 640px) {
  .app {
    padding: 0.6rem;
  }

  .start-overlay {
    padding: 0.75rem;
  }

  .start-card {
    width: fit-content;
  }

  .start-image {
    width: min(92vw, 520px);
    max-width: 100%;
    max-height: min(78dvh, 700px);
  }

  .choice-btn,
  #start-btn,
  #move-btn {
    min-height: 72px;
  }

  .card-btn {
    min-height: 108px;
  }
}
