:root {
  --bg: #0f1320;
  --panel: #1a2032;
  --card: #232b40;
  --card-hover: #2b3450;
  --text: #eef1f8;
  --subtle: #9aa3bd;
  --accent: #5b8cff;
  --green: #4caf6e;
  --yellow: #d4a032;
  --gray: #4a5168;
  --red: #c0463b;
  --border: #313a55;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  max-width: 520px;
  margin: 0 auto;
}

.logo {
  font-size: 1.5rem;
  letter-spacing: 0.35em;
  margin: 0;
  font-weight: 800;
  background: linear-gradient(90deg, #5b8cff, #8e6bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.icon-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 1rem;
  cursor: pointer;
}
.icon-btn:hover { background: var(--card-hover); }

.game {
  max-width: 520px;
  margin: 0 auto;
  padding: 18px 16px 40px;
  text-align: center;
}

.puzzle-no {
  color: var(--subtle);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 4px 0;
}

.prompt {
  font-size: 1.2rem;
  margin: 6px 0 4px;
  line-height: 1.3;
}

.subtle { color: var(--subtle); font-size: 0.85rem; margin: 4px 0; }
.subtle.result-line {
  display: inline-block;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  margin: 10px 0 6px;
  padding: 8px 18px;
  border-radius: 999px;
  background: linear-gradient(90deg, #5b8cff, #8e6bff);
  box-shadow: 0 4px 14px rgba(91, 140, 255, 0.3);
}

.board {
  list-style: none;
  padding: 0;
  margin: 18px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 12px;
  transition: background 0.15s, border-color 0.15s;
  cursor: grab;
  user-select: none;
}
.row:hover { background: var(--card-hover); }
.row.dragging { opacity: 0.4; }
.row.over { border-color: var(--accent); }
.row.locked { cursor: default; }

.rank {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  border-radius: 50%;
  background: var(--panel);
  color: var(--subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
}

.name {
  flex: 1;
  text-align: left;
  font-size: 1.02rem;
}

.value {
  color: var(--subtle);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.arrows { display: flex; flex-direction: column; gap: 2px; }
.arrow {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  width: 30px;
  height: 20px;
  line-height: 1;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.7rem;
}
.arrow:hover { background: var(--accent); }
.arrow:disabled { opacity: 0.3; cursor: default; }

.row.fb-g { background: var(--green); border-color: var(--green); }
.row.fb-y { background: var(--yellow); border-color: var(--yellow); color: #1a1a1a; }
.row.fb-x { background: var(--red); border-color: var(--red); }
.row.fb-g .rank, .row.fb-y .rank, .row.fb-x .rank { background: rgba(0,0,0,0.2); color: #fff; }
.row.fb-y .value { color: #2a2a2a; }
.row.fb-g .value, .row.fb-x .value { color: rgba(255, 255, 255, 0.95); }

.actions { margin: 14px 0; }

.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 12px 28px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}
.primary:hover { filter: brightness(1.08); }
.primary:disabled { background: var(--gray); cursor: default; }
.primary.share {
  background: linear-gradient(90deg, #5b8cff, #8e6bff);
}
.primary.share:hover { filter: brightness(1.08); }

.legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--subtle);
  font-size: 0.8rem;
  margin-top: 8px;
}
.swatch {
  display: inline-block;
  width: 13px;
  height: 13px;
  border-radius: 3px;
  vertical-align: -2px;
  margin-right: 3px;
}
.swatch.g { background: var(--green); }
.swatch.y { background: var(--yellow); }
.swatch.x { background: var(--red); }

.footer {
  margin-top: 28px;
  text-align: center;
}
.kofi {
  display: inline-block;
  text-decoration: none;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 0.9rem;
  transition: background 0.15s, transform 0.08s;
}
.kofi:hover { background: var(--card-hover); transform: translateY(-1px); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px;
  max-width: 420px;
  width: 100%;
  position: relative;
  text-align: left;
}
.modal-card h2 { margin-top: 0; }
.modal-card ul { padding-left: 18px; }
.modal-card li { margin: 6px 0; }
.close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: var(--subtle);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  text-align: center;
  margin: 16px 0;
}
.stat-num { display: block; font-size: 1.6rem; font-weight: 800; }
.stat-lbl { display: block; color: var(--subtle); font-size: 0.72rem; }

.result-box { text-align: center; border-top: 1px solid var(--border); padding-top: 14px; }
.share-text {
  font-family: inherit;
  font-size: 1.1rem;
  line-height: 1.35;
  white-space: pre-wrap;
  margin: 0 0 12px;
}
.hidden { display: none; }
