* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --brown: #6f4019;
  --orange: #ffb340;
  --orange-dark: #c5781d;
  --cream: #fff2c4;
  --card: #fff9e8;
  --shadow: rgba(55, 32, 10, .22);
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 255, 255, .6), transparent 28rem),
    linear-gradient(135deg, #ffe7a3 0%, #ffd5ba 48%, #d6f2ff 100%);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--brown);
  overflow: hidden;
  touch-action: none;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 520px) minmax(220px, 320px);
  gap: 24px;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.phone-frame {
  position: relative;
  width: min(100vw - 24px, 520px);
  aspect-ratio: 2 / 3;
  max-height: calc(100vh - 24px);
  border-radius: 28px;
  padding: 12px;
  background: rgba(255, 255, 255, .52);
  box-shadow: 0 18px 48px var(--shadow);
  backdrop-filter: blur(12px);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 22px;
  background: #fff3c2;
  user-select: none;
  touch-action: none;
}

.hud {
  position: absolute;
  left: 24px;
  top: 24px;
  right: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 8px;
  align-items: start;
  pointer-events: none;
}

.hud > div,
.hud-button {
  min-height: 44px;
  border: 2px solid rgba(132, 76, 25, .22);
  background: rgba(255, 250, 232, .82);
  border-radius: 16px;
  box-shadow: 0 6px 18px rgba(88, 46, 10, .12);
}

.hud > div {
  padding: 6px 10px;
}

.hud-button {
  pointer-events: auto;
  padding: 0 12px;
  color: var(--brown);
  font-weight: 700;
}

.hud-label {
  font-size: 12px;
  opacity: .66;
  line-height: 1.1;
}

.hud-value {
  font-size: 20px;
  line-height: 1.15;
  font-weight: 900;
}

.toast {
  position: absolute;
  left: 50%;
  top: 94px;
  transform: translateX(-50%) translateY(-8px);
  min-width: 180px;
  max-width: calc(100% - 72px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(60, 34, 8, .82);
  color: white;
  text-align: center;
  font-weight: 800;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

.toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.screen {
  position: absolute;
  inset: 12px;
  display: grid;
  place-items: center;
  padding: 22px;
  border-radius: 22px;
  background: rgba(82, 44, 8, .34);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .18s ease, visibility .18s ease;
}

.screen-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.card {
  width: min(92%, 380px);
  padding: 22px;
  border-radius: 28px;
  background: var(--card);
  border: 4px solid rgba(199, 120, 29, .32);
  box-shadow: 0 16px 44px rgba(47, 24, 7, .28);
  text-align: center;
}

.big-card {
  padding: 26px 24px;
}

.badge {
  display: inline-flex;
  padding: 6px 12px;
  border-radius: 999px;
  background: #ffe2a2;
  color: #8a4c10;
  font-weight: 800;
  font-size: 13px;
}

h1,
h2 {
  margin: 12px 0 8px;
  line-height: 1.1;
}

h1 {
  font-size: clamp(38px, 8vw, 52px);
  letter-spacing: .08em;
  color: #7b4414;
  text-shadow: 0 3px 0 #ffd174;
}

h2 {
  font-size: 30px;
}

.subtitle,
.notice {
  margin: 10px auto;
  max-width: 320px;
  line-height: 1.65;
}

.notice {
  font-size: 12px;
  opacity: .72;
}

.name-field {
  display: grid;
  gap: 6px;
  margin: 18px 0 14px;
  text-align: left;
  font-weight: 800;
}

.name-field input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border-radius: 16px;
  border: 2px solid rgba(132, 76, 25, .25);
  background: white;
  color: var(--brown);
  outline: none;
}

.name-field input:focus {
  border-color: var(--orange);
}

.primary-button,
.secondary-button,
.danger-button {
  width: 100%;
  min-height: 46px;
  margin-top: 10px;
  border-radius: 18px;
  border: 0;
  font-weight: 900;
}

.primary-button {
  background: linear-gradient(#ffc65a, #ff9d2e);
  color: white;
  text-shadow: 0 1px 0 rgba(80, 30, 0, .25);
  box-shadow: 0 7px 0 var(--orange-dark), 0 12px 24px rgba(151, 82, 10, .24);
}

.primary-button:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 var(--orange-dark), 0 8px 18px rgba(151, 82, 10, .2);
}

.secondary-button {
  background: #fff;
  border: 2px solid rgba(132, 76, 25, .18);
  color: var(--brown);
}

.danger-button {
  background: #fff2f2;
  color: #aa3129;
  border: 2px solid rgba(170, 49, 41, .18);
}

.hidden {
  display: none !important;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 18px 0 12px;
}

.result-grid div {
  padding: 14px 8px;
  border-radius: 18px;
  background: #fff;
  border: 2px solid rgba(132, 76, 25, .14);
}

.result-grid span {
  display: block;
  font-size: 12px;
  opacity: .65;
}

.result-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
}

.leaderboard {
  min-height: 160px;
  max-height: 260px;
  overflow: auto;
  padding-left: 28px;
  text-align: left;
}

.leaderboard li {
  padding: 8px 0;
  border-bottom: 1px dashed rgba(132, 76, 25, .2);
}

.leaderboard strong {
  float: right;
}

.desktop-info {
  max-width: 320px;
  padding: 22px;
  border-radius: 28px;
  background: rgba(255, 255, 255, .52);
  box-shadow: 0 18px 48px rgba(55, 32, 10, .16);
  backdrop-filter: blur(12px);
  line-height: 1.7;
}

.desktop-info h2 {
  font-size: 22px;
}

@media (max-width: 840px) {
  .app {
    grid-template-columns: 1fr;
    padding: 0;
  }

  .phone-frame {
    width: 100vw;
    height: 100vh;
    max-height: none;
    aspect-ratio: auto;
    border-radius: 0;
    padding: 0;
  }

  canvas,
  .screen {
    border-radius: 0;
  }

  .screen {
    inset: 0;
  }

  .hud {
    left: 12px;
    right: 12px;
    top: 12px;
    grid-template-columns: 1fr 1fr auto;
  }

  #soundButton {
    display: none;
  }

  .desktop-info {
    display: none;
  }
}
