/* ===========================================================================
   PyGrind

   One rule governs the palette: green and red mean "a test passed" and "a test
   failed", and nothing else on the page is allowed to use them. Every other
   interactive colour is indigo. That way the dot matrix reads instantly.
   =========================================================================== */

:root {
  --ink:            #12151c;
  --surface:        #171b24;
  --surface-raised: #1e2430;
  --surface-hover:  #262d3b;
  --line:           #2b3342;
  --line-soft:      #222937;

  --text:        #e4e8f0;
  --text-muted:  #8b94a7;
  --text-faint:  #5d6678;

  --indigo:       #7c8cf8;
  --indigo-dim:   #5a67c9;
  --indigo-wash:  rgba(124, 140, 248, 0.12);

  --pass:  #5fbf8f;
  --fail:  #f0685e;
  --slow:  #e8b04b;

  --easy:   #5fbf8f;
  --medium: #e8b04b;

  --display: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --body: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --rail: 264px;
  --radius: 6px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--body);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

#root {
  height: 100%;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
  border-radius: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- boot splash ---------------------------------------------------------- */

.boot-splash {
  height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  color: var(--text-faint);
}

.boot-splash__mark {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 22px;
  color: var(--ink);
  background: var(--indigo);
  width: 44px;
  height: 44px;
  display: grid;
  place-content: center;
  border-radius: 10px;
}

/* --- sign in -------------------------------------------------------------- */

.signin {
  height: 100%;
  display: grid;
  place-content: center;
  padding: 24px;
}

.signin__card {
  width: min(420px, 100%);
}

.signin__mark {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 20px;
  color: var(--ink);
  background: var(--indigo);
  width: 40px;
  height: 40px;
  display: grid;
  place-content: center;
  border-radius: 9px;
  margin-bottom: 22px;
}

.signin__title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 30px;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}

.signin__lede {
  color: var(--text-muted);
  margin: 0 0 26px;
  max-width: 38ch;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field__label {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 7px;
}

.input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 13px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  transition: border-color 0.15s;
}

.input:focus {
  border-color: var(--indigo);
  outline: none;
}

.input--code {
  font-size: 22px;
  letter-spacing: 0.36em;
  text-align: center;
  padding: 13px;
}

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 10px 16px;
  font-family: var(--body);
  font-weight: 500;
  font-size: 13px;
  background: var(--surface-raised);
  border-color: var(--line);
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--indigo);
  color: #0f1218;
  border-color: var(--indigo);
  font-weight: 600;
}

.btn--primary:hover:not(:disabled) {
  background: #8f9dff;
}

.btn--wide {
  width: 100%;
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  padding: 6px 8px;
}

.btn--ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.notice {
  border-radius: var(--radius);
  padding: 10px 13px;
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid;
}

.notice--error {
  background: rgba(240, 104, 94, 0.09);
  border-color: rgba(240, 104, 94, 0.32);
  color: #ffb3ac;
}

.notice--info {
  background: var(--indigo-wash);
  border-color: rgba(124, 140, 248, 0.3);
  color: #b8c2ff;
}

.signin__foot {
  margin-top: 20px;
  color: var(--text-faint);
  font-size: 12px;
}

/* --- app frame ------------------------------------------------------------ */

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  height: 52px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 15px;
}

.topbar__mark {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  color: var(--ink);
  background: var(--indigo);
  width: 26px;
  height: 26px;
  display: grid;
  place-content: center;
  border-radius: 7px;
}

.topbar__spacer {
  flex: 1;
}

.topbar__email {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-faint);
}

/* The 15-cell progress strip: same visual language as the test matrix. */
.progress-strip {
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-strip__cells {
  display: flex;
  gap: 3px;
}

.progress-strip__cell {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--line);
}

.progress-strip__cell--solved {
  background: var(--pass);
}

.progress-strip__cell--attempted {
  background: var(--line);
  box-shadow: inset 0 0 0 1.5px var(--slow);
}

