:root {
  --bg: #050b14;
  --bg-2: #0a1523;
  --surface: #0f1e2f;
  --surface-2: #132741;
  --text: #f1f4f8;
  --muted: #9db0c7;
  --line: rgba(157, 176, 199, 0.2);
  --accent: #ffb648;
  --accent-ink: #301c00;
  --danger: #ff6b6b;
  --success: #5ad4a7;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  overflow-x: hidden;
  background: radial-gradient(circle at 12% -5%, #14335f 0%, transparent 42%),
              radial-gradient(circle at 88% 10%, #2a1f3e 0%, transparent 35%),
              var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 2px solid rgba(255, 182, 72, .9);
  outline-offset: 2px;
}

.ambient-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
      linear-gradient(125deg, rgba(255, 182, 72, 0.05), transparent 35%),
      linear-gradient(235deg, rgba(112, 166, 255, 0.08), transparent 40%);
}

.shell {
  position: relative;
  min-height: 100vh;
  width: min(1400px, 100%);
  margin: 0 auto;
  overflow-x: clip;
}

.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 18, 31, .94);
  position: sticky;
  top: 0;
  z-index: 90;
  backdrop-filter: blur(5px);
}

.mobile-brand {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .11em;
  font-weight: 700;
  font-size: .76rem;
}

.menu-toggle {
  background: transparent;
  border: 1px solid var(--line);
  padding: .46rem;
  display: inline-grid;
  gap: .23rem;
  cursor: pointer;
}

.menu-toggle span {
  display: block;
  width: 1.15rem;
  height: 2px;
  background: var(--text);
}

.mobile-overlay {
  position: fixed;
  inset: 0;
  z-index: 85;
  background: rgba(5, 11, 20, .7);
}

.shell-auth {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 2rem;
  padding: 1.5rem;
}

.shell-guest {
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(15, 30, 47, 0.95), rgba(10, 21, 35, 0.92));
  padding: 1.4rem;
  border-radius: 2px;
}

.brand-lockup h1 {
  margin: .25rem 0 .6rem;
  font-family: "Instrument Serif", serif;
  font-weight: 400;
  font-size: clamp(1.8rem, 3vw, 2.3rem);
  line-height: 1.05;
}

.brand-tag {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .13em;
  color: var(--accent);
  margin: 0;
}

.brand-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: .95rem;
}

.nav-stack {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: .8rem 0;
}

.nav-link {
  color: var(--text);
  padding: .6rem .2rem;
  transition: transform .2s ease, color .2s ease;
}

.nav-link:hover {
  color: var(--accent);
  transform: translateX(4px);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: .9rem;
}

.user-chip {
  margin: 0;
  color: var(--muted);
  font-size: .9rem;
}

.workspace {
  width: 100%;
  display: grid;
  gap: 1.2rem;
  align-content: start;
  min-width: 0;
}

.workspace-header {
  border-bottom: 1px solid var(--line);
  padding-bottom: .9rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
}

.kicker {
  margin: 0;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--accent);
}

h2, h3 {
  margin: .35rem 0 0;
  font-weight: 600;
}

.workspace-header h2 {
  font-size: clamp(1.6rem, 2.3vw, 2.2rem);
}

.header-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .8rem;
  color: var(--muted);
  font-size: .9rem;
}

.workspace-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
}

.pane {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(19, 39, 65, 0.5), rgba(10, 21, 35, 0.7));
  padding: 1rem;
  min-width: 0;
  border-radius: 2px;
}

.muted {
  color: var(--muted);
}

.inline-actions {
  display: flex;
  gap: .6rem;
  align-items: center;
  flex-wrap: wrap;
  margin: .8rem 0;
}

.stack-form {
  display: grid;
  gap: .65rem;
}

label {
  font-size: .86rem;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #091525;
  color: var(--text);
  padding: .66rem .72rem;
  outline: none;
  transition: border-color .2s ease, transform .2s ease;
  font-family: inherit;
  border-radius: 2px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(255, 182, 72, .7);
  transform: translateY(-1px);
}

.btn {
  border: 1px solid transparent;
  padding: .66rem 1rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s ease, filter .2s ease;
  font-family: inherit;
  border-radius: 2px;
}

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

