:root {
  --ink: #172027;
  --muted: #66717b;
  --subtle: #8b96a1;
  --paper: #f3f6f8;
  --panel: #ffffff;
  --line: #dbe2e8;
  --line-strong: #c8d2dc;
  --teal: #0f766e;
  --amber: #f5a524;
  --coral: #e25a3f;
  --button: #111827;
  --shadow: 0 18px 40px rgba(23, 32, 39, 0.08);
  --radius: 8px;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--paper);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.08), transparent 260px),
    linear-gradient(90deg, rgba(23, 32, 39, 0.04) 1px, transparent 1px) 0 0 / 72px 72px,
    var(--paper);
}

body.is-auth-checking .app-shell,
body.is-login-required .app-shell,
body.is-authenticated .auth-gate {
  display: none;
}

button,
input,
textarea {
  font: inherit;
}

a {
  color: inherit;
}

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

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 26px 0 42px;
}

.auth-gate {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.auth-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 251, 0.95)),
    var(--panel);
  box-shadow: var(--shadow);
  padding: 28px;
}

.auth-card h1 {
  margin: 0 0 22px;
  font-size: 30px;
  line-height: 1.08;
  font-weight: 900;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.eyebrow,
.panel-kicker,
.download-kicker {
  margin: 0 0 7px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1;
  font-weight: 900;
}

.top-copy {
  margin: 10px 0 0;
  max-width: 560px;
  color: var(--muted);
  line-height: 1.55;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 9px;
}

.origin-pill {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  border-radius: 999px;
  padding: 9px 13px;
  color: var(--muted);
  max-width: 45vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-button {
  min-height: 38px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.02fr) minmax(340px, 0.98fr);
  gap: 16px;
  align-items: stretch;
}

.panel {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.upload-panel,
.command-panel,
.table-panel {
  padding: 22px;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-head h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.12;
}

.panel-code {
  min-width: 98px;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  background: #f8fafb;
  color: var(--teal);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-weight: 850;
  text-align: center;
  border-radius: 6px;
}

.upload-form {
  display: grid;
  gap: 14px;
}

.identity-row {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr);
  gap: 14px;
  align-items: end;
}

.icon-picker {
  display: grid;
  gap: 8px;
  cursor: pointer;
}

.icon-picker input,
.dropzone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.icon-preview {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(245, 165, 36, 0.18), transparent 48%),
    #f9fbfc;
  color: var(--teal);
  font-size: 13px;
  font-weight: 900;
  overflow: hidden;
}

.icon-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.icon-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.2);
  border-color: var(--teal);
}

.dropzone {
  display: grid;
  gap: 6px;
  place-items: center;
  min-height: 118px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: #f8fafb;
  cursor: pointer;
  transition: border-color 160ms ease, transform 160ms ease, background 160ms ease;
}

.dropzone.is-dragging {
  border-color: var(--teal);
  transform: translateY(-1px);
  background: rgba(15, 118, 110, 0.08);
}

.drop-title {
  font-weight: 850;
}

.drop-meta,
.form-status,
.muted {
  color: var(--muted);
}

.form-status {
  min-height: 22px;
  margin: 0;
  font-size: 14px;
}

.form-status[data-tone="ok"] {
  color: var(--teal);
}

.form-status[data-tone="error"] {
  color: var(--coral);
}

.primary-button,
.download-button {
  border: 0;
  border-radius: 7px;
  background: var(--button);
  color: white;
  min-height: 48px;
  padding: 0 18px;
  font-weight: 850;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  text-decoration: none;
}

.primary-button:hover,
.download-button:hover {
  background: #0a0f16;
}

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

.latest-link {
  min-height: 350px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 280px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.link-block {
  display: grid;
  grid-template-columns: minmax(190px, 0.8fr) minmax(0, 1.2fr);
  gap: 18px;
  align-items: stretch;
}

.download-preview {
  display: grid;
  align-content: center;
  justify-items: center;
  min-height: 288px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, #ffffff, #f7fafb);
  padding: 18px;
  text-align: center;
}

.preview-icon,
.row-icon,
.download-icon {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 8px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--teal), var(--amber));
  color: white;
  font-weight: 900;
}

.preview-icon img,
.row-icon,
.download-icon {
  object-fit: cover;
}

.preview-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-name {
  display: block;
  width: 100%;
  margin-top: 14px;
  font-size: 20px;
  overflow-wrap: anywhere;
}

.preview-button {
  display: grid;
  place-items: center;
  width: 100%;
  height: 42px;
  margin-top: 18px;
  border-radius: 7px;
  background: var(--button);
  color: white;
  font-weight: 850;
}

.link-copy {
  min-width: 0;
}

.qr {
  width: 132px;
  height: 132px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 8px;
}

.link-title {
  margin: 14px 0 8px;
  font-size: 18px;
  font-weight: 850;
}

.link-url {
  display: block;
  color: var(--teal);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 18px;
}

