:root {
  --viewport-height: 100dvh;
  --pointer-color: var(--mn-red);
  --pointer-shadow-color: rgba(117, 27, 27, 0.24);
}

[hidden] {
  display: none !important;
}

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

body {
  min-height: 0;
}

.tool-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  width: min(var(--mn-container), calc(100% - 20px));
  height: var(--viewport-height);
  min-height: 0;
  margin: 0 auto;
  padding: 8px 0 5px;
  overflow: hidden;
}

.tool-header {
  min-height: 58px;
  padding: 7px 12px;
  border-radius: 18px;
}

.tool-header .mn-brand img {
  width: clamp(92px, 12vw, 118px);
}

.tool-header .mn-title h1 {
  font-size: clamp(1.55rem, 2.5vw, 2.1rem);
}

.tool-intro {
  max-width: none;
  margin: 5px auto 7px;
}

.tool-intro p {
  font-size: clamp(0.88rem, 1.5vw, 1rem);
  line-height: 1.35;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: 12px;
  align-items: stretch;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.wheel-card,
.names-card {
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: clamp(10px, 1.4vw, 16px);
  overflow: hidden;
}

.wheel-card {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

.wheel-stage {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 4px 38px 4px 4px;
  overflow: hidden;
}

.wheel-visual {
  position: relative;
  flex: none;
  width: 320px;
  height: 320px;
}

#wheel-canvas {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  border-radius: 50%;
  filter: drop-shadow(0 14px 22px rgba(31, 54, 58, 0.15));
}

.pointer {
  position: absolute;
  top: 50%;
  right: -31px;
  z-index: 2;
  width: 0;
  height: 0;
  border-top: clamp(15px, 3.2vmin, 22px) solid transparent;
  border-bottom: clamp(15px, 3.2vmin, 22px) solid transparent;
  border-right: clamp(25px, 5vmin, 36px) solid var(--pointer-color);
  filter: drop-shadow(0 7px 9px var(--pointer-shadow-color));
  transform: translateY(-50%);
  transition:
    border-right-color 140ms linear,
    filter 180ms ease;
}

.spin-button {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 3;
  display: grid;
  place-items: center;
  width: clamp(92px, 22%, 126px);
  height: clamp(92px, 22%, 126px);
  padding: 12px;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 34%, #fffdf6 0 34%, #ffe6a5 70%, var(--mn-accent) 100%);
  color: var(--mn-teal);
  font-size: clamp(0.92rem, 2.5vmin, 1.22rem);
  font-weight: 900;
  line-height: 1.05;
  text-align: center;
  text-transform: uppercase;
  box-shadow:
    inset 0 4px 8px rgba(255, 255, 255, 0.72),
    inset 0 -6px 10px rgba(137, 93, 16, 0.14),
    0 0 0 6px rgba(255, 255, 255, 0.92),
    0 0 0 9px rgba(242, 140, 40, 0.26),
    0 8px 18px rgba(31, 54, 58, 0.12);
  transform: translate(-50%, -50%);
  transition:
    box-shadow 0.18s ease,
    filter 0.18s ease,
    opacity 0.18s ease;
}

.spin-button:hover:not(:disabled),
.spin-button:focus-visible:not(:disabled) {
  outline: none;
  filter: brightness(1.03);
  box-shadow:
    inset 0 4px 8px rgba(255, 255, 255, 0.82),
    inset 0 -6px 10px rgba(137, 93, 16, 0.12),
    0 0 0 7px rgba(255, 255, 255, 0.96),
    0 0 0 11px rgba(242, 140, 40, 0.38),
    0 8px 18px rgba(31, 54, 58, 0.14);
}

.spin-button:disabled {
  cursor: not-allowed;
  filter: saturate(0.85);
}

.status-strip {
  display: grid;
  place-items: center;
  min-height: 27px;
  margin-top: 2px;
}

.status-strip .message {
  min-height: 0;
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.25;
  text-align: center;
}

.names-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.names-head {
  align-items: center;
  margin-bottom: 9px;
}

.names-head-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  min-width: 0;
  flex-wrap: wrap;
}

.names-head .pill {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.88rem;
}

.clear-button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid rgba(217, 78, 69, 0.3);
  border-radius: 999px;
  background: #fff;
  color: var(--mn-red);
  font-size: 0.82rem;
  font-weight: 800;
}

.clear-button:hover,
.clear-button:focus-visible {
  outline: none;
  border-color: var(--mn-red);
  box-shadow: 0 0 0 4px rgba(217, 78, 69, 0.12);
}

.names-card .controls-fieldset,
.names-stack {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex: 1;
  flex-direction: column;
}

.names-card .controls-fieldset {
  overflow: hidden;
}

.names-stack {
  gap: 6px;
}

.input-label {
  font-size: 0.92rem;
}

#name-input {
  min-height: 0;
  flex: 1;
  padding: 10px 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  resize: none;
  scrollbar-gutter: stable;
}

.storage-note,
.field-error {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.25;
}

.storage-note {
  color: var(--mn-ink-soft);
}

.storage-note.is-error,
.field-error {
  color: #b42318;
  font-weight: 700;
}

