:root {
  --paper: #f2eee3;
  --paper-deep: #e7dfce;
  --card: rgba(255, 253, 247, 0.88);
  --ink: #17231c;
  --ink-soft: #536057;
  --line: #c8c0ad;
  --green: #1f6a4d;
  --green-bright: #2f8d67;
  --orange: #d97a25;
  --red: #aa3f35;
  --yellow: #edc66a;
  --shadow: 0 24px 60px rgba(30, 38, 32, 0.12);
  --radius: 20px;
  --display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --body: "Avenir Next", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(23, 35, 28, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 35, 28, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 10% 0%, #fffaf0 0, transparent 34%),
    var(--paper);
  background-size: 36px 36px, 36px 36px, auto, auto;
  font-family: var(--body);
  line-height: 1.55;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
summary {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
}

[hidden] {
  display: none !important;
}

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

.page-grain {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.28;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.12'/%3E%3C/svg%3E");
}

.eyebrow,
.card-kicker,
.brand small {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.69rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.signal-dot {
  display: inline-block;
  width: 0.62rem;
  height: 0.62rem;
  margin-right: 0.45rem;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 5px color-mix(in srgb, currentColor 12%, transparent);
}

.lede {
  max-width: 37rem;
  margin: 1.4rem 0 0;
  color: var(--ink-soft);
  font-size: clamp(1rem, 1.5vw, 1.18rem);
}

.muted,
.hint {
  color: var(--ink-soft);
}

.hint {
  margin: 0;
  font-size: 0.82rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 46px;
  padding: 0.7rem 1.15rem;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 750;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

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

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

.button.primary {
  color: #fffdf7;
  background: var(--ink);
  box-shadow: 0 10px 22px rgba(23, 35, 28, 0.18);
}

.button.success {
  color: #fffdf7;
  background: var(--green);
}

.button.danger {
  color: #fffdf7;
  background: var(--red);
}

.button.secondary {
  color: var(--ink);
  background: var(--yellow);
}

.button.ghost {
  color: var(--ink);
  border-color: var(--line);
  background: transparent;
}

.button.compact {
  min-height: 36px;
  padding: 0.4rem 0.85rem;
  font-size: 0.82rem;
}

.button.wide {
  width: 100%;
  justify-content: space-between;
}

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

.stack-form label {
  display: grid;
  gap: 0.45rem;
  font-size: 0.82rem;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  padding: 0.8rem 0.9rem;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 253, 247, 0.82);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  outline: none;
  box-shadow: 0 0 0 4px rgba(31, 106, 77, 0.12);
}

.form-message,
.status-error {
  margin: 0;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  font-size: 0.85rem;
}

.form-message.error,
.status-error {
  color: #7b2821;
  background: rgba(170, 63, 53, 0.11);
}

.form-message.success {
  color: #15543b;
  background: rgba(31, 106, 77, 0.11);
}

/* Login */

.auth-page {
  display: grid;
  place-items: center;
  padding: clamp(1rem, 4vw, 4rem);
}

.auth-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  width: min(1180px, 100%);
  min-height: min(760px, calc(100vh - 8rem));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 30px;
  background: var(--card);
  box-shadow: var(--shadow);
  animation: rise-in 600ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.auth-story {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(2rem, 7vw, 5.5rem);
  overflow: hidden;
  border-right: 1px solid var(--line);
  background:
    radial-gradient(circle at 85% 20%, rgba(237, 198, 106, 0.55), transparent 24%),
    linear-gradient(145deg, rgba(31, 106, 77, 0.14), transparent 56%);
}

.auth-story::after {
  content: "✓";
  position: absolute;
  right: -0.08em;
  bottom: -0.28em;
  color: rgba(23, 35, 28, 0.055);
  font-family: var(--display);
  font-size: clamp(18rem, 35vw, 35rem);
  font-weight: 700;
  line-height: 0.8;
  transform: rotate(-8deg);
}

.auth-story > * {
  position: relative;
  z-index: 1;
}

.auth-story h1,
.hero-panel h1 {
  margin: 1.1rem 0 0;
  font-family: var(--display);
  font-size: clamp(3.4rem, 7vw, 7.2rem);
  font-weight: 500;
  letter-spacing: -0.065em;
  line-height: 0.9;
}

.auth-story h1 em,
.hero-panel h1 em {
  color: var(--green);
  font-weight: 500;
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  max-width: 35rem;
  margin-top: 3.5rem;
  border: 1px solid var(--line);
  background: var(--line);
}

.story-grid span,
.story-grid small {
  display: block;
  padding: 0.9rem 1rem;
  background: var(--paper);
}

.story-grid span {
  padding-bottom: 0;
  font-family: var(--display);
  font-size: clamp(1.8rem, 4vw, 3.2rem);
  line-height: 1;
}

.story-grid small {
  padding-top: 0.2rem;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 0.68rem;
}

.auth-footnote {
  margin: 2rem 0 0;
  color: var(--ink-soft);
  font-size: 0.76rem;
}

.auth-card {
  align-self: center;
  padding: clamp(2rem, 5vw, 4.5rem);
}

.auth-card h2,
.panel h2 {
  margin: 0.4rem 0 0;
  font-family: var(--display);
  font-size: clamp(2rem, 3vw, 3rem);
  font-weight: 500;
  letter-spacing: -0.04em;
}

.auth-card .stack-form {
  margin-top: 2rem;
}

.security-note {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.8rem;
  margin-top: 2.5rem;
  padding-top: 1.2rem;
  color: var(--ink-soft);
  border-top: 1px solid var(--line);
  font-size: 0.78rem;
}

.security-note > span {
  color: var(--green);
  font-size: 1.4rem;
}

.security-note p {
  margin: 0;
}

/* Dashboard */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1rem, 4vw, 3rem);
  border-bottom: 1px solid rgba(200, 192, 173, 0.8);
  background: rgba(242, 238, 227, 0.88);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #fffdf7;
  border-radius: 50% 50% 50% 12%;
  background: var(--green);
  font-family: var(--display);
  font-size: 1.4rem;
  transform: rotate(-4deg);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-family: var(--display);
  font-size: 1.25rem;
}

.brand small {
  color: var(--ink-soft);
  font-size: 0.56rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.connection-state {
  display: inline-flex;
  align-items: center;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 0.68rem;
}

.connection-state[data-state="connected"] {
  color: var(--green);
}

.connection-state[data-state="disconnected"] {
  color: var(--red);
}

.dashboard-shell {
  width: min(1420px, 100%);
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 4rem);
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: clamp(2rem, 6vw, 6rem);
  align-items: end;
  padding-bottom: clamp(2rem, 5vw, 4.5rem);
  animation: rise-in 600ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.hero-panel h1 {
  font-size: clamp(4rem, 9vw, 9rem);
}

.status-board {
  position: relative;
  padding: 1.5rem;
  overflow: hidden;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: #f7f1e4;
  box-shadow: 12px 12px 0 rgba(217, 122, 37, 0.22);
}

.status-board::after {
  content: "";
  position: absolute;
  top: -40px;
  right: -40px;
  width: 140px;
  height: 140px;
  border: 24px solid rgba(237, 198, 106, 0.12);
  border-radius: 50%;
}

.status-value {
  margin: 0.8rem 0 1.4rem;
  color: var(--yellow);
  font-family: var(--display);
  font-size: clamp(2.2rem, 4vw, 3.7rem);
  line-height: 1;
}

.status-value[data-state="running"] {
  color: #66d39e;
}

.status-value[data-state="error"] {
  color: #ff9186;
}

.status-facts {
  display: grid;
  gap: 0.65rem;
  margin: 0;
}

.status-facts div {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: 0.8rem;
  padding-top: 0.65rem;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

.status-facts dt {
  color: #aeb8b1;
  font-size: 0.72rem;
}

.status-facts dd {
  margin: 0;
  text-align: right;
  font-size: 0.82rem;
}

.status-error {
  position: relative;
  z-index: 1;
  margin-top: 1rem;
  color: #ffd1cc;
  background: rgba(255, 145, 134, 0.12);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 1rem;
}

.panel {
  position: relative;
  padding: clamp(1.25rem, 2.4vw, 2rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 10px 30px rgba(23, 35, 28, 0.05);
  animation: rise-in 600ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.auth-panel {
  grid-column: span 5;
  animation-delay: 80ms;
}

.monitor-panel {
  grid-column: span 7;
  animation-delay: 140ms;
}

.locations-panel {
  grid-column: span 5;
  animation-delay: 200ms;
}

.log-panel {
  grid-column: span 7;
  animation-delay: 260ms;
}

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

.panel h2 {
  font-size: 2rem;
}

.tag {
  padding: 0.32rem 0.7rem;
  color: var(--green);
  border: 1px solid rgba(31, 106, 77, 0.28);
  border-radius: 999px;
  background: rgba(31, 106, 77, 0.08);
  font-family: var(--mono);
  font-size: 0.67rem;
}

.auth-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1rem;
  padding: 0.3rem;
  border-radius: 999px;
  background: var(--paper-deep);
}

.auth-tab {
  flex: 1;
  padding: 0.55rem 0.8rem;
  color: var(--ink-soft);
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 750;
}

.auth-tab.active {
  color: var(--ink);
  background: #fffdf7;
  box-shadow: 0 3px 10px rgba(23, 35, 28, 0.08);
}

.authorization-source {
  display: grid;
  gap: 0.7rem;
  margin-bottom: 1.2rem;
  padding: 1rem;
  border: 1px dashed #b9ae97;
  border-radius: 14px;
  background: rgba(237, 198, 106, 0.12);
}

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

.authorization-heading h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.2rem;
  font-weight: 700;
}

.authorization-steps {
  display: grid;
  gap: 0.28rem;
  margin: 0;
  padding-left: 1.15rem;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.authorization-link-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.55rem;
}

.authorization-link-row input,
.authorization-link-row textarea {
  min-width: 0;
  overflow: hidden;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 0.68rem;
  text-overflow: ellipsis;
}

.authorization-link-row textarea {
  resize: none;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.button-row {
  display: flex;
  gap: 0.7rem;
}

.check-row {
  display: flex !important;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.7rem !important;
  cursor: pointer;
}

.check-row input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--green);
}

.button-row .button {
  flex: 1;
}

.locations-panel details {
  margin: 0;
}

.locations-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  list-style: none;
}

.locations-panel summary::-webkit-details-marker {
  display: none;
}

.locations-panel summary strong {
  display: block;
  margin-top: 0.35rem;
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 500;
}

.summary-action {
  color: var(--green);
  font-family: var(--mono);
  font-size: 0.72rem;
}

.location-body {
  display: grid;
  gap: 1rem;
  margin-top: 1.5rem;
}

.location-list {
  display: grid;
  gap: 0.7rem;
}

.location-row {
  display: grid;
  grid-template-columns: minmax(120px, 1.3fr) repeat(2, minmax(90px, 0.8fr)) minmax(100px, 1fr);
  gap: 0.55rem;
  align-items: end;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(242, 238, 227, 0.55);
}

.location-row label {
  display: grid;
  gap: 0.25rem;
  font-family: var(--mono);
  font-size: 0.62rem;
  color: var(--ink-soft);
}

.location-row input {
  padding: 0.55rem;
  font-size: 0.8rem;
}

.location-row .course-name {
  padding-bottom: 0.55rem;
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 700;
}

.log-view {
  min-height: 280px;
  max-height: 420px;
  overflow: auto;
  padding: 1rem;
  color: #dfe8df;
  border-radius: 14px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    #16221b;
  background-size: 100% 26px, auto;
  font-family: var(--mono);
  font-size: 0.76rem;
}

.log-line {
  display: grid;
  grid-template-columns: 6.5rem 5rem 1fr;
  gap: 0.6rem;
  padding: 0.24rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.log-time {
  color: #839389;
}

.log-level {
  color: #b5c7ba;
  text-transform: uppercase;
}

.log-line[data-level="success"] .log-level {
  color: #72d8a3;
}

.log-line[data-level="warning"] .log-level {
  color: var(--yellow);
}

.log-line[data-level="error"] .log-level {
  color: #ff9186;
}

.log-placeholder {
  margin: 0;
  color: #839389;
}

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

@media (max-width: 980px) {
  .auth-shell {
    grid-template-columns: 1fr;
  }

  .auth-story {
    min-height: 360px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .hero-panel {
    grid-template-columns: 1fr;
  }

  .auth-panel,
  .monitor-panel,
  .locations-panel,
  .log-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .auth-page {
    padding: 0.6rem;
  }

  .auth-shell {
    border-radius: 22px;
  }

  .auth-story,
  .auth-card {
    padding: 1.6rem;
  }

  .auth-story h1 {
    font-size: 3.4rem;
  }

  .story-grid {
    margin-top: 2rem;
  }

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

  .connection-state {
    display: none;
  }

  .dashboard-shell {
    padding: 1rem 0.7rem 2rem;
  }

  .hero-panel h1 {
    font-size: 4rem;
  }

  .status-board {
    box-shadow: 6px 6px 0 rgba(217, 122, 37, 0.22);
  }

  .panel {
    padding: 1.15rem;
  }

  .location-row {
    grid-template-columns: 1fr 1fr;
  }

  .location-row .course-name {
    grid-column: 1 / -1;
  }

  .authorization-link-row {
    grid-template-columns: 1fr;
  }

  .log-line {
    grid-template-columns: 1fr auto;
  }

  .log-message {
    grid-column: 1 / -1;
  }
}

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