.ghost-button,
.mini-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  font-weight: 780;
}

.ghost-button:hover,
.mini-button:hover {
  border-color: var(--line-strong);
  background: #f8fafb;
}

.mini-button:disabled {
  opacity: 0.58;
  cursor: progress;
}

.danger-button {
  color: #b43b2a;
  border-color: rgba(226, 90, 63, 0.28);
}

.danger-button:hover {
  background: rgba(226, 90, 63, 0.08);
  border-color: rgba(226, 90, 63, 0.42);
}

.note-button {
  color: var(--teal);
  border-color: rgba(15, 118, 110, 0.26);
}

.note-button:hover {
  background: rgba(15, 118, 110, 0.08);
  border-color: rgba(15, 118, 110, 0.38);
}

.metrics-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--line);
}

.metrics-strip div {
  background: rgba(255, 255, 255, 0.9);
  padding: 15px 16px;
}

.metrics-strip span {
  display: block;
  font-size: 28px;
  font-weight: 900;
}

.metrics-strip small {
  color: var(--muted);
  font-weight: 760;
}

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

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

th,
td {
  padding: 14px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0;
}

td strong,
td small {
  display: block;
}

td small {
  margin-top: 4px;
  color: var(--muted);
}

code {
  color: #34404b;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
}

.table-empty {
  color: var(--muted);
  text-align: center;
  padding: 30px;
}

.app-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.row-icon {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  font-size: 14px;
}

.row-icon-fallback {
  background: linear-gradient(135deg, var(--teal), var(--amber));
  color: white;
}

.link-cell {
  display: flex;
  align-items: center;
  gap: 9px;
}

.remark-cell {
  display: grid;
  gap: 8px;
  max-width: 220px;
}

.remark-text {
  display: -webkit-box;
  max-width: 220px;
  color: #34404b;
  line-height: 1.45;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.remark-text.is-empty {
  color: var(--subtle);
}

.mini-link {
  color: var(--teal);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-weight: 850;
}

.download-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 18px;
  position: relative;
  overflow: hidden;
}

.minimal-download {
  background:
    linear-gradient(180deg, #071116, #10171d 54%, #131016),
    #071116;
  color: #f8fafc;
}

.download-stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.stage-grid {
  position: absolute;
  inset: -18%;
  background:
    linear-gradient(90deg, rgba(68, 215, 196, 0.14) 1px, transparent 1px) 0 0 / 54px 54px,
    linear-gradient(180deg, rgba(245, 165, 36, 0.10) 1px, transparent 1px) 0 0 / 54px 54px,
    linear-gradient(135deg, transparent 0 46%, rgba(226, 90, 63, 0.12) 48%, transparent 52% 100%);
  opacity: 0.48;
  transform: rotate(-6deg) scale(1.1);
  animation: grid-drift 16s linear infinite;
}

.stage-sweep {
  position: absolute;
  left: -30vw;
  width: 160vw;
  height: 130px;
  background: linear-gradient(90deg, transparent, rgba(66, 211, 194, 0.22), rgba(245, 165, 36, 0.18), transparent);
  filter: blur(18px);
  opacity: 0.72;
  transform: rotate(-18deg);
}

.stage-sweep-one {
  top: 13%;
  animation: sweep-pass 6.8s ease-in-out infinite;
}

.stage-sweep-two {
  bottom: 12%;
  animation: sweep-pass 8.6s ease-in-out infinite reverse;
}

.stage-spark {
  position: absolute;
  display: block;
  width: 148px;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(248, 250, 252, 0.92), transparent);
  opacity: 0;
  transform: rotate(-18deg);
}

.stage-spark-one {
  top: 24%;
  animation: spark-run 4.8s 0.2s ease-in-out infinite;
}

.stage-spark-two {
  top: 63%;
  animation: spark-run 5.6s 1.1s ease-in-out infinite;
}

.stage-spark-three {
  top: 78%;
  animation: spark-run 7s 2.2s ease-in-out infinite;
}

.download-shell {
  width: min(420px, 100%);
  position: relative;
  z-index: 1;
}

.download-card {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.install-card {
  display: grid;
  justify-items: center;
  gap: 18px;
  text-align: center;
}

.minimal-download .install-card {
  position: relative;
  overflow: hidden;
  padding: 32px 24px 26px;
  border-color: rgba(148, 163, 184, 0.28);
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.08) 42%, rgba(15, 118, 110, 0.16)),
    rgba(9, 17, 22, 0.82);
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(18px);
  animation: card-rise 720ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.minimal-download .install-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(110deg, transparent 0 32%, rgba(255, 255, 255, 0.18) 43%, transparent 54% 100%);
  z-index: 0;
  opacity: 0.58;
  transform: translateX(-120%);
  animation: card-sheen 5.2s ease-in-out infinite;
  pointer-events: none;
}

.minimal-download .install-card::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(68, 215, 196, 0.18);
  border-radius: 7px;
  pointer-events: none;
}

