:root {
  --bg: #eef3f7;
  --panel: #ffffff;
  --text: #172733;
  --muted: #526372;
  --primary: #0f766e;
  --primary-strong: #0a5c57;
  --border: #ced9e3;
  --board-max: 760px;
}

body.dark-mode {
  --bg: #0f1822;
  --panel: #111d29;
  --text: #e6edf3;
  --muted: #9cb3c7;
  --border: #2f455a;
  --primary: #16a394;
  --primary-strong: #24b8a8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #f7fafc 0%, var(--bg) 100%);
}

body.dark-mode {
  background: linear-gradient(180deg, #0b131d 0%, var(--bg) 100%);
}

body.auth-locked .layout,
body.auth-locked .app-header,
body.auth-locked .how-to-play {
  filter: blur(5px);
  opacity: 0.35;
  pointer-events: none;
  user-select: none;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(20, 34, 44, 0.28);
  backdrop-filter: blur(8px);
  overflow: auto;
}

.auth-overlay.hidden {
  display: none;
}

.auth-modal {
  width: min(460px, 96vw);
}

.app-header {
  max-width: 1240px;
  margin: 0 auto;
  padding: 1rem 1.25rem 0.25rem;
}

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

.subtitle {
  color: var(--muted);
  margin: 0.3rem 0 0;
}

.layout {
  max-width: 1240px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 1rem;
  padding: 1rem 1.25rem;
  align-items: start;
}

.board-panel {
  display: grid;
  gap: 1rem;
}

.board-wrap {
  width: min(100%, var(--board-max));
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 12px 30px rgba(23, 39, 51, 0.08);
}

body.dark-mode .board-wrap {
  background: #0f1a24;
}

#boardSvg {
  width: 100%;
  height: 100%;
  display: block;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 8px 18px rgba(23, 39, 51, 0.05);
}

.hidden {
  display: none;
}

.panel-page.hidden {
  display: none;
}

#pageUsers {
  display: grid;
  gap: 0.75rem;
}

#pageUsers.hidden {
  display: none;
}

#pageUsers h3 {
  margin: 0.55rem 0 0.05rem;
}

#pageUsers .small {
  margin: 0 0 0.35rem;
}

#usersAccessHint {
  margin: 0;
  padding: 0.6rem 0.7rem;
  border: 1px solid #c7d8e6;
  border-radius: 8px;
  background: #f5f9fd;
}

#pageUsers label {
  margin-top: 0.2rem;
}

#pageUsers .actions {
  margin-top: 0.15rem;
  margin-bottom: 0.25rem;
}

#pageUsers .search-row {
  margin: 0.1rem 0 0.25rem;
}

label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-top: 0.55rem;
}

input,
button,
select {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  margin-top: 0.28rem;
}

body.dark-mode input,
body.dark-mode select,
body.dark-mode textarea {
  background: #0b1621;
  color: var(--text);
  border-color: #355067;
}

textarea {
  resize: vertical;
}

button {
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: #fff;
  color: var(--primary-strong);
  cursor: pointer;
  padding: 0.58rem 0.82rem;
}

body.dark-mode button {
  background: #132333;
  color: #b7dfd9;
  border-color: #2d6971;
}

button.primary {
  background: linear-gradient(120deg, var(--primary), #159f95);
  color: #fff;
  border-color: transparent;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.table-action-btn {
  padding: 0.26rem 0.5rem;
  font-size: 0.8rem;
  border-radius: 6px;
}

.table-action-btn.danger {
  border-color: #b91c1c;
  color: #b91c1c;
}

.quick-nav {
  position: fixed;
  right: 22px;
  top: 20px;
  transform: none;
  z-index: 900;
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 20px rgba(23, 39, 51, 0.12);
}

body.dark-mode .quick-nav {
  background: rgba(14, 25, 36, 0.92);
  border-color: #2f455a;
}

.quick-nav-btn {
  min-width: 74px;
  font-size: 0.78rem;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  border-color: #93a9be;
  background: #ffffff;
  color: #325169;
}

body.dark-mode .quick-nav-btn {
  background: #132433;
  color: #a7c3d9;
  border-color: #365168;
}

.quick-nav-btn.active {
  background: #0f766e;
  color: #fff;
  border-color: transparent;
}

.row-between {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  align-items: center;
}

.progress-top {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fbfe;
  padding: 0.6rem 0.7rem;
  margin-bottom: 0.7rem;
}

body.dark-mode .progress-top {
  background: #0f1e2c;
}

.progress-top .turn,
.progress-top .status {
  margin: 0;
}

.progress-top .status {
  margin-top: 0.25rem;
}

.actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.8rem;
  flex-wrap: wrap;
}

.dice-row {
  margin-top: 0.7rem;
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 0.55rem;
  align-items: center;
}

.dice {
  width: 74px;
  height: 74px;
  border-radius: 12px;
  border: 2px solid #0d7f8a;
  background: #ebfcff;
  display: grid;
  place-items: center;
  font-size: 2rem;
  font-weight: 700;
}

.dice.rolling {
  animation: rollPulse 0.24s linear infinite;
}

@keyframes rollPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.07); }
  100% { transform: scale(1); }
}

