* { box-sizing: border-box; }

html {
  background: #e7ebef;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #e7ebef;
  color: #1f2b38;
  font-family: Arial, sans-serif;
}

button, input, select { font-family: inherit; }

.app {
  width: min(100%, 440px);
  margin: 0 auto;
  padding: 8px 8px 24px;
}

.app-wide {
  width: min(100%, 960px);
}

.topbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.brand {
  display: block;
  width: min(100%, 280px);
  height: auto;
}

.nav {
  display: flex;
  gap: 6px;
  width: 100%;
}

.nav a {
  flex: 1;
  min-height: 36px;
  padding: 8px 6px;
  border: 1px solid #cfd7e2;
  border-radius: 8px;
  background: #fff;
  color: #334155;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.nav a[aria-current="page"] {
  border-color: #93c5fd;
  background: #eff6ff;
  color: #1e40af;
}

.banner, .status-line {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

.banner { border: 1px solid #fcd34d; background: #fffbeb; color: #92400e; }
.banner[hidden], .status-line[hidden], [hidden] { display: none !important; }

.card {
  margin-bottom: 10px;
  padding: 12px;
  border: 1px solid #cfd7e2;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(21, 33, 47, 0.08);
}

.card h1, .card h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 900;
}

.competition-title {
  color: #1e40af;
  font-size: 22px;
  font-weight: 900;
  text-align: center;
}

.meta-date, .hint, .footer-note, .updated {
  margin: 4px 0 0;
  color: #64748b;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.pill-row, .action-row, .filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
}

.pill {
  padding: 5px 10px;
  border: 1.5px solid transparent;
  border-radius: 999px;
  background: #eff6ff;
  color: #1e40af;
  font-size: 13px;
  font-weight: 900;
}

.pill.is-empty { background: #f1f5f9; color: #64748b; }
.pill.is-static { border-color: #93c5fd; }

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  margin-top: 8px;
}

.field span, .filters label span {
  color: #64748b;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

input, select {
  width: 100%;
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid #cfd7e2;
  border-radius: 8px;
  background: #fff;
  color: #1f2b38;
  font-size: 16px;
  font-weight: 700;
}

input:focus, select:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.18);
}

input[aria-invalid="true"] {
  border-color: #dc2626;
  color: #dc2626;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.16);
}

.field-error {
  margin: 0;
  color: #dc2626;
  font-size: 12px;
  font-weight: 700;
}

.judge-row, .split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 8px;
  align-items: end;
}

.btn {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid #007bff;
  border-radius: 8px;
  background: #fff;
  color: #1e40af;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { border-color: #cbd5e1; color: #94a3b8; cursor: default; transform: none; }

.btn-primary {
  border-color: #0056b3;
  background: #007bff;
  color: #fff;
}

.btn-wide { width: 100%; }

.score-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 10px;
}

.score-line strong {
  color: #007bff;
  font-size: 28px;
  font-variant-numeric: tabular-nums;
}

.try-row { display: flex; gap: 6px; }

.try-btn, .try-extra {
  min-height: 40px;
  border: 1px solid #cfd7e2;
  border-radius: 8px;
  background: #fff;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}

.try-btn { flex: 1; }
.try-extra { width: 54px; text-align: center; }

.try-btn[aria-pressed="true"], .try-extra.is-active {
  border-color: #007bff;
  background: #007bff;
  color: #fff;
}

.check-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 10px;
  font-size: 14px;
  font-weight: 700;
}

.check-row input { width: 20px; height: 20px; min-height: 0; margin-top: 2px; accent-color: #16a34a; }

.revision-banner {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #eff6ff;
  color: #1e40af;
  font-size: 13px;
  font-weight: 800;
}

.previous-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }

.previous-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #dbeafe;
  border-radius: 8px;
  background: #f8fafc;
  color: #1f2b38;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.previous-item small { color: #64748b; font-size: 12px; }

.table-wrap {
  margin-bottom: 10px;
  overflow: hidden;
  border: 1px solid #cfd7e2;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(21, 33, 47, 0.08);
}

.table-caption {
  margin: 0;
  padding: 8px 10px;
  background: #f8fafc;
  color: #334155;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.score-table, .data-table, .history-table {
  width: 100%;
  border-collapse: collapse;
}

.score-table { table-layout: fixed; font-size: 12px; font-weight: 800; text-align: center; }
.score-table th:first-child,
.score-table td:first-child { width: 24%; }

#leanbot-wrap td:first-child {
  width: 78%;
  padding-left: 10px;
  text-align: left;
}

#leanbot-wrap td:last-child { width: 22%; }

.score-table th {
  padding: 8px 4px;
  border: 1px solid #cdd5df;
  background: #f1f4f8;
  font-size: 11px;
  line-height: 1.2;
}

