:root {
  color-scheme: light;
  --ink: #141821;
  --muted: #667085;
  --line: #d9dee8;
  --panel: #ffffff;
  --blue: #245bff;
  --blue-dark: #173ac7;
  --blue-soft: #eef3ff;
  --red: #b42318;
  --green: #087443;
  --admin-bg: #eef1f6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
}

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

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

input[type="file"] {
  display: none;
}

.editor-panel input[type="file"] {
  display: block;
}

.hidden {
  display: none !important;
}

/* Mobile user app */

.mobile-body {
  height: 100dvh;
  overflow: hidden;
  background: #090b10;
  overscroll-behavior: none;
}

.hk-app {
  position: relative;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background:
    radial-gradient(circle at 50% 0%, rgba(97, 117, 255, 0.28), transparent 34%),
    linear-gradient(180deg, #11141d 0%, #080a0f 100%);
  color: #fff;
}

.hk-topbar {
  height: calc(54px + env(safe-area-inset-top));
  padding: calc(10px + env(safe-area-inset-top)) 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 auto;
}

.hk-brand-lockup {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.hk-logo {
  font-size: 22px;
  font-weight: 950;
  line-height: 1;
  letter-spacing: 0;
}

.hk-version {
  color: rgba(255, 255, 255, 0.48);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.hk-admin-link {
  min-height: 34px;
  padding: 8px 11px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: rgba(255, 255, 255, 0.82);
  display: flex;
  align-items: center;
  text-decoration: none;
  font-size: 12px;
  font-weight: 850;
}

.hk-workspace {
  position: relative;
  min-height: 0;
  padding: 8px 14px 10px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
}

.hk-canvas-toolbar {
  position: absolute;
  z-index: 4;
  top: 20px;
  left: 26px;
  right: 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.hk-canvas-toolbar span {
  max-width: 48%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(14px);
  color: rgba(255, 255, 255, 0.88);
  font-size: 11px;
  font-weight: 850;
  padding: 7px 10px;
}

.hk-canvas-frame {
  position: relative;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255,255,255,0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.045) 1px, transparent 1px),
    #0c0f16;
  background-size: 34px 34px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.025),
    0 18px 50px rgba(0, 0, 0, 0.34);
  display: flex;
  align-items: center;
  justify-content: center;
}

.hk-canvas-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.08), transparent 17%, transparent 76%, rgba(0,0,0,0.22)),
    radial-gradient(circle at 50% 20%, rgba(91, 120, 255, 0.2), transparent 36%);
}

.hk-empty {
  z-index: 2;
  width: min(78%, 310px);
  min-height: 160px;
  border: 1px solid rgba(255,255,255,0.11);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.055), rgba(255,255,255,0.025));
  color: rgba(255,255,255,0.68);
  padding: 24px 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  text-align: center;
  pointer-events: none;
}

.hk-empty strong {
  color: #fff;
  font-size: 17px;
  line-height: 1.2;
}

.hk-empty span {
  font-size: 13px;
  line-height: 1.45;
}

.hk-canvas-img {
  z-index: 2;
  position: absolute;
  inset: 50% auto auto 50%;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  transform: translate(-50%, -50%);
  transform-origin: center;
  transition: filter 320ms ease, opacity 320ms ease, transform 420ms ease;
  will-change: opacity, transform, clip-path, filter;
}

.hk-source-out {
  animation: sourceYield 1100ms ease both;
}

.hk-result-in {
  animation: resultReveal 1100ms cubic-bezier(.19, 1, .22, 1) both;
}

.hk-canvas-frame.hk-revealing::before {
  content: "";
  position: absolute;
  z-index: 4;
  top: 0;
  bottom: 0;
  left: -18%;
  width: 18%;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent, rgba(255,255,255,0.88), rgba(127, 161, 255, 0.55), transparent);
  filter: blur(.5px);
  opacity: .9;
  animation: revealSweep 1100ms cubic-bezier(.19, 1, .22, 1) both;
  mix-blend-mode: screen;
}

@keyframes resultReveal {
  0% {
    clip-path: inset(0 100% 0 0);
    filter: saturate(.72) brightness(.82) blur(8px);
    opacity: .35;
  }
  58% {
    filter: saturate(1.08) brightness(1.08) blur(1px);
    opacity: 1;
  }
  100% {
    clip-path: inset(0 0 0 0);
    filter: none;
    opacity: 1;
  }
}

@keyframes sourceYield {
  0% {
    opacity: 1;
    filter: none;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: .24;
    filter: saturate(.5) brightness(.7) blur(2px);
    transform: translate(-50%, -50%) scale(.985);
  }
}

@keyframes revealSweep {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(760%);
  }
}

.hk-progress {
  z-index: 5;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  background: rgba(15, 18, 27, 0.86);
  backdrop-filter: blur(18px);
  padding: 11px 12px;
}

.hk-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.hk-progress-row strong {
  color: #fff;
  font-size: 13px;
}

.hk-progress-row span {
  color: #9db0ff;
  font-size: 13px;
  font-weight: 950;
}

.hk-progress-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,0.13);
  margin-top: 9px;
}

.hk-progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #6b8cff, #b56cff);
  transition: width 420ms ease;
}

.hk-progress p {
  margin: 7px 0 0;
  color: rgba(255,255,255,0.58);
  font-size: 11px;
  line-height: 1.4;
}

