:root {
  color-scheme: light;
  --ink: #17191f;
  --muted: #687382;
  --paper: #fffdf8;
  --panel: rgba(255, 255, 255, 0.72);
  --line: rgba(23, 25, 31, 0.08);
  --blue: #3f8ea5;
  --cyan: #9ed9e8;
  --violet: #7d5cff;
  --violet-deep: #4320a8;
  --red: #c43e32;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #f7efe4;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "SF Pro Display", "PingFang SC", "Hiragino Sans GB", sans-serif;
  background:
    radial-gradient(circle at 4% 6%, rgba(158, 217, 232, 0.42), transparent 17rem),
    radial-gradient(circle at 92% 88%, rgba(125, 92, 255, 0.16), transparent 18rem),
    linear-gradient(135deg, #fff9f1 0%, #f2e7d5 52%, #ddeff3 100%);
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

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

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.flow {
  position: absolute;
  width: 34rem;
  height: 10rem;
  border-radius: 999px;
  filter: blur(42px);
  opacity: 0.34;
  transform: rotate(-18deg);
  animation: flowDrift 11s ease-in-out infinite alternate;
}

.flow-a {
  top: 8%;
  left: -28%;
  background: linear-gradient(90deg, transparent, rgba(125, 92, 255, 0.42), rgba(83, 218, 255, 0.36), transparent);
}

.flow-b {
  right: -34%;
  bottom: 12%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.48), rgba(125, 92, 255, 0.22), transparent);
  animation-duration: 14s;
  animation-delay: -4s;
}

.shell {
  position: relative;
  width: min(100%, 1180px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(26px, env(safe-area-inset-bottom));
}

.screen {
  min-height: calc(100dvh - 44px);
}

.is-hidden {
  display: none !important;
}

.login-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  max-width: 520px;
  margin: 0 auto;
}

.brand-lockup {
  display: grid;
  place-items: center;
  gap: 12px;
}

.brand-lockup h1,
.topbar h1 {
  margin: 0;
  line-height: 1.05;
  letter-spacing: 0;
}

.brand-lockup h1 {
  font-size: 34px;
  font-weight: 900;
}

.brand-logo {
  width: 46px;
  height: 46px;
  border-radius: 18px;
  object-fit: cover;
  box-shadow: 0 12px 26px rgba(67, 32, 168, 0.22);
  animation: logoBreath 3.4s ease-in-out infinite;
}

.brand-logo-large {
  width: 76px;
  height: 76px;
  border-radius: 22px;
}

.panel {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 18px 42px rgba(48, 39, 22, 0.08);
  backdrop-filter: blur(22px);
}

.auth-panel,
.stack,
.reference-panel,
.generate-panel,
.result-panel,
.history-panel {
  padding: 16px;
}

.auth-panel {
  display: grid;
  gap: 12px;
}

.app-screen {
  display: grid;
  align-content: start;
  gap: 14px;
}

.view-tabs {
  position: sticky;
  top: max(10px, env(safe-area-inset-top));
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(22px);
  box-shadow: 0 16px 34px rgba(48, 39, 22, 0.08);
}

.view-tab {
  min-height: 43px;
  border: 0;
  border-radius: 12px;
  color: var(--muted);
  background: transparent;
  font-weight: 900;
}

.view-tab.active {
  color: #fff;
  background: var(--ink);
  box-shadow: 0 10px 24px rgba(23, 25, 31, 0.18);
}

.view-panel {
  min-width: 0;
}

.workspace {
  display: grid;
  gap: 14px;
}

.control-column {
  display: grid;
  align-content: start;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 2px;
}

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

.topbar h1 {
  font-size: 24px;
  font-weight: 900;
}

.topbar p {
  min-height: 18px;
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 0 0 1px var(--line);
}

.icon-button svg,
.soft-action svg,
.mini-action svg,
.empty-result svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stack {
  display: grid;
  gap: 14px;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  border-radius: 15px;
  background: rgba(23, 25, 31, 0.06);
}

.mode-button,
.count-button {
  min-height: 42px;
  border: 0;
  border-radius: 11px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.mode-button.active,
.count-button.active {
  color: #fff;
  background: var(--ink);
  box-shadow: 0 10px 24px rgba(23, 25, 31, 0.18);
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: 0;
  color: var(--ink);
  background: rgba(255, 253, 248, 0.88);
}

input {
  height: 52px;
  padding: 0 14px;
}

textarea {
  min-height: 154px;
  resize: vertical;
  padding: 13px 14px;
  line-height: 1.55;
}

textarea:focus,
input:focus {
  border-color: rgba(63, 142, 165, 0.55);
  box-shadow: 0 0 0 4px rgba(158, 217, 232, 0.28);
}

.count-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.reference-head,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.soft-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 13px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: inset 0 0 0 1px var(--line);
  font-weight: 850;
}