.btn:disabled,
.btn.is-loading {
  cursor: not-allowed;
  filter: grayscale(.1);
  opacity: .86;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-outline {
  background: transparent;
  border-color: rgba(255, 182, 72, .45);
  color: var(--accent);
}

.inline-error {
  color: var(--danger);
  margin: 0 0 .8rem;
}

.data-list p {
  margin: .2rem 0;
  color: var(--muted);
  font-size: .92rem;
}

.data-list span {
  color: #c9d9eb;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th,
td {
  text-align: left;
  padding: .64rem .35rem;
  border-bottom: 1px solid var(--line);
}

th {
  color: #c4d2e1;
  font-size: .86rem;
  font-weight: 500;
}

td {
  color: var(--text);
  font-size: .92rem;
}

.table-link {
  font-weight: 600;
}

.table-link:focus-visible {
  border-radius: 2px;
}

.result-panel {
  border: 1px solid rgba(255, 182, 72, .35);
  padding: 1.2rem;
  background: linear-gradient(145deg, rgba(255, 182, 72, .1), rgba(10, 21, 35, .85));
  border-radius: 2px;
}

.result-label {
  margin: 0;
  color: #ffe0a7;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-size: .74rem;
}

.result-panel h3 {
  margin: .4rem 0 .5rem;
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-family: "Instrument Serif", serif;
  font-weight: 400;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  color: #d1deec;
}

.result-meta code {
  word-break: break-all;
}

.ranking-list {
  margin: .4rem 0 0;
  padding-left: 1rem;
  display: grid;
  gap: .45rem;
}

.ranking-list li {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed var(--line);
  padding-bottom: .35rem;
}

.rank-index {
  color: var(--accent);
  margin-right: .28rem;
}

.auth-screen {
  width: min(960px, 100%);
  min-height: calc(100svh - 3rem);
  display: grid;
  grid-template-columns: 1.25fr .9fr;
  border: 1px solid var(--line);
  background: radial-gradient(circle at 8% 14%, rgba(255, 182, 72, .16), transparent 45%),
              radial-gradient(circle at 88% 8%, rgba(77, 133, 224, .2), transparent 42%),
              linear-gradient(120deg, rgba(6, 14, 24, .68), rgba(6, 14, 24, .92));
  border-radius: 2px;
}

.auth-intro {
  padding: 2rem;
  align-self: end;
}

.auth-intro h2 {
  margin: .4rem 0 .7rem;
  font-family: "Instrument Serif", serif;
  font-weight: 400;
  font-size: clamp(2rem, 3.8vw, 3rem);
  line-height: 1.03;
  max-width: 16ch;
}

.auth-intro p {
  margin: 0;
  max-width: 36ch;
  color: #d4dfec;
}

.auth-form {
  background: rgba(7, 17, 29, .88);
  backdrop-filter: blur(2px);
  border-left: 1px solid var(--line);
  padding: 1.8rem 1.4rem;
  display: grid;
  gap: .62rem;
  align-content: center;
}

.auth-link {
  margin: .6rem 0 0;
  color: var(--muted);
  font-size: .9rem;
}

.flash-stack {
  display: grid;
  gap: .6rem;
}

.flash {
  border: 1px solid var(--line);
  padding: .72rem .9rem;
  font-size: .92rem;
  border-radius: 2px;
}

.manual-connection {
  margin-top: .25rem;
  border: 1px solid var(--line);
  padding: .68rem;
  border-radius: 2px;
  background: rgba(9, 21, 37, .35);
}

.manual-connection summary {
  cursor: pointer;
  color: var(--muted);
  font-size: .86rem;
  list-style: none;
}

.manual-connection summary::-webkit-details-marker {
  display: none;
}

.manual-connection summary::before {
  content: "▶";
  display: inline-block;
  margin-right: .4rem;
  transition: transform .2s ease;
}

.manual-connection[open] summary::before {
  transform: rotate(90deg);
}

.manual-connection .stack-form {
  margin-top: .75rem;
}

.empty-state {
  display: grid;
  gap: .35rem;
  justify-items: start;
  padding: .85rem;
  border: 1px dashed var(--line);
  border-radius: 2px;
  background: rgba(9, 21, 37, .24);
}

.empty-emoji {
  margin: 0;
  font-size: 1.15rem;
}

.empty-title {
  margin: 0;
  font-weight: 600;
}

.form-feedback {
  font-size: .86rem;
}

.workspace-header-action {
  white-space: nowrap;
}

.error-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.error-box {
  width: min(520px, 100%);
  text-align: center;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(19, 39, 65, 0.52), rgba(10, 21, 35, 0.72));
  padding: 2rem 1.2rem;
  border-radius: 2px;
}

.error-code {
  margin: .3rem 0 0;
  font-size: clamp(3rem, 12vw, 5.2rem);
  line-height: 1;
  color: rgba(255, 182, 72, .2);
  font-weight: 700;
}

.error-title {
  margin: .45rem 0;
  font-size: clamp(1.35rem, 4vw, 1.8rem);
}

.error-message {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.error-actions {
  margin-top: 1rem;
  display: flex;
  gap: .55rem;
  justify-content: center;
  flex-wrap: wrap;
}

.flash-success {
  border-color: rgba(90, 212, 167, .45);
  background: rgba(90, 212, 167, .12);
}

.flash-error {
  border-color: rgba(255, 107, 107, .52);
  background: rgba(255, 107, 107, .12);
}

.flash-info {
  border-color: rgba(157, 176, 199, .35);
  background: rgba(157, 176, 199, .12);
}

.reveal {
  animation: rise .55s cubic-bezier(.2, .64, .32, 1) both;
}

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

@media (max-width: 1080px) {
  .shell-auth {
    grid-template-columns: 1fr;
    padding-top: .8rem;
  }

  .mobile-topbar {
    display: flex;
  }

  .sidebar {
    gap: 1rem;
    position: fixed;
    top: 0;
    left: 0;
    width: min(85vw, 320px);
    height: 100vh;
    z-index: 92;
    margin: 0;
    border-radius: 0;
    transform: translateX(-102%);
    transition: transform .24s ease;
    overflow-y: auto;
  }

  .sidebar.open {
    transform: translateX(0);
  }

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

@media (max-width: 820px) {
  .shell-guest {
    place-items: start stretch;
  }

  .auth-screen {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .auth-form {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 640px) {
  .shell-auth,
  .shell-guest {
    padding: .8rem;
  }

  .workspace-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .workspace-header .workspace-header-action,
  .workspace-header .btn {
    width: 100%;
  }

  .auth-form {
    align-content: start;
  }

  table {
    min-width: 520px;
  }
}
