:root {
  --ink: #28261f;
  --muted: #706b57;
  --line: #d9d2b5;
  --surface: #ffffff;
  --background: #fffef8;
  --green: #1e614d;
  --green-soft: #e7f2eb;
  --yellow: #f2c94c;
  --yellow-soft: #fff3b8;
  --yellow-dark: #d5a91f;
  --coral: #f2c94c;
  --coral-dark: #dfb42d;
  --focus: #9a6d00;
  --radius: 4px;
  font-family: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", STSong, Georgia, serif;
  color: var(--ink);
  background: var(--background);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-width: 320px;
  background: var(--background);
  letter-spacing: 0;
}

body::before {
  position: fixed;
  inset: 0 0 auto;
  z-index: 40;
  height: 8px;
  background: var(--yellow);
  content: "";
  pointer-events: none;
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.wordmark {
  color: var(--ink);
  font-size: 25px;
  font-weight: 900;
  text-decoration: none;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 18px;
}

.auth-panel {
  width: min(100%, 400px);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 34px;
  box-shadow: 10px 10px 0 var(--yellow);
}

.auth-wordmark {
  display: inline-block;
  margin-bottom: 42px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 28px;
  font-size: 30px;
  font-weight: 900;
  line-height: 1.2;
}

h2 {
  margin-bottom: 16px;
  font-size: 15px;
  line-height: 1.3;
}

.form-stack {
  display: grid;
  gap: 18px;
}

.form-error {
  margin: 14px 0 0;
  border-left: 3px solid #8f2f22;
  background: #fff2ee;
  color: #76251b;
  font-size: 13px;
  line-height: 1.6;
  padding: 10px 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input {
  width: 100%;
  min-width: 0;
  height: 44px;
  border: 1px solid #aaa382;
  border-radius: 3px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
}

input[readonly] {
  background: #fff9d9;
}

.primary-button,
.secondary-button,
.copy-row button,
.nav-button,
.mobile-nav button,
.text-button {
  border-radius: 5px;
}

.primary-button {
  height: 44px;
  border: 1px solid var(--ink);
  background: var(--coral);
  color: var(--ink);
  font-weight: 900;
  padding: 0 18px;
  box-shadow: 3px 3px 0 var(--ink);
}

.primary-button:hover {
  background: var(--coral-dark);
  transform: translate(1px, 1px);
  box-shadow: 2px 2px 0 var(--ink);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.secondary-button {
  min-height: 36px;
  border: 1px solid var(--ink);
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  padding: 0 13px;
}

.secondary-button:hover,
.copy-row button:hover {
  background: #eff2ed;
}

.text-button {
  display: block;
  border: 0;
  background: transparent;
  color: var(--green);
  font-weight: 700;
  margin: 18px auto 0;
  padding: 6px;
}

.text-button.compact {
  margin: 0;
  padding: 2px 0;
  color: var(--muted);
  font-size: 12px;
}

.app-shell {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 5;
  width: 210px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--ink);
  background: var(--yellow);
  padding: 28px 20px 22px;
}

.side-nav {
  display: grid;
  gap: 6px;
  margin-top: 42px;
}

.nav-button {
  height: 40px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 800;
  text-align: left;
  padding: 0 12px;
}

.nav-button:hover {
  background: rgba(255, 255, 255, 0.52);
  color: var(--ink);
}

.nav-button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 4px 0 0 var(--green);
}

.account-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  border-top: 1px solid rgba(40, 38, 31, 0.36);
  padding-top: 16px;
}

.account-name {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-main {
  min-height: 100vh;
  margin-left: 210px;
}

.mobile-header,
.mobile-nav {
  display: none;
}

.metrics-band {
  min-height: 92px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-bottom: 1px solid var(--ink);
  background: var(--surface);
}

.metrics-band > div {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 18px 28px;
}

.metrics-band > div + div {
  border-left: 1px solid var(--line);
}

.metrics-band span {
  color: var(--muted);
  font-size: 12px;
}

.metrics-band strong {
  overflow: hidden;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
}

.content-wrap {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: 48px 34px 76px;
}

.view-section {
  min-height: 430px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 30px;
}

.section-heading h1 {
  margin: 0;
}

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

.tool-panel {
  min-width: 0;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 22px;
}

.panel-heading-row {
  min-height: 36px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.copy-row {
  min-width: 0;
  display: flex;
  gap: 8px;
}

.copy-row input {
  flex: 1 1 auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.copy-row button {
  flex: 0 0 auto;
  height: 44px;
  border: 1px solid var(--ink);
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
  padding: 0 12px;
}

.empty-line {
  height: 44px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.compact {
  min-height: 30px;
}

.models-section {
  margin-top: 36px;
  border-top: 1px solid var(--ink);
  padding-top: 24px;
}

.model-list {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.model-list code {
  border: 1px solid #c9a62f;
  border-radius: 4px;
  background: var(--yellow-soft);
  color: var(--ink);
  font-size: 12px;
  padding: 7px 9px;
}

.redeem-form {
  max-width: 680px;
  border-top: 1px solid var(--ink);
  padding-top: 26px;
}

.redeem-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.table-wrap {
  overflow-x: auto;
  border-top: 1px solid var(--ink);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 13px;
}

th,
td {
  height: 48px;
  border-bottom: 1px solid var(--line);
  padding: 8px 12px;
  text-align: left;
  white-space: nowrap;
}

th {
  background: var(--yellow-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.empty-state {
  margin: 0;
  color: var(--muted);
  padding: 38px 12px;
  text-align: center;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: min(360px, calc(100vw - 40px));
  border-radius: var(--radius);
  border: 1px solid var(--yellow);
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: #8f2f22;
}

@media (max-width: 820px) {
  .sidebar {
    display: none;
  }

  .app-main {
    margin-left: 0;
    padding-bottom: 62px;
  }

  .mobile-header {
    height: 62px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--ink);
    background: var(--yellow);
    padding: 0 18px;
  }

  .mobile-account {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .mobile-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 20;
    height: 58px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    border-top: 1px solid var(--ink);
    background: var(--surface);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .mobile-nav button {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
  }

  .mobile-nav button.active {
    color: var(--green);
    box-shadow: inset 0 4px 0 var(--yellow-dark);
  }

  .metrics-band {
    min-height: 78px;
  }

  .metrics-band > div {
    padding: 13px 15px;
  }

  .metrics-band strong {
    font-size: 17px;
  }

  .content-wrap {
    padding: 30px 18px 56px;
  }

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

@media (max-width: 520px) {
  .auth-panel {
    border: 0;
    background: transparent;
    padding: 18px 4px;
    box-shadow: none;
  }

  .metrics-band span {
    font-size: 10px;
  }

  .metrics-band strong {
    font-size: 15px;
  }

  .section-heading h1 {
    font-size: 24px;
  }

  .tool-panel {
    padding: 18px;
  }

  .copy-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .copy-row input {
    grid-column: 1 / -1;
  }

  .redeem-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .redeem-row .primary-button {
    width: 100%;
  }
}

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