.progress-strip__label {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* --- layout --------------------------------------------------------------- */

.workspace {
  display: grid;
  grid-template-columns: var(--rail) minmax(320px, 1fr) minmax(420px, 1.15fr);
  min-height: 0;
}

.pane {
  min-height: 0;
  overflow-y: auto;
  border-right: 1px solid var(--line);
}

.pane:last-child {
  border-right: none;
}

/* --- problem rail --------------------------------------------------------- */

.rail {
  background: var(--surface);
  padding: 12px 0 40px;
}

.rail__heading {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 8px 16px 10px;
}

.rail__item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-left: 2px solid transparent;
  padding: 9px 16px;
  transition: background 0.12s;
}

.rail__item:hover {
  background: var(--surface-raised);
}

.rail__item--active {
  background: var(--surface-raised);
  border-left-color: var(--indigo);
}

.rail__status {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-top: 5px;
  background: var(--line);
}

.rail__status--solved {
  background: var(--pass);
}

.rail__status--attempted {
  box-shadow: inset 0 0 0 1.5px var(--slow);
}

.rail__title {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
}

.rail__item--active .rail__title {
  color: var(--text);
}

.rail__meta {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-faint);
  margin-top: 3px;
  display: flex;
  gap: 8px;
}

.rail__num {
  color: var(--text-faint);
}

.diff {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.diff--Easy {
  color: var(--easy);
}

.diff--Medium {
  color: var(--medium);
}

/* --- problem description -------------------------------------------------- */

.brief {
  padding: 26px 30px 60px;
}

.brief__eyebrow {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 10px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.brief__title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
  line-height: 1.2;
}

.brief__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 22px;
}

.tag {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-muted);
  background: var(--surface-raised);
  border: 1px solid var(--line-soft);
  border-radius: 3px;
  padding: 2px 7px;
}

.prose {
  color: #c8cedb;
}

.prose h3 {
  font-family: var(--display);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 26px 0 10px;
}

.prose p {
  margin: 0 0 12px;
}

.prose ul {
  margin: 0 0 12px;
  padding-left: 20px;
}

.prose li {
  margin-bottom: 5px;
}

.prose code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--surface-raised);
  border: 1px solid var(--line-soft);
  border-radius: 3px;
  padding: 1px 5px;
  color: #d9dff0;
}

.prose pre {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
  overflow-x: auto;
  margin: 0 0 14px;
}

.prose pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 12.5px;
  line-height: 1.65;
  color: #b9c2d6;
}

.prose strong {
  color: var(--text);
  font-weight: 600;
}

/* --- hints ---------------------------------------------------------------- */

.hints {
  margin-top: 30px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
}

.hints__heading {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 12px;
}

.hint {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}

.hint__toggle {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: none;
  padding: 9px 13px;
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  gap: 10px;
  align-items: center;
}

.hint__toggle:hover {
  background: var(--surface-raised);
  color: var(--text);
}

.hint__index {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--indigo);
}

.hint__body {
  padding: 11px 13px 13px 36px;
  font-size: 13px;
  color: #c8cedb;
  border-top: 1px solid var(--line-soft);
  background: var(--surface-raised);
}

.reveal {
  margin-top: 12px;
}

.reveal__code {
  margin-top: 10px;
}

/* --- editor pane ---------------------------------------------------------- */

.studio {
  display: grid;
  grid-template-rows: auto minmax(180px, 1fr) auto minmax(160px, 0.85fr);
  min-height: 0;
  overflow: hidden;
}

.studio__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex-wrap: wrap;
}

.studio__file {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  margin-right: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.saved-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--indigo);
  opacity: 0;
  transition: opacity 0.3s;
}

.saved-dot--on {
  opacity: 1;
}

.editor-host {
  min-height: 0;
  overflow: hidden;
  background: var(--ink);
}

.editor-host .cm-editor {
  height: 100%;
}

.editor-host .cm-scroller {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
}

.editor-host .cm-focused {
  outline: none;
}

/* --- results -------------------------------------------------------------- */