.text-action {
  border: 0;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.reference-list {
  display: flex;
  gap: 10px;
  min-height: 0;
  margin-top: 12px;
  overflow-x: auto;
  scrollbar-width: none;
}

.reference-list::-webkit-scrollbar {
  display: none;
}

.reference-thumb {
  flex: 0 0 auto;
  width: 82px;
  height: 82px;
  border-radius: 13px;
  object-fit: cover;
  box-shadow: inset 0 0 0 1px var(--line);
}

.primary-action {
  position: relative;
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 15px;
  color: #fff;
  background: var(--ink);
  font-weight: 900;
  overflow: hidden;
  box-shadow: 0 16px 34px rgba(23, 25, 31, 0.18);
}

.primary-action::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 18%, rgba(255, 255, 255, 0.32), transparent 72%);
  transform: translateX(-120%);
}

.primary-action:not(:disabled)::after {
  animation: buttonShine 3.6s ease-in-out infinite;
}

.primary-action:disabled {
  color: rgba(255, 255, 255, 0.6);
  background: rgba(23, 25, 31, 0.42);
  box-shadow: none;
}

.pulse-ready:not(:disabled) {
  animation: buttonPulse 2.35s ease-in-out infinite;
}

.progress-track {
  height: 8px;
  border-radius: 99px;
  background: rgba(23, 25, 31, 0.08);
  overflow: hidden;
}

.progress-fill {
  position: relative;
  display: block;
  width: 8%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--violet), var(--blue), var(--cyan));
  transition: width 280ms ease;
  overflow: hidden;
}

.progress-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 50%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.78), transparent);
  animation: progressSweep 1.35s linear infinite;
}

.section-title h2 {
  margin: 0;
  font-size: 17px;
}

#resultState {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.result-grid {
  display: grid;
  gap: 12px;
}

.history-grid {
  display: grid;
  gap: 12px;
}

.empty-result {
  display: grid;
  place-items: center;
  height: 182px;
  border-radius: 16px;
  color: rgba(104, 115, 130, 0.68);
  background: rgba(255, 253, 248, 0.64);
}

.empty-result svg {
  width: 34px;
  height: 34px;
}

.compact-empty {
  height: 142px;
}

.result-card {
  display: grid;
  gap: 9px;
  padding: 10px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 0 0 1px var(--line);
}

.result-card img {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border-radius: 13px;
  object-fit: cover;
  background: rgba(255, 253, 248, 0.72);
}

.history-card {
  display: grid;
  gap: 11px;
  padding: 12px;
  border-radius: 17px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 0 0 1px var(--line);
}

.history-card-main {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.history-cover {
  width: 92px;
  aspect-ratio: 1;
  border-radius: 14px;
  object-fit: cover;
  background: rgba(255, 253, 248, 0.74);
  box-shadow: inset 0 0 0 1px var(--line);
}

.history-meta {
  min-width: 0;
}

.history-meta strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.result-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.result-actions span,
.history-actions span {
  font-size: 13px;
  font-weight: 850;
}

.result-actions a,
.mini-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 11px;
  color: var(--blue);
  background: rgba(63, 142, 165, 0.1);
  font-size: 13px;
  font-weight: 850;
  text-decoration: none;
}

.result-action-group,
.history-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 20;
  width: min(calc(100% - 32px), 460px);
  padding: 12px 14px;
  border-radius: 14px;
  color: #fff;
  background: rgba(23, 25, 31, 0.9);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
  transform: translate(-50%, 140%);
  transition: transform 240ms ease;
}

.toast.show {
  transform: translate(-50%, 0);
}

.image-dialog {
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #050507;
}

.image-dialog::backdrop {
  background: #050507;
}

.image-dialog img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: max(16px, env(safe-area-inset-top)) 10px max(16px, env(safe-area-inset-bottom));
}

.preview-close {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  z-index: 2;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
}

@keyframes logoBreath {
  0%,
  100% {
    filter: drop-shadow(0 0 0 rgba(125, 92, 255, 0.2));
    transform: scale(1);
  }
  50% {
    filter: drop-shadow(0 0 18px rgba(125, 92, 255, 0.38));
    transform: scale(1.026);
  }
}

@keyframes flowDrift {
  from {
    transform: translate3d(-8%, -6%, 0) rotate(-21deg);
  }
  to {
    transform: translate3d(18%, 22%, 0) rotate(8deg);
  }
}

@keyframes buttonPulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 16px 34px rgba(23, 25, 31, 0.18);
  }
  50% {
    transform: scale(1.012);
    box-shadow: 0 18px 42px rgba(67, 32, 168, 0.24);
  }
}

@keyframes buttonShine {
  0%,
  48% {
    transform: translateX(-120%);
  }
  78%,
  100% {
    transform: translateX(120%);
  }
}

@keyframes progressSweep {
  from {
    transform: translateX(-120%);
  }
  to {
    transform: translateX(220%);
  }
}

@media (min-width: 680px) {
  .shell {
    padding-inline: 24px;
  }

  .auth-panel,
  .stack,
  .reference-panel,
  .generate-panel,
  .result-panel,
  .history-panel {
    padding: 18px;
  }

  .workspace {
    grid-template-columns: minmax(300px, 0.82fr) minmax(340px, 1.18fr);
    align-items: start;
  }

  .result-panel {
    position: sticky;
    top: 86px;
  }

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

@media (min-width: 1024px) {
  .shell {
    padding-inline: 32px;
  }

  .workspace {
    grid-template-columns: minmax(340px, 420px) minmax(0, 1fr);
  }

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

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

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