.mobile-view-switcher {
  display: none;
}

.tool-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 24px;
  margin: 0;
  padding: 3px 8px 0;
  font-size: 0.76rem;
  line-height: 1.2;
}

.tool-footer a {
  color: var(--mn-teal);
  font-weight: 800;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(20, 37, 40, 0.48);
}

.modal-card {
  position: relative;
  width: min(100%, 520px);
  max-height: calc(var(--viewport-height) - 32px);
  padding: clamp(22px, 5vw, 30px);
  overflow-y: auto;
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--mn-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--mn-ink-soft);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(31, 54, 58, 0.08);
}

.modal-close:hover,
.modal-close:focus-visible {
  outline: none;
  color: var(--mn-ink);
  box-shadow: var(--mn-focus);
}

.modal-kicker {
  margin: 0;
  color: var(--mn-accent-dark);
  font-size: 0.9rem;
  font-weight: 900;
  text-transform: uppercase;
}

.result-name {
  --result-accent: var(--mn-teal);
  --result-accent-soft: rgba(15, 89, 97, 0.1);
  --result-accent-glow: rgba(15, 89, 97, 0.2);
  display: inline-block;
  margin: 12px 0 10px;
  padding: 0.14em 0.34em;
  border: 2px solid transparent;
  border-radius: var(--mn-radius-lg);
  font-size: clamp(2rem, 6vw, 3rem);
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.result-name.is-winner {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.97), rgba(255, 255, 255, 0.92)) padding-box,
    conic-gradient(
      from 200deg,
      var(--result-accent) 0deg,
      #ffd75a 72deg,
      #6fd6c6 150deg,
      #7b61c8 225deg,
      #ff8aa6 300deg,
      var(--result-accent) 360deg
    ) border-box;
  color: var(--result-accent);
  box-shadow: 0 10px 24px rgba(31, 54, 58, 0.08);
}

.result-name.winner-flash {
  animation: winner-name-pulse 1000ms ease-out 1;
}

@keyframes winner-name-pulse {
  0%,
  30%,
  100% {
    transform: scale(1);
  }

  15% {
    transform: scale(1.02);
    box-shadow:
      0 0 0 7px var(--result-accent-soft),
      0 0 30px var(--result-accent-glow),
      0 12px 28px rgba(31, 54, 58, 0.12);
  }
}

.modal-copy {
  margin: 0;
  color: var(--mn-ink-soft);
  line-height: 1.5;
}

.modal-actions {
  display: grid;
  gap: 11px;
  margin-top: 22px;
}

.btn-large {
  width: 100%;
}

@media (max-width: 820px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 7px;
  }

  .mobile-view-switcher {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-height: 42px;
    border: 1px solid var(--mn-line);
    border-radius: 15px;
    overflow: hidden;
    background: #fff;
  }

  .view-button {
    min-height: 42px;
    padding: 0 12px;
    border: 0;
    background: #fff;
    color: var(--mn-teal);
    font-weight: 900;
  }

  .view-button[aria-pressed="true"] {
    background: var(--mn-teal);
    color: #fff;
  }

  .view-button:focus-visible {
    position: relative;
    z-index: 1;
    outline: 3px solid var(--mn-accent);
    outline-offset: -3px;
  }

  .view-count {
    font-size: 0.85em;
  }

  .wheel-card,
  .names-card {
    grid-column: 1;
    grid-row: 2;
  }

  #tool-main[data-active-view="wheel"] .names-card,
  #tool-main[data-active-view="names"] .wheel-card {
    display: none;
  }

  .wheel-stage {
    padding-right: 35px;
  }

  .names-head {
    display: flex;
  }
}

@media (max-width: 640px) {
  .tool-shell {
    width: min(100% - 14px, var(--mn-container));
    padding-top: 6px;
  }

  .tool-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
    min-height: 54px;
    padding: 6px 9px;
  }

  .tool-header .mn-header-left,
  .tool-header .mn-header-actions {
    align-self: center;
  }

  .tool-header .mn-title {
    grid-column: auto;
    order: initial;
    justify-self: center;
  }

  .tool-header .mn-brand img {
    width: 82px;
  }

  .tool-header .mn-title h1 {
    font-size: clamp(1.35rem, 7vw, 1.75rem);
  }

  .tool-intro {
    margin: 4px auto 5px;
  }

  .tool-intro p {
    font-size: 0.82rem;
  }

  .wheel-card,
  .names-card {
    padding: 10px;
    border-radius: 17px;
  }

  .wheel-stage {
    padding: 2px 32px 2px 2px;
  }

  .pointer {
    right: -27px;
  }

  .names-head-actions {
    gap: 5px;
  }

  .clear-button,
  .names-head .pill {
    min-height: 32px;
    font-size: 0.78rem;
  }

  .tool-footer {
    gap: 5px;
    font-size: 0.68rem;
  }
}

@media (max-width: 340px), (max-height: 440px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .tool-shell {
    height: auto;
    min-height: 600px;
    overflow: visible;
  }

  .layout {
    min-height: 440px;
    overflow: visible;
  }
}

@media (prefers-reduced-motion: reduce) {
  .result-name.winner-flash {
    animation: none;
  }
}
