:root {
  --bg: #f6fbff;
  --panel: #ffffff;
  --ink: #1f2a37;
  --muted: #5a6b80;
  --border: #d6e4f0;
  --accent: #2d9cdb;
  --accent-soft: #e8f6ff;
  --ok: #1f9d55;
  --warn: #e45757;
  --shadow: 0 10px 24px rgba(24, 56, 94, 0.12);
  --radius: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Nunito", "Trebuchet MS", "Avenir Next", Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(900px 500px at 10% 10%, #dff3ff 0%, transparent 60%),
    radial-gradient(900px 500px at 95% 20%, #dfffe9 0%, transparent 60%),
    var(--bg);
  padding: 18px;
  display: flex;
  justify-content: center;
}

.app {
  width: min(980px, 100%);
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}

header {
  padding: 18px 20px 14px;
  border-bottom: 2px solid var(--border);
  background: linear-gradient(180deg, #ffffff, #f7fcff);
}

h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0.2px;
}

.sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.layout {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 14px;
  padding: 14px;
  align-items: start;
}

.card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px;
}

.title {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 800;
}

.value {
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.hud {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.targets {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.target {
  width: 52px;
  height: 52px;
  border-radius: 999px;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 18px;
  background: #fff;
  position: relative;
}

.target.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.target.done {
  border-color: #9ce6b8;
  background: #e8fff1;
  color: var(--ok);
}

.target.done::after {
  content: "\2713";
  position: absolute;
  right: -4px;
  top: -4px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #e8fff1;
  border: 1px solid #9ce6b8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 900;
}

.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.currentStage {
  margin-top: 14px;
  border: 2px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 16px;
  padding: 10px 12px;
  text-align: center;
}

.currentStage .label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.bigCurrent {
  margin-top: 4px;
  font-size: 56px;
  line-height: 1;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.numCard {
  border: 2px solid var(--border);
  border-radius: 14px;
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: 900;
  cursor: pointer;
  user-select: none;
  background: #fff;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
}

.numCardValue {
  font-size: 40px;
  line-height: 1;
}

.numCard .blocksWrap {
  margin-top: 0;
  min-height: 32px;
  justify-content: center;
}

.numCard .block.hundred {
  width: 18px;
  height: 18px;
}

.numCard .block.ten {
  width: 8px;
  height: 16px;
}

.numCard .block.one {
  width: 6px;
  height: 6px;
}

.numCard:hover { background: #f7fcff; }

.numCard.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.numCard.jokerEligible {
  border-color: #f2a900;
  box-shadow: 0 0 0 2px rgba(242, 169, 0, 0.24);
  animation: jokerPulse 1s ease-in-out infinite;
}

.numCard.disabled {
  opacity: 0.35;
  cursor: not-allowed;
  background: #f6f8fb;
}

@keyframes jokerPulse {
  0% { box-shadow: 0 0 0 1px rgba(242, 169, 0, 0.15); }
  50% { box-shadow: 0 0 0 3px rgba(242, 169, 0, 0.35); }
  100% { box-shadow: 0 0 0 1px rgba(242, 169, 0, 0.15); }
}

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

.jokers {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;
}

.jokerGroup {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  gap: 8px;
}

.jokerGroupTitle {
  font-size: 12px;
  font-weight: 900;
  color: var(--muted);
  text-align: center;
}

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

.jokerBtn {
  width: 58px;
  height: 58px;
  min-height: 58px;
  border-radius: 999px;
  padding: 0;
  font-size: 12px;
  text-align: center;
  line-height: 1.1;
}

.sideStack {
  display: grid;
  gap: 12px;
}

.blocksWrap {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.blockGroup {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  flex-wrap: wrap;
}

.block {
  border: 1px solid #7fb7d9;
  background: #dff3ff;
  border-radius: 3px;
}

.block.hundred {
  width: 28px;
  height: 28px;
}

.block.ten {
  width: 12px;
  height: 24px;
  border-radius: 2px;
  background: #e7f7ff;
}

.block.one {
  width: 9px;
  height: 9px;
  background: #f2fbff;
  border-radius: 2px;
}

button {
  appearance: none;
  border: 2px solid var(--border);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 10px;
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
}

button:hover { background: #f7fcff; }
button:disabled { opacity: 0.35; cursor: not-allowed; }

.ops button.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.jokerBtn.selected {
  border-color: #f2a900;
  background: #fff6df;
}

.msg {
  margin-top: 10px;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #f9fcff;
  min-height: 48px;
  font-size: 14px;
  color: var(--muted);
}

.levelList {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  max-height: 280px;
  overflow: auto;
}

.lvlBtn {
  text-align: left;
  padding: 10px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: #fff;
  cursor: pointer;
}

.lvlBtn strong {
  display: block;
  font-size: 14px;
  margin-bottom: 3px;
}

.lvlBtn small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.lvlBtn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.lvlBtn.locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.footer {
  padding: 0 14px 14px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(13, 29, 44, 0.55);
  padding: 20px;
}

.overlay.show { display: flex; }

body.menuOpen header,
body.menuOpen .layout,
body.menuOpen .footer {
  visibility: hidden;
}

.overlayCard {
  width: min(460px, 100%);
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
}

.overlayCard h2 {
  margin: 0;
  font-size: 24px;
}

.overlayCard p {
  margin: 10px 0 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.menuCard {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: min(88vh, 760px);
}

.menuActions {
  display: grid;
  gap: 10px;
}

#tierRunList {
  display: grid;
  gap: 10px;
}

.tierRunCard {
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
}

.tierRunHead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.tierRunTitle {
  font-size: 14px;
  font-weight: 900;
}

.tierRunMeta {
  font-size: 12px;
  color: var(--muted);
}

.tierRunButtons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

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

.numberPickBtn {
  width: 100%;
  aspect-ratio: 1 / 1;
  min-height: 34px;
  border-radius: 999px;
  font-size: 13px;
  padding: 0;
}

.numberPickBtn.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.menuActions button {
  text-align: left;
  padding: 12px;
  font-size: 16px;
}

.menuPanelBody {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.dangerButton {
  border-color: #8a1d1d;
  background: #ffe9e9;
  color: #5b0f0f;
}

.dangerButton:hover:not(:disabled) {
  background: #ffd5d5;
}

.confirmActions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.menuHidden {
  display: none;
}

.menuLevelBlock {
  margin-top: 14px;
}

.menuLevelBlock h3 {
  margin: 0 0 8px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--muted);
}

.menuJokerList {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
}

.menuJokerItem {
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
}

.menuJokerItem strong {
  display: block;
  font-size: 14px;
}

.menuJokerItem small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.3;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .levelList { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr; }
  .ops { grid-template-columns: repeat(2, 1fr); }
  .jokerGroup {
    grid-template-columns: 26px 1fr;
  }
  .jokerGroupRow {
    justify-content: center;
  }
  .bigCurrent { font-size: 48px; }
  .confirmActions { flex-direction: column; }
}
