:root {
  --bg: #f5f8fd;
  --surface: #ffffff;
  --surface-alt: #eef4fb;
  --text: #272829;
  --text-muted: #6c7a89;
  --heading: #173b6c;
  --accent: #149ddd;
  --accent-hover: #37b3ed;
  --accent-soft: #e4f3fb;
  --border: #dde6f0;
  --shadow: 0 2px 15px rgba(0, 0, 0, 0.08);
  --success: #2e9e5b;
  --success-soft: #e3f5ea;
  --danger: #d64545;
  --gold: #e0a100;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1320;
  --surface: #101b2c;
  --surface-alt: #16263d;
  --text: #c9d1d9;
  --text-muted: #8b98a8;
  --heading: #e6edf3;
  --accent: #37b3ed;
  --accent-hover: #6cc8f2;
  --accent-soft: #16263d;
  --border: #1f3350;
  --shadow: 0 2px 15px rgba(0, 0, 0, 0.4);
  --success: #4cc685;
  --success-soft: #143424;
  --danger: #f07070;
  --gold: #f2c94c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Open Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}

[hidden] {
  display: none !important;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #040b14;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: "Poppins", sans-serif;
  font-weight: 500;
  color: #fff;
}

.back-link:hover {
  color: #37b3ed;
}

.theme-toggle {
  border: 0;
  font-size: 18px;
  background-color: #149ddd;
  color: #fff;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.theme-toggle:hover {
  background-color: #2eafec;
}

.theme-toggle .bi-sun,
[data-theme="dark"] .theme-toggle .bi-moon-stars {
  display: none;
}

[data-theme="dark"] .theme-toggle .bi-sun {
  display: inline;
}

/* Title */
.page-title {
  text-align: center;
  padding: 36px 16px 24px;
}

.page-title h1 {
  font-family: "Raleway", sans-serif;
  font-size: 32px;
  font-weight: 700;
  color: var(--heading);
  margin: 0 0 20px;
  padding-bottom: 20px;
  position: relative;
}

.page-title h1::after {
  content: "";
  position: absolute;
  width: 50px;
  height: 3px;
  background: var(--accent);
  bottom: 0;
  left: calc(50% - 25px);
}

.page-title p {
  margin: 0;
  color: var(--text-muted);
}

/* Layout: menu + current tool */
.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px 32px;
}

.tool-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-self: start;
  position: sticky;
  top: 16px;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 8px;
}

.tool-menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--text);
  font-family: "Poppins", sans-serif;
  font-size: 15px;
  white-space: nowrap;
  transition: background-color 0.2s, color 0.2s;
}

.tool-menu a i {
  font-size: 18px;
  color: var(--accent);
}

.tool-menu a:hover {
  background: var(--surface-alt);
}

.tool-menu a[aria-current="page"] {
  background: #149ddd;
  color: #fff;
}

.tool-menu a[aria-current="page"] i {
  color: #fff;
}

.tool h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "Raleway", sans-serif;
  font-weight: 700;
  font-size: 26px;
  color: var(--heading);
  margin: 0 0 6px;
}

.tool h2 i {
  color: var(--accent);
}

.tool-desc {
  margin: 0 0 20px;
  color: var(--text-muted);
}

/* Cards and forms */
.card {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.card h3 {
  font-family: "Poppins", sans-serif;
  font-weight: 600;
  font-size: 18px;
  color: var(--heading);
  margin: 0 0 12px;
}

.card.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.field-label,
.fields label,
.range-label {
  font-family: "Poppins", sans-serif;
  font-weight: 500;
  font-size: 14px;
  color: var(--heading);
}

.field-label {
  display: block;
  margin-bottom: 8px;
}

textarea,
input[type="number"],
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: "Open Sans", sans-serif;
  font-size: 15px;
}

textarea {
  resize: vertical;
  min-height: 120px;
}

textarea:focus,
input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 157, 221, 0.2);
}

.list-info {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.fields {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}

.fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 140px;
  text-align: left;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 14px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 15px;
}

.check input {
  width: 17px;
  height: 17px;
  accent-color: #149ddd;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 50px;
  padding: 9px 22px;
  font-family: "Poppins", sans-serif;
  font-weight: 500;
  font-size: 15px;
  cursor: pointer;
  transition: background-color 0.3s, color 0.3s;
}

.btn-lg {
  padding: 12px 36px;
  font-size: 17px;
}

.btn-primary {
  background: #149ddd;
  color: #fff;
}

.btn-primary:hover {
  background: #2eafec;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: wait;
}

.btn-secondary {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-secondary:hover {
  background: var(--border);
}

[data-theme="dark"] .btn-secondary {
  background: #1f3350;
  color: #e6edf3;
}

[data-theme="dark"] .btn-secondary:hover {
  background: #2a4468;
}

.btn.copied,
.icon-btn.copied {
  color: var(--success);
}

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 18px;
  width: 38px;
  height: 38px;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--accent-soft);
}

/* Results */
.result:empty {
  display: none;
}

