* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

:root {
  --bg-a: #f6fbff;
  --bg-b: #eef4ff;
  --card-bg: #ffffff;
  --card-border: #dce7f7;
  --text: #0f2238;
  --muted: #4a6078;
  --accent: #0f69ff;
  --accent-2: #0b4fbd;
  --danger: #b64848;
  --ok: #1d8d4d;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Manrope", "SF Pro Display", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px circle at 10% -5%, rgba(15, 105, 255, 0.12), transparent 60%),
    radial-gradient(900px circle at 90% 0%, rgba(80, 151, 255, 0.11), transparent 62%),
    linear-gradient(180deg, var(--bg-b) 0%, var(--bg-a) 100%);
  min-height: 100vh;
}

header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 1px solid #e0eaf8;
  color: #17395d;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.header-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid #cfe0f8;
  background: #f2f7ff;
  color: #174978;
  text-decoration: none;
  font-weight: 600;
}

.header-link:hover {
  color: #0f3c64;
  background: #e6f0ff;
}

main {
  max-width: 1240px;
  margin: 18px auto;
  padding: 0 16px 28px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 12px 28px rgba(20, 68, 129, 0.12);
}

.hero {
  display: grid;
  gap: 12px;
  grid-template-columns: 1.4fr 0.6fr;
  align-items: center;
}

