:root {
  --bg-1: #f8f1df;
  --bg-2: #d9edf1;
  --ink: #1e2428;
  --muted: #4a575a;
  --accent: #d96b36;
  --accent-2: #2c6d6a;
  --panel: #fff8ee;
  --line: #e2d6c8;
  --ok: #2d7f5f;
  --bad: #b43a2f;
  --shadow: rgba(30, 36, 40, 0.12);
  --chart-height: 260px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
  color: var(--ink);
  background: radial-gradient(circle at 15% 20%, #fff8e6 0, transparent 50%),
    radial-gradient(circle at 85% 10%, #cde8e8 0, transparent 45%),
    linear-gradient(120deg, var(--bg-1), var(--bg-2));
  min-height: 100vh;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

body.auth-locked #codeCard,
body.auth-locked #runtimeCard {
  display: none;
}

body.auth-locked #authCard {
  display: block;
}

body:not(.auth-locked) #authCard {
  display: none;
}

body.auth-locked #testsCard {
  display: none;
}

header {
  display: grid;
  gap: 16px;
  align-items: center;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 2.5vw + 1rem, 3.2rem);
  letter-spacing: 0.5px;
}

h2 {
  margin: 0 0 8px;
  font-size: 1.6rem;
}

p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.hero {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 18px 30px var(--shadow);
  position: relative;
  overflow: hidden;
}

.hero:after {
  content: "";
  position: absolute;
  inset: auto -20% -40% auto;
  width: 260px;
  height: 260px;
  background: radial-gradient(
    circle,
    rgba(217, 107, 54, 0.18),
    transparent 65%
  );
}

.task-stack {
  display: grid;
  gap: 10px;
  max-width: 640px;
  position: relative;
  z-index: 1;
}

.task-select {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 8px 14px rgba(31, 20, 10, 0.08);
  width: fit-content;
  max-width: 100%;
}

.task-select label {
  margin: 0;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.task-select select {
  border: none;
  background: transparent;
  padding: 4px 6px;
  min-width: 220px;
  font-weight: 600;
  font-family: inherit;
  flex: 1;
}

#taskDescription {
  max-width: 620px;
}

.task-example {
  margin: 10px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font-family: "Consolas", "Liberation Mono", "Courier New", monospace;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.task-example.hidden {
  display: none;
}

.stats {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 0.95rem;
}

.stat-label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

.stat select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-family: inherit;
  background: #fff;
}

.stat-hidden {
  display: none;
}

.signature-ok {
  color: var(--ok);
  font-weight: 600;
}

.signature-error {
  color: var(--bad);
  font-weight: 600;
}

.stack {
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.metrics-row {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  align-items: start;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 10px 18px var(--shadow);
}

.output.is-idle .summary-meta,
.output.is-idle .progress,
.output.is-idle .results-scroll,
.output.is-idle #errors {
  display: none;
}

.output.is-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.output.is-idle .summary {
  margin-bottom: 8px;
}

.idle-message {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  position: relative;
  display: none;
}

.idle-loader {
  margin-top: 12px;
  display: none;
  align-items: center;
}

.output.is-idle .idle-message,
.output.is-idle .idle-loader {
  display: flex;
}


