:root {
  color-scheme: light;
  --bg: #f6f3ee;
  --panel: #ffffff;
  --ink: #191816;
  --muted: #706a63;
  --line: #e7dfd5;
  --red: #cf2b23;
  --red-dark: #a91f1a;
  --gold: #f3b83b;
  --green: #256f5d;
  --shadow: 0 22px 60px rgba(76, 42, 21, 0.16);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 12% 8%, rgba(243, 184, 59, 0.28), transparent 24rem),
    linear-gradient(135deg, #fffaf1 0%, #f7efe6 42%, #eef5f0 100%);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(36px + env(safe-area-inset-bottom));
}

.topbar,
.admin-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.brand-mark {
  display: inline-grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 14px;
  background: var(--red);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 12px 28px rgba(207, 43, 35, 0.28);
}

.admin-link {
  color: var(--green);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.invite-card,
.admin-panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.front-footer {
  margin: 18px 0 0;
  color: rgba(112, 106, 99, 0.78);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.friend-line {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.invite-copy {
  min-width: 0;
}

.invite-title {
  white-space: nowrap;
  font-size: clamp(15px, 4.2vw, 28px);
  font-weight: 900;
  line-height: 1.12;
}

.avatar {
  width: 72px;
  height: 72px;
  flex: 0 0 auto;
  border: 3px solid #fff;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 12px 28px rgba(25, 24, 22, 0.18);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--red);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  line-height: 1.16;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(24px, 7vw, 34px);
}

h2 {
  font-size: 26px;
}

.notice {
  margin: 0 0 22px;
  padding: 12px 14px;
  border: 1px solid #f1ddaf;
  border-radius: 12px;
  background: #fff8e5;
  color: #765717;
  font-size: 14px;
  line-height: 1.5;
}

.register-form,
.admin-form {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.field input,
.pin-display {
  width: 100%;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 15px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.pin-display {
  text-align: left;
}

.pin-display:not(.has-value) {
  color: #9a9187;
  font-weight: 500;
}

.pin-display.has-value {
  color: var(--ink);
  font-size: 20px;
  letter-spacing: 4px;
  font-weight: 900;
}

.field input:focus,
.pin-display:focus-visible {
  border-color: var(--red);
  box-shadow: 0 0 0 4px rgba(207, 43, 35, 0.1);
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--red-dark);
  font-size: 14px;
}

.primary-button {
  width: 100%;
  height: 54px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--red), #e95d36);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 14px 28px rgba(207, 43, 35, 0.28);
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 34px rgba(207, 43, 35, 0.32);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
  transform: none;
}

.draw-screen {
  min-height: calc(100vh - 60px);
  min-height: calc(100svh - 60px);
  display: grid;
  align-content: start;
  gap: 20px;
  padding-top: clamp(24px, 6vh, 54px);
  text-align: center;
}

.draw-header {
  display: grid;
  gap: 6px;
}

.draw-header p:not(.eyebrow) {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.wheel-wrap {
  position: relative;
  width: min(86vw, 380px);
  aspect-ratio: 1;
  margin: 0 auto;
  padding: 12px;
  border-radius: 50%;
  background:
    conic-gradient(from 0deg, #fff0b7, #d79a19, #fff1b9, #cc8010, #fff0b7),
    radial-gradient(circle, #fff8de 0%, #f0bd43 72%, #b85b16 100%);
  box-shadow: 0 24px 64px rgba(117, 64, 18, 0.26);
}

.wheel-wrap::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
  pointer-events: none;
  z-index: 1;
}

.wheel-wrap::after {
  content: "";
  position: absolute;
  inset: 21px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(126, 58, 16, 0.12);
  pointer-events: none;
  z-index: 2;
}

.pointer {
  position: absolute;
  z-index: 4;
  top: 1px;
  left: 50%;
  width: 0;
  height: 0;
  border-left: 17px solid transparent;
  border-right: 17px solid transparent;
  border-top: 34px solid var(--red);
  transform: translateX(-50%);
  filter: drop-shadow(0 7px 10px rgba(0, 0, 0, 0.2));
}

.wheel {
  position: relative;
  width: 100%;
  height: 100%;
  border: 8px solid #fff;
  border-radius: 50%;
  background: conic-gradient(
    from -36deg,
    #ffe08a 0deg 72deg,
    #ef5a3f 72deg 144deg,
    #ffffff 144deg 216deg,
    #58ad95 216deg 288deg,
    #f7b74c 288deg 360deg
  );
  box-shadow: inset 0 0 0 8px rgba(255, 255, 255, 0.36), inset 0 0 28px rgba(112, 47, 12, 0.12);
  transition: transform 4.6s cubic-bezier(0.16, 0.84, 0.22, 1);
}

.wheel::before {
  content: "";
  position: absolute;
  inset: 18px;
  border: 1px dashed rgba(126, 58, 16, 0.26);
  border-radius: 50%;
}

.prize {
  position: absolute;
  left: 50%;
  top: 50%;
  --prize-distance: -112px;
  width: 88px;
  margin-left: -44px;
  color: #2a2117;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.25;
  text-align: center;
  transform-origin: 50% 0;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.42);
}

.prize-1 {
  --angle: 0deg;
  --reverse-angle: 0deg;
  transform: rotate(var(--angle)) translateY(var(--prize-distance)) rotate(var(--reverse-angle));
}

.prize-2 {
  --angle: 72deg;
  --reverse-angle: -72deg;
  transform: rotate(var(--angle)) translateY(var(--prize-distance)) rotate(var(--reverse-angle));
}

.prize-3 {
  --angle: 144deg;
  --reverse-angle: -144deg;
  transform: rotate(var(--angle)) translateY(var(--prize-distance)) rotate(var(--reverse-angle));
}

.prize-4 {
  --angle: 216deg;
  --reverse-angle: -216deg;
  transform: rotate(var(--angle)) translateY(var(--prize-distance)) rotate(var(--reverse-angle));
}

.prize-5 {
  --angle: 288deg;
  --reverse-angle: -288deg;
  transform: rotate(var(--angle)) translateY(var(--prize-distance)) rotate(var(--reverse-angle));
}

.wheel-center {
  position: absolute;
  inset: 50% auto auto 50%;
  display: grid;
  width: 82px;
  height: 82px;
  place-items: center;
  border: 7px solid #fff;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 26%, #ff9b64, var(--red) 62%, #9d1512 100%);
  color: #fff;
  font-size: 28px;
  font-weight: 900;
  transform: translate(-50%, -50%);
  box-shadow: 0 12px 28px rgba(207, 43, 35, 0.34), inset 0 2px 8px rgba(255, 255, 255, 0.35);
}

.spin-button {
  width: min(100%, 360px);
  justify-self: center;
}

.keypad-backdrop,
.result-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: end center;
  padding: 18px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
  background: rgba(20, 18, 14, 0.48);
}

.keypad,
.result-modal {
  position: relative;
  width: min(100%, 420px);
  max-height: calc(100svh - 32px);
  overflow: auto;
  border-radius: 22px;
  background: var(--panel);
  padding: 24px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.close-button {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: #f1ece6;
  color: #5b544c;
  font-size: 22px;
  line-height: 1;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 22px 0 10px;
}

.pin-dots span {
  width: 18px;
  height: 18px;
  border: 2px solid #d9cec2;
  border-radius: 50%;
  background: #fff;
}

.pin-dots span.filled {
  border-color: var(--red);
  background: var(--red);
}

.keypad-message {
  min-height: 22px;
  margin: 0 0 16px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}

.key-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.key-grid button {
  height: 54px;
  border: 0;
  border-radius: 12px;
  background: #f3eee8;
  color: var(--ink);
  font-size: 20px;
  font-weight: 800;
}

.key-grid button:active {
  transform: scale(0.98);
}

.result-modal {
  place-self: center;
  text-align: center;
}

.result-modal p:not(.eyebrow) {
  margin: 14px 0 22px;
  color: var(--muted);
  line-height: 1.6;
}

.admin-shell {
  width: min(100%, 980px);
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: calc(28px + env(safe-area-inset-top)) 18px calc(42px + env(safe-area-inset-bottom));
}

.admin-hero {
  margin-bottom: 18px;
}

.admin-hero h1 {
  font-size: 32px;
}

.admin-form {
  grid-template-columns: 1fr auto;
  align-items: end;
}

.compact {
  width: 140px;
}

.table-wrap {
  margin-top: 18px;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 800;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 520px) {
  .app-shell {
    padding: calc(14px + env(safe-area-inset-top)) 12px calc(22px + env(safe-area-inset-bottom));
  }

  .topbar,
  .admin-hero {
    margin-bottom: 14px;
  }

  .invite-card,
  .admin-panel {
    border-radius: 16px;
    padding: 18px;
  }

  .friend-line {
    align-items: flex-start;
    gap: 12px;
  }

  .avatar {
    width: 54px;
    height: 54px;
  }

  h1 {
    font-size: 24px;
  }

  .invite-title {
    font-size: clamp(15px, 4.2vw, 19px);
  }

  h2 {
    font-size: 23px;
  }

  .notice {
    margin-bottom: 16px;
    padding: 10px 12px;
  }

  .register-form,
  .admin-form {
    gap: 12px;
  }

  .field input,
  .pin-display,
  .primary-button {
    height: 52px;
  }

  .draw-screen {
    min-height: calc(100svh - 36px);
    gap: 18px;
    padding-top: 18px;
  }

  .wheel-wrap {
    width: min(82vw, 340px);
    padding: 10px;
  }

  .prize {
    --prize-distance: clamp(-106px, -24vw, -88px);
    width: 78px;
    margin-left: -39px;
    font-size: 12px;
  }

  .prize-1,
  .prize-2,
  .prize-3,
  .prize-4,
  .prize-5 {
    transform: rotate(var(--angle)) translateY(var(--prize-distance)) rotate(var(--reverse-angle));
  }

  .admin-form {
    grid-template-columns: 1fr;
  }

  .compact {
    width: 100%;
  }

  .keypad-backdrop {
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .keypad {
    border-radius: 18px;
    padding: 20px;
  }

  .key-grid {
    gap: 8px;
  }

  .key-grid button {
    height: 50px;
  }
}