.hk-dock {
  flex: 0 0 auto;
  min-height: 318px;
  max-height: 42dvh;
  padding: 9px 12px max(12px, env(safe-area-inset-bottom));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background:
    linear-gradient(180deg, rgba(32, 37, 52, 0.98), rgba(16, 19, 28, 0.99));
  color: #fff;
  box-shadow: 0 -18px 44px rgba(0, 0, 0, 0.28);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.hk-dock-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  margin: 0 auto 1px;
}

.hk-status-line {
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.64);
  padding: 7px 10px;
  font-size: 12px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hk-status-line.error {
  border-color: rgba(255, 112, 112, 0.38);
  background: rgba(255, 87, 87, 0.12);
  color: #ffb4b4;
}

.hk-tool-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hk-tool-head strong,
.hk-upload-copy strong {
  display: block;
  font-size: 14px;
  line-height: 1.2;
}

.hk-tool-head span,
.hk-upload-copy span {
  display: block;
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.48);
  font-size: 11px;
  line-height: 1.3;
}

.hk-template-strip {
  display: flex;
  gap: 9px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 1px 1px 5px;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.hk-template-strip::-webkit-scrollbar {
  display: none;
}

.hk-template {
  scroll-snap-align: start;
  flex: 0 0 104px;
  min-height: 116px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  padding: 6px;
  text-align: left;
}

.hk-template.active {
  border-color: rgba(157, 176, 255, 0.95);
  background: rgba(107, 140, 255, 0.16);
  box-shadow: 0 0 0 2px rgba(107, 140, 255, 0.18);
}

.hk-template img {
  width: 100%;
  height: 66px;
  display: block;
  object-fit: cover;
  border-radius: 6px;
  background: #e7eaf0;
}

.hk-template strong {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.2;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.hk-template span {
  display: none;
}

.hk-upload-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  padding: 10px;
}

.hk-upload-copy {
  min-width: 0;
}

.hk-upload-copy span {
  max-width: 230px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hk-upload-button {
  flex: 0 0 72px;
  min-height: 38px;
  border-radius: 8px;
  background: #fff;
  color: #111827;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 950;
}

.hk-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  margin-top: auto;
}

.hk-result-actions {
  grid-template-columns: 1fr 1fr;
}

.hk-primary,
.hk-secondary {
  min-height: 50px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 15px;
  font-weight: 950;
}

.hk-primary {
  border: 1px solid #fff;
  background: #fff;
  color: #111827;
}

.hk-primary:disabled {
  opacity: 0.62;
}

.hk-secondary {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
}

@media (max-height: 720px) {
  .hk-dock {
    min-height: 292px;
  }

  .hk-template {
    min-height: 102px;
  }

  .hk-template img {
    height: 54px;
  }

  .hk-progress p {
    display: none;
  }
}

/* Admin app */

.admin-body {
  background: var(--admin-bg);
}

.admin-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.admin-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  background: #111827;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.admin-brand span {
  display: block;
  color: #9db4ff;
  font-size: 13px;
  font-weight: 800;
}

.admin-brand strong {
  display: block;
  margin-top: 5px;
  font-size: 20px;
  line-height: 1.2;
}

.template-nav {
  display: grid;
  gap: 8px;
}

.template-nav button {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: #d8deea;
  padding: 10px;
  text-align: left;
}

.template-nav button.active {
  border-color: #7aa2ff;
  background: rgba(36, 91, 255, 0.28);
  color: #fff;
}

.template-nav span {
  display: block;
  color: #9ca3af;
  font-size: 12px;
  margin-top: 3px;
}

.sidebar-link {
  margin-top: auto;
  color: #fff;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}

.admin-main {
  padding: 28px;
}

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

.admin-topbar h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.18;
}

.admin-topbar p {
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.admin-login,
.admin-editor,
.dashboard article,
.editor-panel,
.preview-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.admin-login {
  max-width: 520px;
  padding: 20px;
  display: grid;
  gap: 14px;
}

.admin-login h2 {
  margin: 0;
}

.admin-login p {
  margin: 0;
  color: var(--muted);
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
}

textarea {
  min-height: 122px;
  line-height: 1.45;
  resize: vertical;
}

.admin-primary,
.admin-secondary {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
}

.admin-primary {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #fff;
}

.admin-secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.admin-status {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--green);
}

.admin-status.error {
  color: var(--red);
  border-color: #ffd0d0;
  background: #fff3f3;
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.dashboard article {
  padding: 14px;
}

.dashboard span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.dashboard strong {
  display: block;
  margin-top: 5px;
  font-size: 22px;
}

.admin-editor {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0;
  overflow: hidden;
}

.preview-panel {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  padding: 18px;
}

.preview-panel img {
  width: 100%;
  aspect-ratio: 9 / 16;
  display: block;
  object-fit: cover;
  border-radius: 8px;
  background: #e7eaf0;
}

.preview-panel h2 {
  margin: 14px 0 0;
}

.preview-panel p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.editor-panel {
  border: 0;
  border-radius: 0;
  padding: 18px;
}

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

.editor-grid .span-2 {
  grid-column: span 2;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

@media (max-width: 820px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .admin-sidebar {
    position: static;
    height: auto;
  }

  .admin-main {
    padding: 16px;
  }

  .dashboard,
  .admin-editor,
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .editor-grid .span-2 {
    grid-column: span 1;
  }
}