.idle-voice {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  position: relative;
  background: radial-gradient(circle at 65% 35%, #ffd9b6 0%, #ffb978 35%, var(--accent) 100%);
  box-shadow: 0 8px 18px rgba(217, 107, 54, 0.2);
  animation: idlePulse 2.2s ease-in-out infinite;
}

.idle-voice::after {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  left: 8px;
  top: 7px;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
}

@keyframes idlePulse {
  0%,
  100% {
    transform: scale(0.96);
    box-shadow:
      0 0 0 0 rgba(217, 107, 54, 0.35),
      0 6px 18px rgba(217, 107, 54, 0.2);
  }
  50% {
    transform: scale(1.06);
    box-shadow:
      0 0 0 10px rgba(217, 107, 54, 0.05),
      0 10px 24px rgba(217, 107, 54, 0.28);
  }
}

.card.wide {
  width: 100%;
}

.card:nth-child(2) {
  animation-delay: 0.08s;
}

.card:nth-child(3) {
  animation-delay: 0.16s;
}

.auth-card form {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.auth-card input {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  font-size: 1rem;
  font-family: inherit;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
}

textarea {
  width: 100%;
  min-height: 240px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  font-family: "Consolas", "Liberation Mono", "Courier New", monospace;
  font-size: 0.95rem;
  background: #fff;
}

.code-field {
  position: relative;
}

.code-field textarea {
  padding-right: 44px;
  padding-bottom: 40px;
}

.signature-indicator {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  border: 1px solid transparent;
  background: #fff;
  box-shadow: 0 8px 14px rgba(31, 20, 10, 0.08);
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.signature-indicator.visible {
  opacity: 1;
  transform: scale(1);
}

.signature-indicator.ok {
  color: var(--ok);
  border-color: rgba(46, 139, 87, 0.35);
  background: #ebf7f0;
}

.signature-indicator.error {
  color: var(--bad);
  border-color: rgba(193, 85, 73, 0.35);
  background: #fcebe9;
}

.controls {
  display: grid;
  grid-row: 2;
  gap: 12px;
  margin-top: 12px;
  align-items: start;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.controls .field {
  display: flex;
  flex-direction: column;
}

.controls input {
  width: 120px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-family: "Consolas", "Liberation Mono", "Courier New", monospace;
}

.controls select {
  width: 160px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-family: "Consolas", "Liberation Mono", "Courier New", monospace;
}

#nameInput {
  width: 200px;
  font-family: inherit;
}

.controls select {
  min-width: 200px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-family: inherit;
  background: #fff;
}

.hash-display {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px dashed var(--line);
  background: #fff;
  display: grid;
  gap: 6px;
}

.hash-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
}

.hash-value {
  font-family: "Consolas", "Liberation Mono", "Courier New", monospace;
  word-break: break-all;
  font-size: 0.9rem;
}

button {
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 12px rgba(217, 107, 54, 0.3);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

button.secondary {
  background: #fff;
  color: var(--accent-2);
  border: 1px solid var(--accent-2);
  box-shadow: none;
}

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

.output {
  min-height: 120px;
  display: flex;
  flex-direction: column;
  height: 100%;
}

#runtimeCard {
  display: flex;
  flex-direction: column;
  height: 100%;
  align-self: start;
}

#runtimeCard canvas {
  flex: 0 0 var(--chart-height);
  height: var(--chart-height);
}

#testsCard {
  min-height: 0;
  height: 100%;
}

.summary {
  font-weight: 600;
  margin-bottom: 12px;
}

.summary span {
  display: inline-block;
  margin-right: 10px;
}

#summary.error {
  color: var(--bad);
}

#errors {
  margin-bottom: 10px;
}

#errors.error-visible {
  background: #fbe5e4;
  border: 1px solid #e0a09a;
  color: var(--bad);
  padding: 8px 10px;
  border-radius: 10px;
  font-weight: 600;
}

.summary-meta {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 10px;
}

#authError {
  color: var(--bad);
  font-weight: 600;
}

.progress {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.progress label {
  font-weight: 600;
  margin-bottom: 0;
}

progress {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
}

progress::-webkit-progress-bar {
  background: #f1e7da;
}

progress::-webkit-progress-value {
  background: var(--accent-2);
}

progress::-moz-progress-bar {
  background: var(--accent-2);
}

.progress-bar {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f1e7da;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #2c6d6a, #4d9b7f);
  box-shadow: 0 0 10px rgba(44, 109, 106, 0.35);
  transition: width 0.35s ease;
}

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

th,
td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  word-break: break-word;
}

.table-wrap {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
}

.results-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin-top: 8px;
}

.table-wrap table {
  border: none;
}

thead th {
  background: #f6efe5;
  font-weight: 600;
}

tbody tr:nth-child(even) {
  background: #fcf8f1;
}

th:first-child,
td:first-child {
  width: 35%;
}

.highscore-table th:first-child,
.highscore-table td:first-child {
  width: 50px;
  text-align: center;
}

.highscore-table th:nth-child(2),
.highscore-table td:nth-child(2) {
  width: 20%;
}

.highscore-table th:nth-child(3),
.highscore-table td:nth-child(3) {
  width: 35%;
}

tr.fail {
  color: var(--bad);
  font-weight: 600;
}