.minimal-download .install-card > * {
  position: relative;
  z-index: 1;
}

.download-icon {
  width: 86px;
  height: 86px;
  box-shadow: 0 10px 28px rgba(23, 32, 39, 0.12);
}

.minimal-download .download-icon {
  position: relative;
  z-index: 1;
  border: 1px solid rgba(255, 255, 255, 0.26);
  box-shadow:
    0 16px 34px rgba(0, 0, 0, 0.34),
    0 0 0 6px rgba(68, 215, 196, 0.08),
    0 0 46px rgba(245, 165, 36, 0.20);
  animation: icon-float 3.6s ease-in-out infinite;
}

.download-icon-fallback {
  font-size: 38px;
}

.download-card h1 {
  margin: 0;
  max-width: 100%;
  font-size: 28px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.minimal-download .download-card h1 {
  position: relative;
  z-index: 1;
  color: #f8fafc;
  text-shadow: 0 6px 22px rgba(0, 0, 0, 0.34);
}

.browser-warning {
  width: 100%;
  border: 1px solid rgba(226, 90, 63, 0.24);
  border-radius: 7px;
  background: rgba(226, 90, 63, 0.08);
  color: #a43624;
  padding: 10px 12px;
  text-align: left;
}

.download-button {
  width: 100%;
}

.kinetic-button {
  position: relative;
  z-index: 2;
  overflow: hidden;
  min-height: 54px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background:
    linear-gradient(135deg, #ffc247, #18c1b1 42%, #ff6a4d 100%);
  background-size: 180% 180%;
  box-shadow:
    0 16px 34px rgba(0, 0, 0, 0.34),
    0 0 36px rgba(19, 166, 154, 0.24);
  color: #071116;
  font-size: 17px;
  font-weight: 950;
  letter-spacing: 0;
  transform: translateZ(0);
  animation: button-breathe 2.3s ease-in-out infinite, button-flow 5.6s linear infinite;
}

.kinetic-button span {
  position: relative;
  z-index: 2;
  color: #071116;
  text-shadow: 0 1px 18px rgba(255, 255, 255, 0.36);
}

.kinetic-button::before {
  content: "";
  position: absolute;
  inset: -40% auto -40% -45%;
  width: 42%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.62), transparent);
  transform: skewX(-20deg);
  animation: button-sweep 2.7s ease-in-out infinite;
}

.kinetic-button::after {
  content: "↓";
  position: relative;
  z-index: 2;
  margin-left: 8px;
  font-size: 18px;
  color: #071116;
  text-shadow: 0 1px 18px rgba(255, 255, 255, 0.36);
  animation: arrow-drop 1.2s ease-in-out infinite;
}

.kinetic-button:hover {
  transform: translateY(-2px) scale(1.01);
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.38),
    0 0 48px rgba(245, 165, 36, 0.30);
}

.kinetic-button:active {
  transform: translateY(0) scale(0.99);
}

@keyframes grid-drift {
  from {
    background-position: 0 0, 0 0, 0 0;
  }
  to {
    background-position: 108px 54px, 54px 108px, 160px 0;
  }
}

@keyframes sweep-pass {
  0%, 100% {
    transform: translateX(-12%) rotate(-18deg);
    opacity: 0.34;
  }
  50% {
    transform: translateX(12%) rotate(-18deg);
    opacity: 0.78;
  }
}

@keyframes spark-run {
  0% {
    left: -30%;
    opacity: 0;
  }
  18% {
    opacity: 0.8;
  }
  52% {
    opacity: 0.25;
  }
  100% {
    left: 110%;
    opacity: 0;
  }
}

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

@keyframes card-sheen {
  0%, 64% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(120%);
  }
}

@keyframes icon-float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

@keyframes button-breathe {
  0%, 100% {
    box-shadow:
      0 16px 34px rgba(0, 0, 0, 0.34),
      0 0 34px rgba(19, 166, 154, 0.22);
  }
  50% {
    box-shadow:
      0 18px 42px rgba(0, 0, 0, 0.40),
      0 0 54px rgba(245, 165, 36, 0.34);
  }
}

@keyframes button-flow {
  from {
    background-position: 0% 50%;
  }
  to {
    background-position: 180% 50%;
  }
}

@keyframes button-sweep {
  0%, 48% {
    left: -48%;
  }
  100% {
    left: 118%;
  }
}

@keyframes arrow-drop {
  0%, 100% {
    transform: translateY(-1px);
    opacity: 0.85;
  }
  50% {
    transform: translateY(3px);
    opacity: 1;
  }
}

@media (max-width: 900px) {
  .workspace,
  .link-block {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 16px;
  }

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

  .top-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .origin-pill {
    max-width: 100%;
  }

  .identity-row,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .icon-picker {
    grid-template-columns: 72px minmax(0, 1fr);
    align-items: center;
  }

  .upload-panel,
  .command-panel,
  .table-panel,
  .download-card {
    padding: 16px;
  }
}

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