.th-stack { display: flex; flex-direction: column; gap: 1px; }
.th-stack span:last-child { font-size: 10px; font-weight: 700; }

.score-table td { height: 48px; border: 1px solid #cdd5df; padding: 4px; }

.block-btn {
  width: 100%;
  min-height: 40px;
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 800;
  cursor: pointer;
}

.check-btn {
  width: 100%;
  min-height: 40px;
  border: 2px solid rgba(0, 0, 0, 0.12);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.55);
  color: #64748b;
  font-weight: 800;
  cursor: pointer;
}

.check-btn[aria-pressed="true"] {
  border-color: #0056b3;
  background: #007bff;
  color: #fff;
}

.cell-disabled {
  background: repeating-linear-gradient(-45deg, #cbd5e1, #cbd5e1 6px, #e2e8f0 6px, #e2e8f0 12px);
}

.row-red { background: #ffe1df; }
.row-yellow { background: #fff6bf; }
.row-green { background: #dff6df; }
.row-blue { background: #dce7ff; }
.row-purple { background: #eadfff; }
.row-mystery { background: #fff; }

.score-note {
  margin: 0 0 10px;
  color: #64748b;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.consent {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
}

.consent:has(input:checked) { background: #e6f4ea; color: #166534; }
.consent input { width: 22px; height: 22px; min-height: 0; accent-color: #16a34a; }
.consent small { display: block; font-weight: 600; }

.locked-note { margin: 0; color: #166534; font-size: 12px; font-weight: 800; text-align: center; }

.photo-frame {
  margin: 8px 0;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #0f172a;
}

.photo-frame img { display: block; width: 100%; max-height: 320px; object-fit: contain; }

.photo-tools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  background: #f8fafc;
  color: #64748b;
  font-size: 12px;
  font-weight: 700;
}

.btn-photo {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 48px;
  border: 1px solid #008000;
  border-radius: 8px;
  background: #fff;
  color: #166534;
  font-weight: 800;
  cursor: pointer;
}

.btn-photo:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-photo small { font-weight: 600; }

.btn-submit {
  width: 100%;
  min-height: 46px;
  margin-top: 8px;
  border: 1px solid #0056b3;
  border-radius: 8px;
  background: #007bff;
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}

.btn-submit:disabled { cursor: default; }
.btn-submit.is-sending { border-color: #b45309; background: #d97706; }
.btn-submit.is-done { border-color: #15803d; background: #16a34a; }
.btn-submit.is-failed { border-color: #b91c1c; background: #dc2626; }

.status-line { text-align: center; }
.status-line.is-ok { background: #dcfce7; color: #15803d; }
.status-line.is-warn { background: #fef3c7; color: #92400e; }
.status-line.is-error { background: #fee2e2; color: #b91c1c; }

.is-run-locked { opacity: 0.72; }
.is-run-locked .lockable { pointer-events: none; }

.footer { padding: 8px 0 0; text-align: center; }
.footer img { max-width: 180px; height: auto; }

.history-table th, .history-table td, .data-table th, .data-table td {
  padding: 8px 6px;
  border-bottom: 1px solid #e2e8f0;
  font-size: 12px;
  text-align: left;
  vertical-align: top;
}

.history-table th, .data-table th {
  color: #64748b;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.history-table button, .data-row {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.data-table tr[role="button"]:hover, .history-table tr:hover { background: #eff6ff; }
.data-table .num, .history-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.filters { justify-content: stretch; }
.filters label { display: flex; flex: 1 1 160px; flex-direction: column; gap: 4px; }
.filters .btn { align-self: end; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.7);
}

.modal-card {
  width: min(100%, 640px);
  max-height: min(88vh, 820px);
  overflow: auto;
  border-radius: 10px;
  background: #fff;
}

.modal-head, .card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.modal-head { padding: 10px 12px; border-bottom: 1px solid #e2e8f0; background: #f8fafc; }
.modal-body { padding: 12px; }

.icon-btn {
  min-width: 36px;
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #475569;
  font-size: 24px;
  cursor: pointer;
}

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

.detail-grid div, .revision {
  padding: 8px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
}

.detail-grid span, .revision h3 {
  display: block;
  margin: 0 0 2px;
  color: #64748b;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.revision { margin-bottom: 10px; }
.revision.is-latest { border-color: #86efac; background: #f0fdf4; }
.revision table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.revision td { padding: 4px 0; font-size: 13px; font-weight: 700; }
.revision td:last-child { text-align: right; color: #1e40af; }
.revision img { display: block; width: 100%; max-height: 240px; object-fit: contain; margin-top: 8px; background: #0f172a; border-radius: 6px; }

.rank { font-weight: 900; }

@media (max-width: 640px) {
  .detail-grid { grid-template-columns: 1fr; }
  .data-table { display: block; overflow-x: auto; }
}