.turn {
  font-weight: 700;
}

.status,
.small {
  color: var(--muted);
}

.meta {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.meta p {
  margin: 0;
}

.stat-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.26rem 0.5rem;
  border: 1px solid #c7d8e6;
  border-radius: 999px;
  background: #f3f9ff;
  color: #214258;
  font-size: 0.95rem;
  line-height: 1.2;
}

body.dark-mode .stat-tag {
  background: #132638;
  color: #b7d0e2;
  border-color: #34506a;
}

.stat-tag span {
  font-weight: 700;
}

.countdown-box {
  margin-top: 0.7rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid #c7d8e6;
  border-radius: 10px;
  background: #f5faff;
}

body.dark-mode .countdown-box {
  background: #0f2232;
}

.countdown-box .small {
  margin: 0;
}

.countdown-value {
  margin: 0.2rem 0 0;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #0f766e;
}

.task-section {
  margin-top: 0.75rem;
  padding: 0.65rem;
  border: 1px solid #c7d8e6;
  border-radius: 10px;
  background: #f8fcff;
}

body.dark-mode .task-section {
  background: #102233;
  border-color: #35506a;
}

.task-section h3 {
  margin: 0;
}

.task-section .small {
  margin: 0.3rem 0 0.55rem;
}

.task-list {
  display: grid;
  gap: 0.5rem;
}

.task-item {
  display: grid;
  gap: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.55rem;
  background: #ffffff;
}

body.dark-mode .task-item {
  background: #0e1a27;
  border-color: #32506b;
}

.task-title {
  margin: 0;
  font-weight: 700;
}

.task-links-grid {
  display: grid;
  gap: 0.45rem;
}

.task-link-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f9fcff;
}

body.dark-mode .task-link-item {
  background: #0b1621;
  border-color: #355067;
}

.task-link-title {
  margin: 0;
  font-weight: 700;
}

.platform-tag {
  display: inline-block;
  margin-left: 0.25rem;
  padding: 0.1rem 0.38rem;
  border-radius: 999px;
  border: 1px solid #9fc4dc;
  background: #eef7ff;
  color: #24516c;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: capitalize;
}

body.dark-mode .platform-tag {
  border-color: #365a76;
  background: #102536;
  color: #afcde1;
}

.task-reward {
  color: var(--primary);
  font-weight: 800;
}

.admin-link-builder {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
  background: #f8fbfe;
}

body.dark-mode .admin-link-builder {
  background: #0f1e2c;
}

.admin-link-list {
  margin-top: 0.55rem;
  display: grid;
  gap: 0.45rem;
}

.admin-link-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.5rem;
  background: #ffffff;
}

body.dark-mode .admin-link-row {
  background: #0b1621;
}

.admin-link-title {
  margin: 0;
  font-weight: 700;
}

.podium-section {
  margin-top: 0.8rem;
  padding: 0.7rem;
  border: 1px solid #c7d8e6;
  border-radius: 10px;
  background: #fffdfa;
}

body.dark-mode .podium-section {
  background: #1a2a24;
  border-color: #47644b;
}

.podium-section h3 {
  margin: 0 0 0.6rem;
}

.podium-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
}

