:root {
  color-scheme: light;
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --panel: #fbfcff;
  --text: #111318;
  --muted: #5d6472;
  --line: #ccd1dc;
  --line-dark: #7e8491;
  --brand: #2b76d2;
  --brand-dark: #214f93;
  --accent: #f9c226;
  --success: #1d9b63;
  --danger: #e3262e;
  --shadow-soft: 0 18px 46px rgba(28, 35, 56, 0.12);
  --shadow-panel: 0 5px 16px rgba(21, 27, 43, 0.16);
  --radius: 4px;
  --tap: 42px;
  --wheel-size: min(46vw, calc(100vh - 120px));
  --wheel-size-multi: min(100%, 320px);
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: Roboto, Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.42;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.sr-only {
  height: 1px;
  margin: -1px;
  overflow: hidden;
  position: absolute;
  width: 1px;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  align-items: center;
  background: rgba(249, 250, 253, 0.96);
  display: flex;
  gap: 20px;
  justify-content: space-between;
  min-height: 50px;
  padding: 6px 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  color: inherit;
  display: inline-flex;
  text-decoration: none;
}

.brand-text {
  color: #fefefe;
  display: inline-block;
  font-size: 23px;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  text-shadow:
    -1px -1px 0 #6d7077,
    1px -1px 0 #6d7077,
    -1px 1px 0 #6d7077,
    1px 1px 0 #6d7077,
    0 3px 6px rgba(0, 0, 0, 0.22);
  white-space: nowrap;
}

.brand-text span {
  margin-left: 2px;
}

.brand-text span::before {
  background: conic-gradient(#e3262e, #f9c226, #23ab46, #47a8d6, #624992, #e3262e);
  border: 1px solid #fff;
  border-radius: 50%;
  content: "";
  display: inline-block;
  height: 14px;
  margin: 0 2px -1px 0;
  width: 14px;
}

.top-actions {
  align-items: center;
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.lang-switch {
  display: inline-flex;
  gap: 2px;
  margin-right: 4px;
}

.lang-button {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  min-height: 30px;
  min-width: 34px;
  padding: 0 8px;
}

.lang-button.active {
  background: #fff;
  border-color: var(--brand-dark);
  box-shadow: var(--shadow-panel);
}

.toolbar-button,
.mini-tools button,
.clear-button,
.result-dialog button {
  border-radius: var(--radius);
  min-height: var(--tap);
}

.toolbar-button {
  background: transparent;
  border: 0;
  color: #12151c;
  font-size: 15px;
  font-weight: 800;
  padding: 0 9px;
  white-space: nowrap;
}

.toolbar-button:hover,
.toolbar-button.primary {
  background: #fff;
  box-shadow: var(--shadow-panel);
}

.spin-all-button {
  background: #fff;
  border: 1px solid var(--brand-dark);
  box-shadow: var(--shadow-panel);
  color: var(--brand-dark);
  font-weight: 900;
}

.spin-all-button:hover {
  background: var(--brand);
  color: #fff;
}

.spin-all-button[hidden] {
  display: none !important;
}

.workspace {
  margin: 0 auto;
  max-width: 1460px;
  padding: 8px 10px 28px;
}

.tool-surface {
  gap: 16px;
  margin: 0 auto;
  max-width: 1460px;
  width: 100%;
}

.tool-surface.mode-single {
  align-items: stretch;
  display: flex;
  height: calc(100vh - 62px);
  max-height: calc(100vh - 62px);
  min-height: calc(100vh - 62px);
}

.tool-surface.mode-single .wheel-unit {
  align-items: stretch;
  display: flex;
  flex: 1;
  gap: 16px;
  min-height: 0;
  min-width: 0;
  width: 100%;
}

.tool-surface.mode-multi {
  align-content: start;
  align-items: start;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  min-height: calc(100vh - 62px);
  padding-bottom: 8px;
}

.tool-surface.mode-multi .wheel-unit {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc((100% - (var(--cols) - 1) * 16px) / var(--cols));
  max-width: 420px;
  min-width: 0;
}

.wheel-unit {
  min-width: 0;
}

.tool-surface.mode-single .wheel-zone {
  align-content: center;
  display: grid;
  flex: 0 0 50%;
  gap: 8px;
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  max-width: 50%;
  min-height: 0;
  min-width: 0;
}

.tool-surface.mode-multi .wheel-zone {
  display: grid;
  gap: 6px;
  justify-items: center;
  width: 100%;
}

.wheel-stage {
  align-items: center;
  aspect-ratio: 1 / 1;
  cursor: pointer;
  display: grid;
  justify-items: center;
  max-height: 100%;
  overflow: visible;
  position: relative;
  width: min(100%, var(--wheel-size));
}

.tool-surface.mode-multi .wheel-stage {
  width: min(100%, var(--wheel-size-multi));
}

.wheel-canvas {
  aspect-ratio: 1 / 1;
  display: block;
  filter: drop-shadow(0 8px 18px rgba(15, 20, 32, 0.28));
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  width: 100%;
}

.tool-surface.mode-single .wheel-stage {
  height: min(100%, var(--wheel-size));
  max-height: calc(100vh - 130px);
  width: min(100%, var(--wheel-size));
}

.wheel-pointer {
  border-bottom: 30px solid transparent;
  border-right: 48px solid #111318;
  border-top: 30px solid transparent;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.32));
  height: 0;
  left: calc(100% - 7px);
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  z-index: 3;
}

.tool-surface.mode-multi .wheel-pointer {
  border-bottom-width: 18px;
  border-right-width: 28px;
  border-top-width: 18px;
  left: calc(100% - 5px);
}

.spin-hint {
  color: #fff;
  font-size: clamp(24px, 3.2vw, 46px);
  font-weight: 900;
  left: 50%;
  line-height: 1;
  pointer-events: none;
  position: absolute;
  text-shadow:
    -2px -2px 0 rgba(0, 0, 0, 0.62),
    2px -2px 0 rgba(0, 0, 0, 0.62),
    -2px 2px 0 rgba(0, 0, 0, 0.62),
    2px 2px 0 rgba(0, 0, 0, 0.62),
    0 4px 5px rgba(0, 0, 0, 0.35);
  top: 50%;
  transform: translate(-50%, -50%);
  user-select: none;
  z-index: 4;
}

.spin-hint[hidden],
.wheel-stage:not(.has-spin-hint) .spin-hint {
  display: none;
}

.app-shell.is-locked .wheel-unit.is-active-lock .wheel-stage {
  cursor: wait;
}

.result-bar {
  align-items: center;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  min-height: 44px;
  padding: 8px 12px;
  width: 100%;
}

.tool-surface.mode-single .result-bar {
  max-width: var(--wheel-size);
}

.result-bar span {
  color: var(--muted);
  font-weight: 800;
}

.result-bar strong {
  font-size: clamp(18px, 2.3vw, 26px);
  max-width: 66%;
  overflow-wrap: anywhere;
  text-align: right;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-height: 0;
  min-width: 0;
  width: 100%;
}

.tool-surface.mode-single .control-panel {
  align-self: start;
  flex: 0 0 50%;
  max-height: calc(100vh - 80px);
  max-width: 50%;
  overflow-x: hidden;
  overflow-y: auto;
}

.tool-surface.mode-multi .control-panel {
  width: 100%;
}

.control-panel.is-collapsed .panel-body {
  display: none;
}

.panel-body {
  display: grid;
  flex: 0 0 auto;
  min-height: 0;
  width: 100%;
}

.tab-panel {
  display: grid;
  gap: 9px;
  grid-area: 1 / 1;
  width: 100%;
}

.tab-panel[hidden] {
  display: none !important;
}

.app-shell.is-locked .wheel-unit:not(.is-active-lock) {
  opacity: 0.55;
  pointer-events: none;
}

.app-shell.is-locked .wheel-unit.is-active-lock {
  opacity: 1;
}

button:disabled,
.theme-swatch:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.editor-tabs {
  --tab-cols: 4;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  flex-shrink: 0;
  grid-template-columns: repeat(var(--tab-cols), minmax(0, 1fr));
  height: 44px;
  overflow: hidden;
}

.editor-tabs .tab-btn {
  align-items: center;
  background: var(--panel);
  border: 0;
  box-shadow: inset 0 -2px 0 transparent;
  box-sizing: border-box;
  color: #111318;
  display: inline-flex;
  height: 44px;
  justify-content: center;
  max-height: 44px;
  min-height: 44px;
  padding: 0;
  position: relative;
}

.tab-icon-slot {
  align-items: center;
  display: inline-flex;
  height: 20px;
  justify-content: center;
  position: relative;
  width: 20px;
}

.tab-icon {
  display: block;
  flex-shrink: 0;
  height: 20px;
  width: 20px;
}

.tool-icon {
  display: block;
  height: 18px;
  width: 18px;
}

.tab-btn .eye-closed {
  display: none;
}

.tab-btn.is-collapsed-state .eye-open {
  display: none;
}

.tab-btn.is-collapsed-state .eye-closed {
  display: block;
}

.editor-tabs .tab-btn.active {
  background: #fff;
  box-shadow: inset 0 -2px 0 #111318;
}

.tab-badge {
  background: #111318;
  border-radius: 999px;
  color: #fff;
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
  min-width: 14px;
  padding: 2px 4px;
  position: absolute;
  right: -8px;
  top: -7px;
}

.editor-tabs button[hidden],
.add-tab[hidden],
.delete-tab[hidden] {
  display: none !important;
}

.wheel-unit.is-last-wheel .add-tab {
  display: inline-flex;
}

.mini-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-tools button {
  align-items: center;
  display: inline-flex;
  justify-content: center;
  min-width: 38px;
  padding: 0 10px;
}

.entries-section .entries-input {
  min-height: 180px;
  padding-bottom: 42px;
}

.entry-count-pill {
  background: var(--brand);
  border-radius: 999px;
  bottom: 10px;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  padding: 5px 10px;
  pointer-events: none;
  position: absolute;
  right: 10px;
}

.mini-tools button,
.clear-button,
.add-row button {
  background: linear-gradient(#ffffff, #dfe3eb);
  border: 1px solid #b6bdca;
  box-shadow: 0 1px 4px rgba(20, 26, 40, 0.24);
  color: #111318;
  font-size: 13px;
  font-weight: 800;
  min-height: 31px;
  padding: 0 10px;
}

.add-row {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.panel-section {
  display: grid;
  gap: 7px;
}

.section-row {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

label,
.section-row span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

input,
textarea {
  background: #fff;
  border: 1px solid #222936;
  border-radius: var(--radius);
  color: var(--text);
  width: 100%;
}

input {
  min-height: 38px;
  padding: 0 10px;
}

textarea {
  min-height: 180px;
  padding: 11px 13px;
  resize: none;
}

.tool-surface.mode-single textarea {
  min-height: min(360px, calc(100vh - 380px));
}

.tool-surface.mode-single .history-list {
  max-height: min(360px, calc(100vh - 380px));
  min-height: min(360px, calc(100vh - 380px));
}

.theme-section {
  margin-top: 4px;
}

.theme-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(44px, 1fr));
}

.theme-swatch {
  aspect-ratio: 1 / 1;
  border: 2px solid transparent;
  border-radius: 50%;
  height: auto;
  justify-self: center;
  min-height: 0;
  width: 34px;
}

.theme-swatch.active {
  border-color: var(--brand-dark);
  box-shadow: 0 0 0 3px rgba(43, 118, 210, 0.18);
}

.theme-swatch[data-theme="fiesta"] {
  background: conic-gradient(#e3262e, #47a8d6, #ffffff, #f4ee36, #624992, #23ab46, #ed7b13, #e3262e);
}

.theme-swatch[data-theme="ocean"] {
  background: conic-gradient(#053b63, #0f6e9d, #1bb3b0, #a7e8d5, #1d4ed8, #0f766e, #38bdf8, #053b63);
}

.theme-swatch[data-theme="candy"] {
  background: conic-gradient(#eb4d88, #f587a8, #ffcf5b, #7f6de3, #42c5f5, #ff7a59, #9b5de5, #eb4d88);
}

.theme-swatch[data-theme="mono"] {
  background: conic-gradient(#243047, #697386, #c6ccd8, #f5f6fa, #8d95a6, #46546c, #243047);
}

.clear-button {
  justify-self: start;
}

.history-list {
  background: #fff;
  border: 1px solid #222936;
  border-radius: var(--radius);
  list-style-position: inside;
  margin: 0;
  overflow: auto;
  padding: 11px 13px;
}

.history-list li,
.entry-list li {
  color: var(--text);
  font-weight: 800;
  overflow-wrap: anywhere;
  padding: 3px 0;
}

.entry-list {
  background: #fff;
  border: 1px solid #222936;
  border-radius: var(--radius);
  list-style-position: inside;
  margin: 0;
  max-height: 360px;
  min-height: 250px;
  overflow: auto;
  padding: 12px 14px;
}

.result-dialog {
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  max-width: 420px;
  overflow: visible;
  padding: 0;
  position: relative;
  width: calc(100% - 34px);
}

.result-dialog.is-batch {
  max-width: 520px;
}

.result-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.confetti-canvas {
  height: 100%;
  inset: 0;
  pointer-events: none;
  position: fixed;
  width: 100%;
  z-index: 2;
}

.result-form {
  background: #fff;
  border-radius: var(--radius);
  display: grid;
  gap: 16px;
  padding: 18px;
  position: relative;
  z-index: 1;
}

.result-single {
  display: grid;
  gap: 16px;
  text-align: center;
}

.result-single-label {
  color: var(--muted);
  font-weight: 900;
}

.result-single-value {
  font-size: 38px;
  overflow-wrap: anywhere;
}

.result-batch {
  display: grid;
  gap: 12px;
}

.result-batch-title {
  color: var(--text);
  font-size: 28px;
  font-weight: 900;
  margin: 0;
}

.result-batch-list {
  background: #f3f4f7;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  list-style: none;
  margin: 0;
  max-height: min(360px, 58vh);
  overflow: auto;
  padding: 0;
}

.result-batch-item {
  align-items: center;
  border-bottom: 1px solid #d8dde7;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 72px;
  padding: 12px 14px;
}

.result-batch-item:last-child {
  border-bottom: 0;
}

.result-batch-value {
  color: var(--text);
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 900;
  overflow-wrap: anywhere;
  text-align: center;
}

.result-batch-remove {
  background: linear-gradient(#ffffff, #dfe3eb);
  border: 1px solid #b6bdca;
  box-shadow: 0 1px 4px rgba(20, 26, 40, 0.18);
  color: #111318;
  font-size: 13px;
  font-weight: 800;
  min-height: 34px;
  padding: 0 12px;
}

.result-close {
  background: var(--brand);
  border: 1px solid var(--brand-dark);
  color: #fff;
  font-weight: 900;
  justify-self: stretch;
}

.result-dialog.is-batch .result-close {
  background: #fff;
  border: 1px solid #b6bdca;
  box-shadow: 0 2px 8px rgba(20, 26, 40, 0.12);
  color: #111318;
  justify-self: end;
  min-width: 112px;
}

.guide-band {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 18px;
  margin: 18px auto 0;
  max-width: 1460px;
  padding: 22px 24px 26px;
  width: 100%;
}

.guide-title {
  color: var(--text);
  font-size: clamp(24px, 3vw, 32px);
  font-weight: 900;
  line-height: 1.15;
  margin: 0;
}

.guide-intro {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.65;
  margin: 0;
  max-width: 72ch;
}

.guide-block {
  display: grid;
  gap: 10px;
}

.guide-heading {
  color: var(--text);
  font-size: 18px;
  font-weight: 900;
  line-height: 1.25;
  margin: 0;
}

.guide-list {
  color: var(--text);
  display: grid;
  gap: 8px;
  line-height: 1.6;
  margin: 0;
  padding-left: 1.2em;
}

.guide-list li {
  padding-left: 0.2em;
}

@media (max-width: 1120px) {
  :root {
    --wheel-size: min(44vw, calc(100vh - 120px));
    --wheel-size-multi: min(100%, 280px);
  }

  .tool-surface.mode-multi .wheel-unit {
    max-width: 360px;
  }
}

@media (max-width: 720px) {
  :root {
    --wheel-size: min(92vw, calc(100vh - 200px));
    --wheel-size-multi: min(100%, 240px);
  }

  body,
  .app-shell,
  .workspace,
  .tool-surface,
  .wheel-unit,
  .control-panel {
    max-width: 100vw;
    overflow-x: hidden;
  }

  .tool-surface.mode-single {
    flex-direction: column;
    height: auto;
    max-height: none;
    min-height: 0;
  }

  .tool-surface.mode-single .wheel-unit {
    flex-direction: column;
  }

  .tool-surface.mode-single .wheel-zone,
  .tool-surface.mode-single .control-panel {
    flex: none;
    max-width: 100%;
    width: 100%;
  }

  .tool-surface.mode-multi {
    align-items: stretch;
    flex-direction: column;
  }

  .tool-surface.mode-multi .wheel-unit {
    max-width: none;
    width: 100%;
  }

  .tool-surface.mode-multi.cols-2 .wheel-unit,
  .tool-surface.mode-multi.cols-3 .wheel-unit {
    width: 100%;
  }

  .guide-band {
    margin-left: 10px;
    margin-right: 10px;
    padding: 18px 16px 22px;
  }

  .guide-intro {
    font-size: 15px;
  }

  .topbar {
    align-items: stretch;
    gap: 8px;
    min-height: auto;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .brand-text {
    font-size: 22px;
  }

  .top-actions {
    display: grid;
    flex: 1 1 auto;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    min-width: 0;
  }

  .top-actions {
    display: none;
  }

  .toolbar-button {
    font-size: 12px;
    min-height: 34px;
    overflow: hidden;
    padding: 0 4px;
    text-overflow: ellipsis;
  }

  .workspace {
    padding: 0 0 18px;
  }

  .tool-surface {
    gap: 12px;
  }

  .wheel-stage {
    width: min(100%, var(--wheel-size));
  }

  .tool-surface.mode-multi .wheel-stage {
    width: min(100%, var(--wheel-size-multi));
  }

  .wheel-pointer {
    border-bottom-width: 22px;
    border-right-width: 36px;
    border-top-width: 22px;
  }

  .spin-hint {
    font-size: 24px;
  }

  .result-bar {
    justify-content: flex-start;
    margin: 0 10px;
    min-width: 0;
    width: calc(100% - 20px);
  }

  .result-bar strong {
    flex: 0 1 auto;
    margin-left: 14px;
    max-width: none;
    padding-right: 0;
    text-align: left;
  }

  .control-panel {
    padding: 0 10px;
  }

  textarea {
    min-height: 220px;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .toolbar-button {
    font-size: 11px;
    white-space: normal;
  }

  .toolbar-button.primary {
    display: none;
  }

  #copyShare {
    display: none;
  }

  .top-actions .toolbar-button:nth-child(3) {
    display: none;
  }

}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }

  .confetti-canvas {
    display: none;
  }
}
