:root {
  --ink: #10171d;
  --ink-soft: #1a252d;
  --paper: #f3eddf;
  --paper-muted: #d9d0bf;
  --gold: #d7aa4c;
  --gold-bright: #f4ce75;
  --teal: #2c8f82;
  --danger: #b74c3e;
  --success: #4f9d73;
  --line: rgba(22, 31, 37, 0.14);
  --shadow: 0 24px 70px rgba(9, 15, 19, 0.18);
  --serif: "Songti SC", "STSong", "SimSun", Georgia, serif;
  --sans: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--ink);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  background:
    linear-gradient(rgba(243, 237, 223, 0.94), rgba(243, 237, 223, 0.94)),
    repeating-linear-gradient(90deg, transparent 0 79px, rgba(16, 23, 29, 0.08) 80px),
    repeating-linear-gradient(0deg, transparent 0 79px, rgba(16, 23, 29, 0.08) 80px);
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.ambient {
  position: fixed;
  z-index: 0;
  border-radius: 999px;
  pointer-events: none;
  filter: blur(3px);
}

.ambient-one {
  width: 38rem;
  height: 38rem;
  right: -15rem;
  top: -17rem;
  background: radial-gradient(circle, rgba(215, 170, 76, 0.3), transparent 68%);
}

.ambient-two {
  width: 28rem;
  height: 28rem;
  left: -12rem;
  bottom: -10rem;
  background: radial-gradient(circle, rgba(44, 143, 130, 0.2), transparent 70%);
}

