:root {
  color-scheme: light;
  --bg: #eef3f6;
  --surface: #ffffff;
  --surface-soft: #f5f8fa;
  --text: #14282d;
  --muted: #5c6f75;
  --line: #cdd9dd;
  --accent: #176b68;
  --accent-strong: #0f4d4b;
  --accent-soft: #e3f1f0;
  --scrollbar-track: #dfe8eb;
  --scrollbar-thumb: #4d918e;
  --scrollbar-thumb-hover: #176b68;
  --scrollbar-thumb-active: #0f4d4b;
  --navy: #123b3a;
  --warn: #96520d;
  --new: #1768a5;
  --updated: #935016;
  --danger: #a23939;
  --shadow: 0 12px 30px rgba(18, 59, 58, 0.08);
}

* {
  box-sizing: border-box;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  scrollbar-width: thin;
}

*::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

*::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

*::-webkit-scrollbar-thumb {
  min-height: 44px;
  border: 3px solid var(--scrollbar-track);
  border-radius: 999px;
  background: linear-gradient(180deg, #65a5a1, var(--scrollbar-thumb));
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

*::-webkit-scrollbar-thumb:active {
  background: var(--scrollbar-thumb-active);
}

*::-webkit-scrollbar-corner {
  background: var(--scrollbar-track);
}

[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(23, 107, 104, 0.08), transparent 260px),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 1rem;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button,
a,
input,
select {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid rgba(23, 104, 165, 0.38);
  outline-offset: 2px;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 30px 0 48px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border-radius: 14px 4px 14px 4px;
  background: var(--navy);
  color: #ffffff;
  font-size: 1.1rem;
  font-weight: 850;
  letter-spacing: -0.04em;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 0.875rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1;
  letter-spacing: -0.045em;
}

.sync-box {
  min-width: 250px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  text-align: right;
}

.sync-box span,
.sync-box small {
  display: block;
  color: var(--muted);
  font-size: 0.875rem;
}

.sync-box strong {
  display: block;
  margin: 2px 0;
  font-size: 1rem;
}

.pwa-install {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 13px;
  margin-bottom: 16px;
  padding: 13px;
  border: 1px solid #bad7d4;
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  background: linear-gradient(105deg, #ffffff 0%, #f7fbfa 62%, var(--accent-soft) 100%);
  box-shadow: 0 7px 20px rgba(18, 59, 58, 0.08);
}

.pwa-install-icon {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 12px 4px 12px 4px;
  background: var(--navy);
  color: #ffffff;
  font-size: 1rem;
  font-weight: 850;
  letter-spacing: -0.04em;
  box-shadow: 0 3px 10px rgba(18, 59, 58, 0.2);
}

.pwa-install-copy {
  min-width: 0;
}

.pwa-install-copy strong {
  display: block;
  font-size: 0.95rem;
}

.pwa-install-copy p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.pwa-install-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.pwa-install-actions button {
  height: 42px;
  min-height: 42px;
  white-space: nowrap;
}

.privacy-note {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 16px;
  padding: 10px 13px;
  border: 1px solid #bad7d4;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.9rem;
  font-weight: 650;
}

.privacy-note span {
  font-size: 0.65rem;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metrics article {
  min-height: 98px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 0.875rem;
}

.metrics strong {
  display: block;
  margin-top: 8px;
  font-size: 2rem;
  line-height: 1;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 13px;
  align-items: end;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(18, 59, 58, 0.04);
}

.segmented {
  display: flex;
  grid-column: 1 / -1;
  flex-wrap: wrap;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.segmented button {
  position: relative;
  flex: 1 1 118px;
  min-width: max-content;
  min-height: 44px;
  padding: 0 13px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 750;
  white-space: nowrap;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button:hover:not(.active) {
  background: #eaf0f2;
  color: var(--text);
}

.segmented button.active {
  background: var(--accent);
  color: #ffffff;
}

.segmented button.has-unseen::after {
  content: "";
  position: absolute;
  top: 7px;
  right: 9px;
  width: 8px;
  height: 8px;
  border: 2px solid #ffffff;
  border-radius: 999px;
  background: var(--danger);
}

.field {
  display: grid;
  gap: 5px;
}

.field span {
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 700;
}

.field > label {
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 0 12px;
}

.field input:hover,
.field select:hover {
  border-color: #9eb1b7;
}

.sort-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
}

.sort-direction {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--accent);
  cursor: pointer;
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1;
}

.sort-direction:hover {
  border-color: #9eb1b7;
  background: var(--surface-soft);
}

.sort-direction:focus-visible {
  outline: 3px solid rgba(18, 59, 58, 0.2);
  outline-offset: 2px;
}

.reference-panel {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(18, 59, 58, 0.04);
}

.reference-head {
  margin-bottom: 12px;
}

.reference-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.reference-head p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.reference-form {
  display: grid;
  grid-template-columns: minmax(170px, 0.75fr) minmax(240px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.reference-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 44px;
}

.reference-actions button {
  white-space: nowrap;
}

.reference-help {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.reference-help a {
  color: var(--accent-strong);
  font-weight: 700;
}

#referenceError {
  margin-top: 8px;
}

.notice {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-left: 4px solid var(--warn);
  border-radius: 8px;
  background: #fff5e8;
  color: #713d0a;
  font-weight: 650;
}

.notice-error {
  border-left-color: var(--danger);
  background: #fff0f0;
  color: #7b2828;
}

.list-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin: 24px 0 12px;
}

.list-header h2 {
  margin: 0 0 3px;
  font-size: 1.35rem;
}

.list-header p {
  margin: 0;
  color: var(--muted);
}

#resultCount {
  color: var(--muted);
  font-weight: 750;
  white-space: nowrap;
}

.contest-list {
  display: grid;
  gap: 12px;
}

.contest-card {
  position: relative;
  padding: 17px 18px 16px 21px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.contest-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--accent);
}

.contest-card.ignored {
  opacity: 0.62;
}

.contest-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 152px;
  gap: 18px;
}

.badges {
  display: flex;
  min-height: 26px;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 7px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 750;
}

.badge.new {
  background: #e4f1fb;
  color: var(--new);
}

.badge.updated {
  background: #fff0df;
  color: var(--updated);
}

.badge.registered {
  background: #e9f5e9;
  color: #2c682f;
}

.badge.exam {
  background: #e9eff6;
  color: #31516c;
}

.badge.soon {
  background: #fff4e6;
  color: var(--warn);
}

.badge.scope {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.contest-card h3 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 1.18rem;
  line-height: 1.3;
  letter-spacing: -0.015em;
}

.contest-card p {
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.deadline {
  align-self: start;
  min-height: 76px;
  padding: 10px 11px;
  border: 1px solid #d7e2e5;
  border-radius: 8px;
  background: var(--surface-soft);
  text-align: right;
}

.deadline span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.deadline strong {
  display: block;
  margin-top: 5px;
  font-size: 1rem;
}

.details {
  display: grid;
  grid-template-columns: minmax(135px, 0.8fr) minmax(190px, 1.2fr) minmax(125px, 0.75fr) minmax(150px, 0.85fr) minmax(175px, 1fr) minmax(130px, 0.75fr);
  gap: 14px;
  margin: 16px 0;
  padding: 13px 0;
  border-top: 1px solid #e2e9eb;
  border-bottom: 1px solid #e2e9eb;
}

.details div {
  min-width: 0;
}

.details dt {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

.details dd {
  margin: 0;
  overflow-wrap: anywhere;
  line-height: 1.4;
}

.exam-event-list {
  margin-bottom: 6px;
}

.organizer-source {
  color: var(--accent-strong);
  font-size: 0.84rem;
  font-weight: 750;
  text-underline-offset: 3px;
}

.detail-list {
  display: grid;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.detail-list li {
  position: relative;
  padding-left: 12px;
}

.detail-list li::before {
  content: "";
  position: absolute;
  top: 0.68em;
  left: 0;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-link,
.secondary-link,
.icon-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 750;
  text-decoration: none;
}

.primary-link {
  padding: 0 14px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.primary-link:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.secondary-link,
.icon-action {
  padding: 0 13px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
}

.secondary-link:hover,
.icon-action:hover {
  border-color: #93aaa9;
  background: var(--surface-soft);
}

.secondary-link.active,
.icon-action.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.empty {
  padding: 44px 20px;
  border: 1px dashed #aebdc2;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.75);
  color: var(--muted);
  text-align: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 33, 36, 0.56);
}

.modal {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(10, 33, 36, 0.28);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
  font-size: 1.15rem;
}

.modal-close {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
}

.modal-body {
  display: grid;
  gap: 13px;
  padding: 17px 18px 19px;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-weight: 700;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 5px;
}

.button-reset {
  cursor: pointer;
}

@media (max-width: 930px) {
  .topbar,
  .list-header {
    align-items: stretch;
    flex-direction: column;
  }

  .sync-box {
    text-align: left;
  }

  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .contest-head {
    grid-template-columns: 1fr;
  }

  .reference-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .reference-actions {
    grid-column: 1 / -1;
  }

  .deadline {
    text-align: left;
  }
}

@media (max-width: 650px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
  }

  .pwa-install {
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 10px;
    padding: 12px;
  }

  .pwa-install-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px 3px 10px 3px;
  }

  .pwa-install-actions {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pwa-install-actions button {
    width: 100%;
  }

  .metrics,
  .toolbar,
  .details,
  .reference-form {
    grid-template-columns: 1fr;
  }

  .reference-actions {
    grid-column: auto;
  }

  .reference-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .reference-actions button {
    width: 100%;
  }

  .metrics {
    gap: 8px;
  }

  .metrics article {
    display: flex;
    min-height: 68px;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border-top-width: 1px;
    border-left: 4px solid var(--accent);
  }

  .metrics strong {
    margin: 0;
    font-size: 1.6rem;
  }

  .segmented button {
    flex-basis: 50%;
    min-height: 46px;
    border-bottom: 1px solid var(--line);
  }

  .contest-card {
    padding: 15px 14px 14px 18px;
  }

  .actions > * {
    flex: 1 1 145px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}
