.wheel-app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.wheel-rules-button { white-space: nowrap; }
.wheel-header-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.wheel-rules-dialog input[type="text"] { width: 100%; min-height: 44px; padding: 8px 12px; border: 2px solid rgba(23, 19, 49, .25); border-radius: 10px; font: inherit; }
.wheel-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(290px, 350px); gap: 12px; min-height: 0; }
.wheel-stage, .wheel-panel { min-width: 0; min-height: 0; border: 2px solid #171331; border-radius: 16px; box-shadow: var(--shadow); }
.wheel-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  overflow: hidden;
  padding: 16px;
  background: #fffaf0;
}
.wheel-graphic { position: relative; width: min(100%, 60dvh, 650px); aspect-ratio: 1; flex: 0 1 auto; min-height: 0; }
.wheel-disc { width: 100%; height: 100%; border: 5px solid #171331; border-radius: 50%; overflow: hidden; background: #eee9ff; box-shadow: 0 12px 22px rgba(23, 19, 49, .2); }
.wheel-disc canvas { display: block; width: 100%; height: 100%; }
.wheel-pointer {
  position: absolute;
  z-index: 2;
  top: -6px;
  left: 50%;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 18px solid transparent;
  border-right: 18px solid transparent;
  border-top: 36px solid #171331;
  filter: drop-shadow(0 2px 1px #fff);
}
.wheel-result { min-height: 1.5em; max-width: 100%; margin: 0; color: #171331; font-size: clamp(1.25rem, 2.8vw, 2.5rem); font-weight: 850; text-align: center; overflow-wrap: anywhere; }
.wheel-result.is-picked { color: #5320d8; }
.wheel-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; width: 100%; }
.wheel-controls .timer-button { min-width: 145px; }
.wheel-controls .wheel-spin { min-width: 175px; background: #ffd23f; }
.wheel-panel { display: flex; flex-direction: column; gap: 10px; padding: 20px; background: #fff; }
.wheel-panel h2 { margin: 0; font-size: 1.65rem; }
.wheel-help { margin: 8px 0 0; color: #514d64; line-height: 1.35; }
.wheel-rule-description { margin: 7px 0 0; color: #5320d8; font-size: .85rem; font-weight: 800; line-height: 1.3; }
.wheel-panel label { font-weight: 800; }
.wheel-panel textarea {
  flex: 1 1 auto;
  min-height: 120px;
  width: 100%;
  padding: 12px;
  border: 2px solid rgba(23, 19, 49, .25);
  border-radius: 10px;
  color: #171331;
  background: #fff;
  font: inherit;
  font-size: 1rem;
  line-height: 1.5;
  resize: none;
}
.wheel-panel textarea:focus-visible, .wheel-panel button:focus-visible, .wheel-controls button:focus-visible { outline: 3px solid #6d38ff; outline-offset: 2px; }
.wheel-count { margin: 0; color: #514d64; font-weight: 750; }
.wheel-error { min-height: 1.2em; margin: 0; color: #b42332; font-weight: 700; }
.wheel-sample { align-self: flex-start; }
.wheel-panel-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.wheel-panel-actions .timer-button { min-height: 39px; padding: 0 9px; font-size: .78rem; }
.wheel-rules-dialog { width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; padding: 0; border: 3px solid #171331; border-radius: 16px; color: #171331; background: #fff; box-shadow: var(--shadow); }
.wheel-rules-dialog::backdrop { background: rgba(0, 0, 0, .65); }
.wheel-rules-dialog form { display: grid; gap: 16px; padding: 24px; }
.wheel-rules-dialog h2 { margin: 0; font-size: 1.7rem; }
.wheel-rule-options { display: grid; gap: 8px; margin: 0; padding: 0; border: 0; }
.wheel-rule-options legend { margin-bottom: 8px; font-weight: 850; }
.wheel-rule-options label, .wheel-drop-option { display: flex; align-items: flex-start; gap: 10px; padding: 10px; border: 2px solid rgba(23, 19, 49, .15); border-radius: 9px; cursor: pointer; }
.wheel-rule-options label:has(input:checked), .wheel-drop-option:has(input:checked) { border-color: #6d38ff; background: #f2edff; }
.wheel-rule-options input, .wheel-drop-option input { flex: 0 0 auto; width: 19px; height: 19px; margin: 2px 0 0; accent-color: #6d38ff; }
.wheel-rule-options label span { display: grid; gap: 3px; }
.wheel-rule-options small { color: #514d64; line-height: 1.35; }
.wheel-rules-note { margin: 0; color: #514d64; line-height: 1.4; }
.wheel-rules-dialog button { justify-self: end; min-width: 110px; }
.wheel-rules-dialog input:focus-visible, .wheel-rules-dialog button:focus-visible, .wheel-rules-button:focus-visible { outline: 3px solid #6d38ff; outline-offset: 2px; }

@media (max-width: 900px) and (orientation: portrait) {
  .wheel-app { gap: 8px; padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  .wheel-layout { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) minmax(185px, 30dvh); gap: 8px; }
  .wheel-graphic { width: min(64dvh, 100%, 580px); }
  .wheel-stage { gap: 7px; padding: 10px; }
  .wheel-panel { display: grid; grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr) auto auto; gap: 5px; padding: 10px; }
  .wheel-panel > div { grid-column: 1 / -1; }
  .wheel-panel label { display: none; }
  .wheel-panel textarea { grid-column: 1 / -1; grid-row: 2; min-height: 0; }
  .wheel-count { align-self: center; }
  .wheel-error { grid-column: 1 / -1; min-height: 0; }
  .wheel-panel-actions { grid-column: 1 / -1; gap: 4px; }
  .wheel-panel-actions .timer-button { min-height: 34px; font-size: .72rem; }
}

@media (max-width: 600px) and (orientation: portrait) {
  .wheel-header { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; }
  .wheel-header-actions { margin-left: auto; gap: 4px; }
  .wheel-header-actions .timer-button { min-height: 36px; padding: 0 6px; font-size: .68rem; }
  .wheel-header .timer-kicker { display: none; }
  .wheel-header .tool-heading { justify-content: flex-start; }
  .wheel-header h1 { font-size: 1rem; }
  .wheel-graphic { width: min(48dvh, 100%); }
  .wheel-controls { gap: 5px; }
  .wheel-controls .timer-button { min-width: 0; min-height: 42px; padding: 0 9px; font-size: .78rem; }
  .wheel-controls .wheel-spin { min-width: 88px; }
  .wheel-panel h2 { font-size: 1.2rem; }
  .wheel-help { margin: 2px 0 0; font-size: .75rem; }
  .wheel-rule-description { margin: 2px 0 0; font-size: .69rem; }
  .wheel-panel textarea { font-size: .86rem; }
  .wheel-count, .wheel-error { font-size: .75rem; }
}

@media (max-width: 600px) and (max-height: 700px) and (orientation: portrait) {
  .wheel-graphic { width: min(42dvh, 100%); }
  .wheel-layout { grid-template-rows: minmax(0, 1fr) minmax(170px, 30dvh); }
}

@media (max-height: 600px) and (orientation: landscape) {
  .wheel-app { gap: 6px; padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left)); }
  .wheel-header { min-height: 44px; padding: 4px 8px; }
  .wheel-header .timer-kicker { display: none; }
  .wheel-layout { gap: 6px; grid-template-columns: minmax(0, 1fr) minmax(220px, 280px); }
  .wheel-stage { gap: 4px; padding: 5px; }
  .wheel-graphic { width: min(60dvh, 70%, 500px); }
  .wheel-result { font-size: 1.25rem; min-height: 1.2em; }
  .wheel-controls .timer-button { min-width: 110px; min-height: 36px; font-size: .75rem; }
  .wheel-panel { gap: 5px; padding: 9px; }
  .wheel-panel h2 { font-size: 1.15rem; }
  .wheel-help { margin-top: 2px; font-size: .72rem; }
  .wheel-rule-description { margin-top: 2px; font-size: .69rem; }
  .wheel-panel textarea { min-height: 0; padding: 6px; font-size: .8rem; }
  .wheel-count, .wheel-error { font-size: .72rem; }
  .wheel-sample { min-height: 34px; font-size: .72rem; }
  .wheel-panel-actions .timer-button { min-height: 30px; font-size: .68rem; }
}

@media (prefers-reduced-motion: reduce) {
  .wheel-disc { transition-duration: 0.01ms !important; }
}