.eyebrow,
.section-index {
  margin: 0;
  color: var(--gold);
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.muted {
  color: #657078;
}

.login-shell {
  position: relative;
  z-index: 1;
  width: min(1120px, calc(100% - 40px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(360px, 0.75fr);
  align-items: center;
  gap: clamp(2rem, 7vw, 7rem);
  padding: 4rem 0;
}

.login-brand {
  position: relative;
  color: var(--paper);
  padding: clamp(2.5rem, 6vw, 5rem);
  min-height: 590px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background:
    linear-gradient(135deg, rgba(215, 170, 76, 0.15), transparent 42%),
    linear-gradient(150deg, #17232b, #0d1419 66%);
  border: 1px solid rgba(215, 170, 76, 0.28);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: rise 600ms ease-out both;
}

.login-brand::before {
  content: "";
  position: absolute;
  inset: 18px;
  border: 1px solid rgba(215, 170, 76, 0.22);
  pointer-events: none;
}

.login-brand::after {
  content: "";
  position: absolute;
  width: 21rem;
  height: 21rem;
  right: -8rem;
  bottom: -8rem;
  border: 1px solid rgba(215, 170, 76, 0.22);
  transform: rotate(45deg);
}

.login-brand h1 {
  position: relative;
  z-index: 1;
  max-width: 9em;
  margin: 1.2rem 0;
  font-family: var(--serif);
  font-size: clamp(2.6rem, 5vw, 4.9rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.08;
}

.brand-copy {
  position: relative;
  z-index: 1;
  max-width: 31rem;
  margin: 0;
  color: var(--paper-muted);
  font-size: 0.96rem;
  line-height: 1.9;
}

.seal {
  position: relative;
  z-index: 1;
  width: 4.6rem;
  height: 4.6rem;
  margin-top: 2.8rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold);
  color: var(--gold-bright);
  font-family: var(--serif);
  font-size: 1.1rem;
  letter-spacing: 0.12em;
}

.login-card {
  background: rgba(250, 247, 239, 0.94);
  padding: clamp(2rem, 4vw, 3.5rem);
  border-top: 4px solid var(--gold);
  box-shadow: var(--shadow);
  animation: rise 600ms 100ms ease-out both;
}

.login-card h2 {
  margin: 0.65rem 0 0.4rem;
  font-family: var(--serif);
  font-size: 2.2rem;
}

.stack {
  display: grid;
  gap: 1.15rem;
  margin-top: 2rem;
}

label {
  display: grid;
  gap: 0.5rem;
  color: #3f4b52;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

input,
select {
  width: 100%;
  min-height: 46px;
  padding: 0.7rem 0.9rem;
  border: 1px solid rgba(16, 23, 29, 0.2);
  border-radius: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  outline: none;
  transition: border-color 160ms, box-shadow 160ms, background 160ms;
}

input:focus,
select:focus {
  border-color: var(--teal);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(44, 143, 130, 0.13);
}

.button {
  min-height: 42px;
  padding: 0.65rem 1.15rem;
  border: 1px solid transparent;
  border-radius: 0;
  font-weight: 700;
  transition: transform 150ms, box-shadow 150ms, background 150ms;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.62;
  transform: none;
}

.button-primary {
  color: #111820;
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  border-color: var(--gold);
  box-shadow: 0 9px 24px rgba(215, 170, 76, 0.22);
}

.button-primary:hover {
  box-shadow: 0 12px 28px rgba(215, 170, 76, 0.34);
}

.button-ghost {
  color: inherit;
  background: transparent;
  border-color: rgba(16, 23, 29, 0.2);
}

.button-small {
  min-height: 34px;
  padding: 0.4rem 0.75rem;
  font-size: 0.76rem;
  color: var(--ink);
  background: var(--paper);
}

.form-error {
  min-height: 1.2rem;
  margin: 0;
  color: var(--danger);
  font-size: 0.8rem;
}

.dashboard {
  position: relative;
  z-index: 1;
  width: min(1500px, calc(100% - 40px));
  margin: 0 auto;
  padding: 2.2rem 0 3rem;
  animation: fade 450ms ease-out both;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 2rem;
  padding: 1.4rem 0 1.8rem;
  border-bottom: 1px solid rgba(16, 23, 29, 0.25);
}

.topbar h1 {
  margin: 0.35rem 0 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 4vw, 3.4rem);
  letter-spacing: -0.04em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: #536068;
  font-size: 0.76rem;
}

.connection i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 5px rgba(79, 157, 115, 0.12);
}

.admin-name {
  font-weight: 700;
  font-size: 0.84rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1.35fr repeat(4, 1fr);
  gap: 1px;
  margin: 1.7rem 0;
  background: var(--line);
  border: 1px solid var(--line);
}

.stat-card {
  min-height: 142px;
  padding: 1.35rem;
  background: rgba(250, 247, 239, 0.9);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stat-card span,
.stat-card small {
  color: #68737a;
  font-size: 0.72rem;
}

.stat-card strong {
  font-family: var(--serif);
  font-size: clamp(2.1rem, 4vw, 3.4rem);
  font-weight: 700;
  line-height: 1;
}

.stat-total {
  color: var(--paper);
  background: var(--ink);
}

.stat-total span,
.stat-total small {
  color: var(--paper-muted);
}

.stat-risk strong {
  color: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(310px, 0.72fr) minmax(0, 2fr);
  gap: 1.2rem;
  align-items: start;
}

.panel {
  background: rgba(250, 247, 239, 0.94);
  border: 1px solid var(--line);
  box-shadow: 0 15px 45px rgba(16, 23, 29, 0.08);
}

.create-panel,
.license-panel,
.events-panel {
  padding: 1.5rem;
}

.create-panel {
  position: sticky;
  top: 1rem;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

.panel-heading h2 {
  margin: 0.42rem 0 0;
  font-family: var(--serif);
  font-size: 1.65rem;
}

.panel-mark {
  min-width: 3.3rem;
  padding: 0.45rem;
  text-align: center;
  border: 1px solid var(--gold);
  color: #946b1e;
  font-family: var(--serif);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.prebind-fields {
  margin: 0;
  padding: 0.9rem;
  border: 1px dashed rgba(16, 23, 29, 0.22);
}

.prebind-fields legend {
  padding: 0 0.35rem;
  color: #556168;
  font-size: 0.72rem;
  font-weight: 700;
}

.prebind-fields > label + .form-grid {
  margin-top: 0.8rem;
}

.prebind-fields .fine-print {
  margin-top: 0.7rem;
}

.fine-print {
  margin: 0;
  color: #737d82;
  font-size: 0.7rem;
  line-height: 1.6;
}

.generated-panel {
  margin-top: 1.5rem;
  padding: 1rem;
  color: var(--paper);
  background: var(--ink);
  border-top: 3px solid var(--gold);
}

.generated-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.generated-heading h3 {
  margin: 0.3rem 0 0;
  font-family: var(--serif);
  font-size: 1.25rem;
}

.generated-codes {
  display: grid;
  gap: 0.55rem;
  margin-top: 1rem;
}

.generated-code {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.7rem;
  color: var(--gold-bright);
  background: rgba(255, 255, 255, 0.06);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.generated-code button {
  flex: 0 0 auto;
  border: 0;
  color: var(--paper);
  background: transparent;
  text-decoration: underline;
}

.quick-guide {
  margin-top: 1.6rem;
  padding-top: 1.3rem;
  border-top: 1px solid var(--line);
}

.quick-guide h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.1rem;
}

.quick-guide ol {
  margin: 0.85rem 0 0;
  padding-left: 1.2rem;
  color: #59656c;
  font-size: 0.78rem;
  line-height: 1.8;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 0.75rem;
  margin: 1.25rem 0;
}

.table-wrap {
  overflow-x: auto;
}

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

th {
  padding: 0.75rem 0.65rem;
  color: #6d777c;
  font-size: 0.67rem;
  letter-spacing: 0.08em;
  text-align: left;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(16, 23, 29, 0.2);
}

td {
  padding: 0.9rem 0.65rem;
  vertical-align: top;
  font-size: 0.78rem;
  border-bottom: 1px solid rgba(16, 23, 29, 0.09);
}

tbody tr {
  transition: background 140ms;
}

tbody tr:hover {
  background: rgba(215, 170, 76, 0.07);
}

.license-id {
  font-family: var(--serif);
  font-weight: 700;
}

.license-key {
  display: block;
  margin-top: 0.2rem;
  color: #69747a;
  font-family: Consolas, monospace;
  font-size: 0.7rem;
}

.binding {
  display: grid;
  gap: 0.2rem;
}

.binding code {
  color: #303d44;
  font-family: Consolas, monospace;
  font-size: 0.7rem;
}

.account-money {
  display: grid;
  gap: 0.2rem;
  min-width: 112px;
}

.account-money strong {
  color: #223039;
  font-family: var(--serif);
  font-size: 0.92rem;
}

.account-money span {
  color: #707b81;
  font-size: 0.66rem;
}

.account-type {
  display: inline-flex;
  width: fit-content;
  padding: 0.15rem 0.42rem;
  font-size: 0.62rem !important;
  font-weight: 700;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
}

.account-demo {
  color: #855f14 !important;
  background: rgba(215, 170, 76, 0.14);
  border-color: rgba(215, 170, 76, 0.36);
}

.account-real {
  color: #236e56 !important;
  background: rgba(79, 157, 115, 0.13);
  border-color: rgba(79, 157, 115, 0.32);
}

.account-contest {
  color: #6a4a9c !important;
  background: rgba(140, 108, 199, 0.14);
  border-color: rgba(140, 108, 199, 0.34);
}

.account-unknown {
  color: #6b7480 !important;
  background: rgba(130, 140, 152, 0.12);
  border-color: rgba(130, 140, 152, 0.3);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0.2rem 0.55rem;
  font-size: 0.68rem;
  font-weight: 700;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status-unused {
  color: #756129;
  background: rgba(215, 170, 76, 0.14);
  border-color: rgba(215, 170, 76, 0.34);
}

.status-active {
  color: #236e56;
  background: rgba(79, 157, 115, 0.13);
  border-color: rgba(79, 157, 115, 0.3);
}

.status-expired {
  color: #73544f;
  background: rgba(183, 76, 62, 0.08);
  border-color: rgba(183, 76, 62, 0.22);
}

.status-revoked {
  color: #8d3027;
  background: rgba(183, 76, 62, 0.14);
  border-color: rgba(183, 76, 62, 0.3);
}

.status-merged {
  color: #4a5568;
  background: rgba(106, 122, 138, 0.12);
  border-color: rgba(106, 122, 138, 0.28);
}

.tm-badge {
  display: inline-block;
  margin-left: 0.25rem;
  padding: 0.05rem 0.4rem;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1.5;
  border: 1px solid transparent;
  white-space: nowrap;
}

.tm-real {
  color: #236e56;
  background: rgba(79, 157, 115, 0.16);
  border-color: rgba(79, 157, 115, 0.34);
}

.tm-demo {
  color: #8a5a12;
  background: rgba(215, 170, 76, 0.18);
  border-color: rgba(215, 170, 76, 0.38);
}

.tm-contest {
  color: #4c5b8a;
  background: rgba(93, 116, 176, 0.14);
  border-color: rgba(93, 116, 176, 0.32);
}

.tm-unknown {
  color: #707b81;
  background: rgba(112, 123, 129, 0.1);
  border-color: rgba(112, 123, 129, 0.26);
}

.date-sub.carried {
  color: #236e56;
}

.date-main {
  display: block;
}

.date-sub {
  display: block;
  margin-top: 0.2rem;
  color: #758087;
  font-size: 0.68rem;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.row-actions button {
  padding: 0.28rem 0.45rem;
  border: 1px solid rgba(16, 23, 29, 0.18);
  color: #354148;
  background: transparent;
  font-size: 0.67rem;
}

.row-actions button:hover {
  background: rgba(16, 23, 29, 0.06);
}

.row-actions button.danger {
  color: var(--danger);
  border-color: rgba(183, 76, 62, 0.32);
}

.empty-state {
  padding: 3rem 1rem;
  color: #78838a;
  text-align: center;
}

.events-panel {
  margin-top: 1.2rem;
}

.event-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin-top: 1rem;
  background: var(--line);
  border: 1px solid var(--line);
}

.event-item {
  display: grid;
  grid-template-columns: 9.5rem minmax(0, 1fr) auto;
  gap: 0.8rem;
  align-items: center;
  padding: 0.75rem;
  background: rgba(250, 247, 239, 0.96);
  font-size: 0.72rem;
}

.event-type {
  color: #46535a;
  font-weight: 700;
}

.event-meta {
  color: #747f85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-time {
  color: #8b949a;
  font-size: 0.65rem;
  white-space: nowrap;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem 0 0;
  color: #707b81;
  font-size: 0.67rem;
  letter-spacing: 0.08em;
}

.toast {
  position: fixed;
  right: 1.2rem;
  bottom: 1.2rem;
  z-index: 20;
  max-width: min(420px, calc(100% - 2.4rem));
  padding: 0.9rem 1.1rem;
  color: var(--paper);
  background: var(--ink);
  border-left: 3px solid var(--gold);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms, transform 180ms;
  font-size: 0.8rem;
}

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

.toast.error {
  border-left-color: var(--danger);
}

.money-positive {
  color: var(--success) !important;
}

.money-negative {
  color: var(--danger) !important;
}

.account-dialog {
  width: min(1120px, calc(100% - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid rgba(16, 23, 29, 0.22);
  box-shadow: 0 30px 100px rgba(6, 11, 14, 0.45);
}

.account-dialog::backdrop {
  background: rgba(9, 15, 19, 0.72);
  backdrop-filter: blur(3px);
}

.dialog-heading {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.4rem 1.5rem;
  background: rgba(243, 237, 223, 0.98);
  border-bottom: 1px solid var(--line);
}

.dialog-heading h2 {
  margin: 0.4rem 0 0;
  font-family: var(--serif);
  font-size: 1.7rem;
}

.account-details {
  padding: 1.5rem;
}

.account-identity {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 1rem;
  padding: 1rem 1.1rem;
  color: var(--paper);
  background:
    linear-gradient(120deg, rgba(215, 170, 76, 0.2), transparent 55%),
    var(--ink-soft);
  border-left: 4px solid var(--gold);
}

.account-identity span {
  color: var(--gold-bright);
  font-size: 0.67rem;
  letter-spacing: 0.08em;
}

.account-identity strong {
  font-family: var(--serif);
  font-size: 1.45rem;
}

.account-identity small {
  color: var(--paper-muted);
  font-size: 0.7rem;
}

.account-hero {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
}

.account-hero > div {
  min-height: 124px;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--ink);
  color: var(--paper);
}

.account-hero span {
  color: var(--paper-muted);
  font-size: 0.72rem;
}

.account-hero strong {
  font-family: var(--serif);
  font-size: clamp(1.45rem, 3vw, 2.4rem);
}

.account-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  margin-top: 1rem;
  background: var(--line);
  border: 1px solid var(--line);
}

.account-metrics > div {
  min-height: 82px;
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.45);
}

.account-metrics span {
  color: #727d83;
  font-size: 0.67rem;
}

.account-metrics strong {
  font-size: 0.84rem;
}

.dialog-section {
  margin-top: 1.5rem;
}

.dialog-section h3 {
  margin: 0 0 0.7rem;
  font-family: var(--serif);
  font-size: 1.15rem;
}

.compact-table {
  min-width: 720px;
  background: rgba(255, 255, 255, 0.35);
}

.compact-table th,
.compact-table td {
  padding: 0.65rem;
  font-size: 0.72rem;
}

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

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (max-width: 1100px) {
  .login-shell {
    grid-template-columns: 1fr;
    max-width: 720px;
  }

  .login-brand {
    min-height: 420px;
  }

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

  .stat-total {
    grid-column: span 2;
  }

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

  .create-panel {
    position: static;
  }

  .event-list {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 680px) {
  .login-shell,
  .dashboard {
    width: min(100% - 24px, 1500px);
  }

  .login-brand {
    min-height: 360px;
    padding: 2rem;
  }

  .login-brand h1 {
    font-size: 2.5rem;
  }

  .login-card,
  .create-panel,
  .license-panel,
  .events-panel {
    padding: 1.1rem;
  }

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

  .topbar-actions {
    justify-content: flex-start;
  }

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

  .stat-total {
    grid-column: span 2;
  }

  .stat-card {
    min-height: 118px;
  }

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

  .event-item {
    grid-template-columns: 1fr auto;
  }

  .account-hero,
  .account-metrics {
    grid-template-columns: 1fr;
  }

  .account-details,
  .dialog-heading {
    padding: 1rem;
  }

  .event-meta {
    grid-column: span 2;
  }

  footer {
    flex-direction: column;
  }
}

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