tr.pass {
  color: var(--ok);
}

tbody[data-view="old"] tr {
    opacity: 0.75;
}

.small {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 10px;
}

.table-empty {
  text-align: center;
  color: var(--muted);
  font-style: italic;
}

.highscore {
  margin-top: 16px;
  display: grid;
  gap: 8px;
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid rgba(217, 107, 54, 0.25);
  border-top-color: var(--accent);
  display: inline-block;
  animation: spin 0.9s linear infinite;
  visibility: hidden;
}

.spinner.active {
  visibility: visible;
}

.inline-spinner {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid rgba(217, 107, 54, 0.25);
  border-top-color: var(--accent);
  display: inline-block;
  animation: spin 0.9s linear infinite;
  vertical-align: middle;
}

.runtime-tooltip {
  position: fixed;
  z-index: 1200;
  background: #fff8ee;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: 0 16px 24px var(--shadow);
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.runtime-tooltip.active {
  opacity: 1;
  transform: translateY(0);
}

.runtime-tooltip-title {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}

.runtime-tooltip canvas {
  width: 180px;
  height: 70px;
  display: block;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.chart-tooltip {
  position: fixed;
  z-index: 1200;
  background: #fff8ee;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px;
  box-shadow: 0 12px 18px var(--shadow);
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.chart-tooltip.active {
  opacity: 1;
  transform: translateY(0);
}

canvas {
  width: 100%;
  height: var(--chart-height);
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--line);
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 600px) {
  .controls-row {
    flex-direction: column;
    align-items: stretch;
  }

  button {
    width: 100%;
  }

  .task-select {
    width: 100%;
  }

  .task-select select {
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 900px) {
  .metrics-row {
    grid-template-columns: 1fr;
  }
}

/* Highscore Tabs */
.tab-group {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.tab-btn {
    padding: 6px 16px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: none;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    background: #fbf8f3;
    color: var(--ink);
}

.tab-btn.active {
    background: var(--ink);
    color: #fff;
    border-color: var(--ink);
    box-shadow: 0 4px 10px rgba(30, 36, 40, 0.2);
}

/* Rank Medals */
.rank-cell {
    font-weight: 700;
    text-align: center;
    color: var(--muted);
}

.rank-1 {
    color: #d4af37; /* Gold */
    font-size: 1.1em;
}

.rank-2 {
    color: #a9a9a9; /* Silver */
}

.rank-3 {
    color: #cd7f32; /* Bronze */
}

.tab-info {
    font-size: 0.85rem;
    color: var(--muted);
    font-style: italic;
    margin-left: 12px;
    align-self: center;
}

.col-lang {
    text-align: center;
}

.lang-icon {
    display: inline-block;
    width: 28px;
    height: 16px;
    vertical-align: middle;
}

.confetti-root {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 1400;
}

.confetti-piece {
    position: absolute;
    top: -16px;
    left: calc(var(--confetti-x) * 1%);
    width: 8px;
    height: 14px;
    border-radius: 2px;
    background: var(--confetti-color);
    transform: rotate(var(--confetti-rotate));
    opacity: 0.95;
    animation: confettiFall var(--confetti-duration) linear var(--confetti-delay) forwards;
}

@keyframes confettiFall {
    0% {
        opacity: 0;
        transform: translateY(-10px) rotate(var(--confetti-rotate));
    }
    10% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translateY(110vh) rotate(calc(var(--confetti-rotate) + 240deg));
    }
}

@media (max-width: 600px) {
    /* Hide non-essential columns on mobile */
    .col-id, .col-lang, .col-status, .col-date {
        display: none;
    }

    /* Make Name column flexible on mobile to handle long names */
    .highscore-table th.col-name,
    .highscore-table td.col-name {
        width: auto;
    }
    
    /* Ensure table layout is auto on mobile to allow flex width */
    .highscore-table {
        table-layout: auto;
    }

    /* Stack Tabs */
    .tab-group {
        flex-wrap: wrap;
    }

    /* Override global mobile button style to keep tabs inline but fill space */
    .tab-btn {
        width: auto;
        flex: 1;
    }

    .tab-info {
        width: 100%;
        margin-left: 4px;
        margin-top: 4px;
        display: block;
    }
}