.results {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  border-top: 1px solid var(--line);
}

.tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 9px 11px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.tab:hover {
  color: var(--text-muted);
}

.tab--active {
  color: var(--text);
  border-bottom-color: var(--indigo);
}

.tab__count {
  margin-left: 6px;
  color: var(--text-faint);
}

.results__body {
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px 30px;
}

.console {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  color: #c3cad9;
}

.console__err {
  color: var(--fail);
}

.empty {
  color: var(--text-faint);
  font-size: 13px;
  padding: 6px 0;
}

.empty code {
  font-family: var(--mono);
  color: var(--text-muted);
}

/* --- the dot matrix: this page's signature -------------------------------- */

.matrix__summary {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.matrix__score {
  font-family: var(--display);
  font-weight: 700;
  font-size: 24px;
  letter-spacing: -0.02em;
}

.matrix__score--pass {
  color: var(--pass);
}

.matrix__score--fail {
  color: var(--fail);
}

.matrix__note {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
}

.matrix__group {
  margin-bottom: 15px;
}

.matrix__group-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 7px;
}

.matrix__group-name {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.matrix__group-count {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-faint);
}

.matrix__cells {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.cell {
  width: 13px;
  height: 13px;
  border-radius: 2px;
  border: none;
  padding: 0;
  background: var(--line-soft);
  transition: background 0.12s, transform 0.12s;
}

.cell--pending {
  background: var(--line-soft);
}

.cell--pass {
  background: var(--pass);
}

.cell--fail {
  background: var(--fail);
}

.cell--running {
  background: var(--indigo);
  animation: pulse 0.7s ease-in-out infinite;
}

.cell:hover {
  transform: scale(1.25);
}

.cell--selected {
  box-shadow: 0 0 0 2px var(--ink), 0 0 0 3.5px var(--indigo);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

/* --- failure detail ------------------------------------------------------- */

.failures {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.failure {
  border: 1px solid rgba(240, 104, 94, 0.26);
  border-radius: var(--radius);
  background: rgba(240, 104, 94, 0.05);
  padding: 11px 13px;
  margin-bottom: 9px;
}

.failure--selected {
  border-color: var(--indigo);
  background: var(--indigo-wash);
}

.failure__head {
  display: flex;
  gap: 9px;
  align-items: baseline;
  margin-bottom: 7px;
  flex-wrap: wrap;
}

.failure__group {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.failure__name {
  font-size: 13px;
  font-weight: 500;
}

.failure__detail {
  font-size: 12.5px;
  color: #ffb3ac;
  margin-bottom: 8px;
}

.kv {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 4px 10px;
  font-family: var(--mono);
  font-size: 12px;
}

.kv__k {
  color: var(--text-faint);
}

.kv__v {
  color: #c8cedb;
  white-space: pre-wrap;
  word-break: break-word;
}

.failure__tb {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: pre-wrap;
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
}

.fatal {
  border: 1px solid rgba(240, 104, 94, 0.4);
  background: rgba(240, 104, 94, 0.08);
  border-radius: var(--radius);
  padding: 13px 15px;
}

.fatal__title {
  color: #ffb3ac;
  font-weight: 600;
  margin-bottom: 7px;
}

.banner {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
  padding: 7px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-raised);
  display: flex;
  align-items: center;
  gap: 9px;
}

.spinner {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--indigo);
  animation: pulse 0.7s ease-in-out infinite;
  flex: none;
}

/* --- responsive ----------------------------------------------------------- */

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 210px 1fr 1fr;
  }
}

@media (max-width: 900px) {
  .app {
    height: auto;
    min-height: 100%;
  }

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

  .pane {
    border-right: none;
    border-bottom: 1px solid var(--line);
    overflow: visible;
  }

  .rail {
    max-height: 240px;
    overflow-y: auto;
  }

  .studio {
    grid-template-rows: auto 380px auto 320px;
    height: auto;
  }

  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 14px;
    gap: 10px;
  }

  .progress-strip__label {
    display: none;
  }
}