.podium-card {
  border: 1px solid #d2b85f;
  border-radius: 8px;
  background: linear-gradient(180deg, #fff4bf 0%, #f5dea0 100%);
  padding: 0.4rem 0.3rem;
  text-align: center;
}

.podium-card.first {
  transform: translateY(-6px);
}

.podium-rank {
  font-size: 1.05rem;
  font-weight: 800;
}

.podium-user {
  margin-top: 0.2rem;
  font-size: 0.86rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.table-wrap {
  max-height: 300px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

body.dark-mode .table-wrap {
  border-color: #32485f;
}

.admin-card {
  margin-top: 1rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border);
}

.admin-card h3 {
  margin: 0 0 0.35rem;
}

.leaderboard-left {
  width: min(100%, var(--board-max));
  margin: 0 auto;
}

.table-wrap.short {
  max-height: 220px;
}

#pageLogs .table-wrap {
  max-height: 520px;
}

#pageLogs {
  min-height: 680px;
}

body.view-logs .layout {
  grid-template-columns: minmax(280px, 1fr) minmax(560px, 840px);
}

body.view-logs .control-panel {
  width: 100%;
}

body.view-users .layout {
  grid-template-columns: minmax(260px, 0.9fr) minmax(640px, 980px);
}

body.view-users .control-panel {
  width: 100%;
}

#pageUsers .table-wrap {
  overflow-x: hidden;
}

#pageUsers th,
#pageUsers td {
  white-space: normal;
}

#pageUsers td:last-child {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.28rem;
}

#pageUsers .table-action-btn {
  width: 100%;
  padding: 0.22rem 0.45rem;
  font-size: 0.78rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  position: sticky;
  top: 0;
  background: #f5f9fc;
  z-index: 1;
}

body.dark-mode thead th {
  background: #172838;
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.45rem;
  border-bottom: 1px solid #e4edf4;
  white-space: nowrap;
}

body.dark-mode th,
body.dark-mode td {
  border-bottom-color: #2d4357;
}

.how-to-play {
  margin: 0;
  padding: 1rem;
  color: var(--muted);
}

.full-row {
  grid-column: 1 / -1;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

  .control-panel {
    width: min(100%, 760px);
    margin: 0 auto;
  }

  body.view-users .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .auth-overlay {
    align-items: start;
    padding: max(12px, env(safe-area-inset-top)) 10px 12px;
  }

  .auth-modal {
    width: 100%;
    max-width: 100%;
    border-radius: 10px;
  }

  .auth-modal .actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }

  .auth-modal .actions button {
    width: 100%;
  }

  .app-header {
    padding: 0.75rem 0.8rem 0.2rem;
  }

  .quick-nav {
    top: auto;
    bottom: 8px;
    left: 8px;
    right: 8px;
    transform: none;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.3rem;
    border-radius: 12px;
    padding: 0.36rem;
    background: rgba(255, 255, 255, 0.96);
  }

  body.dark-mode .quick-nav {
    background: rgba(14, 25, 36, 0.96);
  }

  .quick-nav-btn {
    min-width: 0;
    width: 100%;
    font-size: 0.72rem;
    line-height: 1.1;
    padding: 0.36rem 0.18rem;
    white-space: nowrap;
  }

  .layout {
    padding: 0.65rem 0.8rem 0.9rem;
    gap: 0.75rem;
    padding-bottom: 5.2rem;
  }

  .board-panel {
    order: 2;
    gap: 0.75rem;
  }

  .control-panel {
    order: 1;
    width: 100%;
  }

  .board-wrap,
  .leaderboard-left {
    width: 100%;
  }

  .card {
    padding: 0.75rem;
    border-radius: 10px;
  }

  .row-between {
    flex-wrap: wrap;
  }

  .row-between h2 {
    margin: 0;
    font-size: 1.65rem;
  }

  .dice-row {
    grid-template-columns: 64px 1fr;
    gap: 0.45rem;
  }

  .dice {
    width: 64px;
    height: 64px;
    font-size: 1.7rem;
  }

  .meta {
    gap: 0.4rem;
  }

  .stat-tag {
    width: 100%;
    justify-content: space-between;
    font-size: 0.9rem;
  }

  .search-row {
    grid-template-columns: 1fr;
  }

  .task-item {
    grid-template-columns: 1fr;
  }

  .task-item button {
    width: 100%;
  }

  .task-link-item,
  .admin-link-row {
    grid-template-columns: 1fr;
  }

  .search-row button {
    width: 100%;
  }

  table {
    font-size: 0.82rem;
  }

  .podium-grid {
    grid-template-columns: 1fr;
  }

  .podium-card.first {
    transform: none;
  }

  th,
  td {
    padding: 0.42rem 0.35rem;
  }
}