.hero h2,
.card h3 {
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.row {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.form-grid > div {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-grid > div > label {
  min-height: 20px;
  font-size: 13px;
  color: #294562;
  font-weight: 600;
}

.form-grid > .action-cell {
  justify-content: flex-end;
  padding-top: 26px;
}

.form-grid > .action-cell > button,
.form-grid > .action-cell > a.action-link {
  height: 44px;
}

input,
select,
button,
textarea {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid rgba(33, 62, 91, 0.2);
  font: inherit;
}

input,
select,
textarea {
  background: #fff;
  border-color: #cfdcf2;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(15, 105, 255, 0.25);
  border-color: #79a7ff;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  min-height: 44px;
  line-height: 1.2;
  font-weight: 600;
  border: none;
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease, opacity 0.14s ease;
  box-shadow: 0 8px 18px rgba(15, 80, 186, 0.28);
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

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

button.secondary {
  background: linear-gradient(135deg, #2f78d6 0%, #245fb2 100%);
}

button.danger {
  background: linear-gradient(135deg, #c24f4f 0%, #9b3f3f 100%);
}

button.success {
  background: linear-gradient(135deg, #249d5a 0%, #1c7f49 100%);
}

a.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  min-height: 44px;
  line-height: 1.2;
  width: 100%;
  border-radius: 12px;
  padding: 0 12px;
  background: linear-gradient(135deg, #2f78d6 0%, #245fb2 100%);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 8px 18px rgba(15, 80, 186, 0.2);
}

a.action-link:hover {
  color: #fff;
  filter: brightness(1.04);
}

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

header .muted {
  color: #416080;
}

.status {
  margin-top: 10px;
  font-size: 14px;
  min-height: 20px;
}

.status.error {
  color: var(--danger);
}

.status.ok {
  color: var(--ok);
}

.competition-state {
  min-height: 22px;
  font-weight: 600;
}

.competition-state.state-active {
  color: var(--ok);
}

.competition-state.state-inactive {
  color: var(--danger);
}

.competition-state.state-strict {
  color: #a24a3f;
}

.competition-state.state-flexible {
  color: #1d8d4d;
}

.two-col {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr 1fr;
}

.wizard {
  overflow: hidden;
}

.wizard-steps {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.wizard-step {
  border: 1px solid #d7e3f8;
  border-radius: 10px;
  padding: 8px;
  background: #f7faff;
  text-align: center;
  font-size: 13px;
  color: #26445e;
  cursor: pointer;
  transition: border-color 0.14s ease, background-color 0.14s ease, color 0.14s ease;
}

.wizard-step:hover {
  border-color: #9fc2ff;
  background: #eef5ff;
}

.wizard-step.active {
  border-color: #7db0ff;
  background: #e9f2ff;
  color: #134f98;
  font-weight: 600;
}

.wizard-progress {
  height: 6px;
  border-radius: 999px;
  background: #deebff;
  margin-bottom: 16px;
  overflow: hidden;
}

.wizard-progress > div {
  height: 100%;
  width: 20%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-2) 100%);
  transition: width 0.2s ease;
}

.step-panel {
  display: none;
}

.step-panel.active {
  display: block;
  animation: fade-slide 0.22s ease;
}

.step-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
}

.step-actions button {
  min-width: 170px;
}

.collapsible-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.collapsible-head h3 {
  margin: 0;
}

.collapse-toggle {
  width: auto;
  min-width: 190px;
}

.collapse-panel {
  display: none;
  margin-top: 10px;
}

.collapse-panel.open {
  display: block;
}

.judge-menu-wrap {
  position: relative;
  display: flex;
  justify-content: flex-end;
}

.menu-toggle-btn {
  width: auto;
  min-width: 130px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.menu-lines {
  display: inline-grid;
  gap: 3px;
}

.menu-lines i {
  display: block;
  width: 14px;
  height: 2px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
}

.judge-menu-panel {
  position: absolute;
  top: 46px;
  right: 0;
  min-width: 220px;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid #dce7f7;
  background: #fff;
  box-shadow: 0 10px 24px rgba(18, 66, 129, 0.16);
  display: none;
  z-index: 20;
}

.judge-menu-panel.open {
  display: grid;
  gap: 8px;
}

.menu-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 12px;
  padding: 10px 12px;
  text-decoration: none;
  font-weight: 600;
  color: #204a76;
  background: #eef5ff;
  border: 1px solid #d7e5fb;
}

.menu-link:hover {
  color: #173a5d;
  background: #e3eeff;
}

.apparatus-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.apparatus-toolbar button {
  width: auto;
  min-width: 120px;
}

.apparatus-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.apparatus-chip {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  align-items: center;
  gap: 8px;
  border: 1px solid #d7e3f8;
  border-radius: 12px;
  padding: 10px 12px;
  background: #f8fbff;
  cursor: pointer;
  transition: border-color 0.14s ease, box-shadow 0.14s ease, background-color 0.14s ease;
}

.apparatus-chip:hover {
  border-color: #9ec1ff;
  background: #eef5ff;
  box-shadow: 0 6px 14px rgba(17, 81, 180, 0.12);
}

.apparatus-chip input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.apparatus-chip small {
  color: #3e5f82;
  font-weight: 600;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #edf4ff;
  color: #1258a8;
  padding: 4px 10px;
  font-size: 12px;
  margin-right: 8px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 10px;
  background: #ffffff;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid #e4ecfa;
  padding: 10px 8px;
  transition: background-color 0.32s ease, color 0.22s ease;
}

th {
  color: #234863;
  font-size: 13px;
}

.score {
  font-weight: 700;
  color: #12324a;
}

td.value-update {
  background-color: #eaf3ff;
}

.judge-scores-cell {
  font-size: 12px;
  line-height: 1.35;
  color: #315271;
  min-width: 340px;
  white-space: normal;
}

.warning-text {
  color: #b45420;
  font-weight: 600;
}

.ok-text {
  color: #1d8d4d;
  font-weight: 600;
}

tr.warning-row td {
  background: #fff8f1;
}

.status-warning {
  color: #b45420;
  font-weight: 600;
}

input.status-warning,
textarea.status-warning,
select.status-warning {
  border-color: #d48752;
  background: #fff7ef;
}

.checkbox-cell {
  justify-content: center;
  padding-top: 0;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: #294562;
  font-weight: 600;
}

.checkbox-label input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.attempt-order-editor {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 200px;
}

.attempt-order-editor .attempt-order-input {
  min-width: 78px;
}

.attempt-order-editor .attempt-order-save-btn {
  width: auto;
  min-width: 110px;
  padding: 9px 12px;
}

.result-override-table .result-override-number {
  min-width: 92px;
  padding: 8px 10px;
}

.result-override-table .result-override-note {
  min-width: 220px;
  padding: 8px 10px;
}

.result-override-table .result-override-status {
  min-width: 140px;
  padding: 8px 10px;
}

.result-override-actions {
  display: flex;
  gap: 6px;
  min-width: 220px;
}

.result-override-actions button {
  width: auto;
  min-width: 102px;
  padding: 9px 12px;
}

.judge-score-edit-value {
  min-width: 110px;
  padding: 8px 10px;
}

.judge-score-edit-comment {
  min-width: 220px;
  padding: 8px 10px;
}

.judge-score-edit-save-btn {
  width: auto;
  min-width: 170px;
  padding: 9px 12px;
}

.nowrap {
  white-space: nowrap;
}

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

.board-toolbar button {
  width: auto;
  min-width: 170px;
}

.mobile-action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  display: none;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(246, 251, 255, 0.96);
  border-top: 1px solid #d9e6fb;
  backdrop-filter: blur(8px);
}

.mobile-action-grid {
  max-width: 1240px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

a {
  color: #0b58c6;
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover {
  color: #08469e;
}

.judge-menu-panel .menu-link {
  text-decoration: none;
}

.loading-shimmer {
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.38) 0%, rgba(255, 255, 255, 0.92) 50%, rgba(255, 255, 255, 0.38) 100%);
  background-size: 220% 100%;
  animation: shimmer 1.25s infinite;
  border-radius: 10px;
  height: 38px;
}

.rules-sheet h3 {
  margin-top: 18px;
}

.rules-sheet p {
  margin: 8px 0;
}

.rules-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.rules-print-btn {
  width: auto;
  min-width: 140px;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

@keyframes fade-slide {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 950px) {
  .hero,
  .two-col {
    grid-template-columns: 1fr;
  }
  .wizard-steps {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1100px) {
  body.judge-page main,
  body.admin-page main {
    padding-bottom: calc(104px + env(safe-area-inset-bottom));
  }

  body.judge-page .row,
  body.admin-page .row,
  body.chief-page .row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.judge-page .two-col,
  body.chief-page .two-col {
    grid-template-columns: 1fr;
  }

  body.judge-page input,
  body.judge-page select,
  body.judge-page button,
  body.judge-page textarea,
  body.admin-page input,
  body.admin-page select,
  body.admin-page button,
  body.admin-page textarea,
  body.chief-page input,
  body.chief-page select,
  body.chief-page button,
  body.chief-page textarea {
    min-height: 50px;
    font-size: 16px;
  }

  body.admin-page .wizard-steps {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body.admin-page .wizard-step {
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  body.admin-page .step-actions {
    position: sticky;
    bottom: 0;
    z-index: 35;
    margin: 14px -8px -2px;
    padding: 10px 8px calc(10px + env(safe-area-inset-bottom));
    background: rgba(247, 251, 255, 0.97);
    border-top: 1px solid #d9e6fb;
    backdrop-filter: blur(8px);
  }

  body.judge-page .mobile-action-bar {
    display: block;
  }
}

@media (max-width: 1200px) {
  main {
    max-width: 1080px;
    margin: 12px auto;
    padding: 0 12px 20px;
  }
  .card {
    padding: 14px;
    border-radius: 15px;
  }
  .row {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  }
}

@media (max-width: 760px) {
  header {
    padding: 10px 12px;
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
  .header-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .header-link {
    width: 100%;
  }
  main {
    margin: 8px auto;
    padding: 0 10px 14px;
  }
  .card {
    padding: 12px;
    border-radius: 13px;
  }
  .row {
    grid-template-columns: 1fr;
  }
  body.judge-page .row,
  body.admin-page .row,
  body.chief-page .row {
    grid-template-columns: 1fr;
  }
  .form-grid > .action-cell {
    padding-top: 0;
  }
  .wizard-steps {
    grid-template-columns: 1fr;
  }
  body.admin-page .wizard-steps {
    grid-template-columns: 1fr;
  }
  body.admin-page .step-actions {
    position: static;
    margin: 10px 0 0;
    padding: 0;
    background: transparent;
    border-top: none;
    backdrop-filter: none;
  }
  .mobile-action-grid {
    grid-template-columns: 1fr;
  }
  input,
  select,
  button,
  textarea {
    min-height: 46px;
    font-size: 16px;
  }
  .step-actions {
    flex-direction: column;
  }
  .step-actions button {
    min-width: 0;
    width: 100%;
  }
  .collapse-toggle,
  .menu-toggle-btn {
    width: 100%;
  }
  .apparatus-toolbar button,
  .board-toolbar button {
    width: 100%;
    min-width: 0;
  }
  .judge-scores-cell {
    min-width: 240px;
  }
}

@media print {
  header {
    position: static;
    border-bottom: none;
    padding: 0 0 8px;
    background: #fff;
  }
  header .header-link {
    display: none;
  }
  main {
    max-width: 100%;
    margin: 0;
    padding: 0;
  }
  .card {
    box-shadow: none;
    border: none;
    border-radius: 0;
    padding: 0;
    margin: 0;
  }
  .rules-print-btn {
    display: none;
  }
}

body.board-page main {
  max-width: 1480px;
}

body.board-page table {
  min-width: 860px;
}

body.board-page.board-wall-mode header {
  display: none;
}

body.board-page.board-wall-mode main {
  max-width: 100%;
  padding: 8px 12px;
  margin-top: 0;
}

body.board-page.board-wall-mode .card {
  border-radius: 12px;
  padding: 12px;
}

body.board-page.board-wall-mode h2 {
  font-size: 34px;
}

body.board-page.board-wall-mode .muted,
body.board-page.board-wall-mode .status {
  font-size: 18px;
}

body.board-page.board-wall-mode th,
body.board-page.board-wall-mode td {
  font-size: 20px;
  padding: 12px 10px;
}

body.board-page.board-wall-mode .score {
  font-size: 25px;
}

@media (max-width: 760px) {
  body.board-page table {
    min-width: 620px;
  }
  body.board-page.board-wall-mode h2 {
    font-size: 26px;
  }
  body.board-page.board-wall-mode th,
  body.board-page.board-wall-mode td {
    font-size: 16px;
  }
}