.result {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.error {
  margin: 0;
  color: var(--danger);
  font-weight: 600;
}

.stats {
  margin: 10px 0 0;
  font-size: 14px;
  color: var(--text-muted);
}

.big-number span,
.big-word {
  display: block;
  text-align: center;
  font-family: "Poppins", sans-serif;
  font-weight: 600;
  font-size: 56px;
  line-height: 1.2;
  color: var(--accent);
  word-break: break-word;
}

.big-word {
  font-size: 36px;
}

.winner-label {
  margin: 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.number-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.number-list span {
  min-width: 52px;
  padding: 6px 12px;
  border-radius: 6px;
  text-align: center;
  font-family: "Poppins", sans-serif;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: var(--accent-soft);
  color: var(--accent);
}

.list-title {
  font-family: "Poppins", sans-serif;
  font-weight: 600;
  color: var(--heading);
  margin: 0 0 8px;
}

.list-title:not(:first-child) {
  margin-top: 16px;
}

.ranked {
  margin: 0;
  padding-left: 0;
  list-style: none;
  counter-reset: rank;
}

.ranked li {
  counter-increment: rank;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
}

.ranked li:last-child {
  border-bottom: 0;
}

.ranked li::before {
  content: counter(rank);
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "Poppins", sans-serif;
  font-weight: 600;
  font-size: 14px;
  background: var(--accent-soft);
  color: var(--accent);
}

.ranked.winners li {
  font-weight: 600;
  font-size: 17px;
}

.ranked.winners li::before {
  background: var(--gold);
  color: #3a2a00;
}

/* Roulette */
.roulette-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 20px;
  align-items: start;
}

.roulette-layout .card {
  margin-bottom: 0;
}

.wheel-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.wheel-area .result {
  width: 100%;
}

.wheel-wrap {
  position: relative;
  width: 100%;
  max-width: 420px;
}

.wheel-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.18));
}

.wheel-pointer {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 16px solid transparent;
  border-right: 16px solid transparent;
  border-top: 30px solid var(--heading);
  z-index: 1;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.3));
}

/* Groups */
.groups-result {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

.group-card {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
  border-top: 4px solid #149ddd;
  padding: 16px;
}

.group-card h4 {
  font-family: "Poppins", sans-serif;
  font-weight: 600;
  font-size: 17px;
  color: var(--heading);
  margin: 0 0 8px;
}

.group-card ul {
  margin: 0;
  padding-left: 18px;
}

.group-card li {
  padding: 2px 0;
  word-break: break-word;
}

.groups-result .error {
  grid-column: 1 / -1;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

/* Coin & dice */
.two-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
}

.two-cols .card {
  margin-bottom: 0;
}

.coin {
  width: 130px;
  height: 130px;
  margin: 8px 0 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 35% 30%, #ffe48a, #e0a100 70%);
  box-shadow: inset 0 0 0 6px rgba(255, 255, 255, 0.35), 0 4px 12px rgba(0, 0, 0, 0.2);
  color: #5a3d00;
  font-family: "Poppins", sans-serif;
  font-weight: 600;
  font-size: 20px;
}

.coin.flipping {
  animation: coin-flip 0.5s ease-in-out;
}

@keyframes coin-flip {
  0% { transform: rotateY(0) scale(1); }
  50% { transform: rotateY(900deg) scale(1.15); }
  100% { transform: rotateY(1800deg) scale(1); }
}

.dice {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  min-height: 60px;
  margin: 16px 0;
}

.die {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 2px solid var(--accent);
  color: var(--heading);
  font-family: "Poppins", sans-serif;
  font-weight: 600;
  font-size: 22px;
  box-shadow: 0 3px 0 var(--accent);
}

.dice .error {
  align-self: center;
}

/* Password */
.password-output {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 6px 10px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.password-output code {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 18px;
  color: var(--heading);
  word-break: break-all;
}

.password-output code.muted {
  font-family: "Open Sans", sans-serif;
  font-size: 15px;
  color: var(--text-muted);
}

#password-strength[data-level="weak"] { color: var(--danger); }
#password-strength[data-level="fair"] { color: var(--gold); }
#password-strength[data-level="strong"],
#password-strength[data-level="very-strong"] { color: var(--success); }

.range-label {
  display: block;
  margin-top: 16px;
}

.range-label input {
  display: block;
  width: 100%;
  margin-top: 8px;
  accent-color: #149ddd;
}

/* Tournament */
#tournament-result {
  overflow-x: auto;
}

.bracket {
  display: flex;
  gap: 28px;
  min-width: min-content;
}

.bracket-round {
  display: flex;
  flex-direction: column;
  min-width: 170px;
}

.bracket-round h4 {
  font-family: "Poppins", sans-serif;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  text-align: center;
  margin: 0 0 12px;
}

.bracket-matches {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  gap: 12px;
}

.match {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}

.player {
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 8px 12px;
  font-family: "Open Sans", sans-serif;
  font-size: 14px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

.player + .player {
  border-top: 1px solid var(--border);
}

.player:not(:disabled):hover {
  background: var(--accent-soft);
}

.player:disabled {
  cursor: default;
}

.player.won {
  background: var(--success-soft);
  color: var(--success);
  font-weight: 700;
}

.player.lost {
  color: var(--text-muted);
  text-decoration: line-through;
}

.player.bye,
.player.tbd {
  color: var(--text-muted);
  font-style: italic;
}

.champion-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px;
  border-radius: 8px;
  border: 2px dashed var(--border);
  color: var(--text-muted);
  font-family: "Poppins", sans-serif;
  font-weight: 600;
  text-align: center;
  word-break: break-word;
}

.champion-box i {
  font-size: 32px;
}

.champion-box.has-winner {
  border: 2px solid var(--gold);
  color: var(--heading);
}

.champion-box.has-winner i {
  color: var(--gold);
}

.footer {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  padding: 0 16px 32px;
}

/* Small screens: the menu becomes a horizontal, scrollable bar */
@media (max-width: 860px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }

  .tool-menu {
    flex-direction: row;
    overflow-x: auto;
    position: static;
    scrollbar-width: thin;
  }

  .tool-menu a {
    padding: 8px 12px;
    font-size: 14px;
  }

  .roulette-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .roulette-layout .wheel-area {
    order: -1;
  }

  .big-number span {
    font-size: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .coin.flipping {
    animation: none;
  }
}

.card.center .fields {
  align-self: stretch;
}
