:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --card: #ffffff;
  --ink: #172033;
  --muted: #69758a;
  --line: #dfe6f0;
  --blue: #2563eb;
  --blue-dark: #1746bd;
  --green: #0f8f6d;
  --red: #c2410c;
  --shadow: 0 24px 70px rgba(35, 47, 76, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  font-family: "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.12), transparent 32%),
    linear-gradient(315deg, rgba(15, 143, 109, 0.12), transparent 28%),
    var(--bg);
  overflow-x: hidden;
}

button,
textarea {
  font: inherit;
}

.app-shell {
  height: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 10px 12px 12px;
}

.tool-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  max-width: none;
  margin: 0 auto;
  border: 1px solid rgba(219, 227, 238, 0.95);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  padding: 16px 18px 18px;
}

/* 尚未解析时不要让卡片在视口里悬空留出大块空白 */
.tool-card:not(:has(.result-area:not([hidden]))) {
  flex: 0 1 auto;
}

.layout-top {
  flex-shrink: 0;
}

.header,
.action-row,
.download-row {
  display: flex;
  gap: 12px;
}

.header {
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(20px, 2.6vw, 26px);
}

.header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.input-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  padding: 12px;
}

textarea {
  width: 100%;
  min-height: 100px;
  max-height: min(28vh, 220px);
  resize: vertical;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  line-height: 1.65;
}

.action-row {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  padding: 0 16px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary-button {
  background: var(--blue);
  color: #fff;
}

.primary-button:hover:not(:disabled) {
  background: var(--blue-dark);
}

.secondary-button,
.ghost-button {
  border-color: var(--line);
  background: #fff;
  color: #27364c;
}

.secondary-button:hover,
.ghost-button:hover {
  border-color: #b9c7da;
  background: #f8fbff;
}

.status-line {
  min-height: 22px;
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 13px;
}

.status-line.success {
  color: var(--green);
}

.status-line.error {
  color: var(--red);
}

/* 解析结果：占满卡片剩余高度，左侧大面积预览 */
.result-area {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 340px);
  gap: 14px;
  align-items: stretch;
  min-height: 0;
  margin-top: 14px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.preview-column {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.preview-box {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: min(52vh, 560px);
  width: 100%;
  overflow: hidden;
  border-radius: 10px;
  background: #0b1020;
}

.preview-expand {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.72);
  color: #f8fafc;
  font-size: 13px;
  cursor: pointer;
}

.preview-expand:hover {
  background: rgba(30, 41, 59, 0.92);
}

.preview-expand:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.preview-box video,
.preview-box img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.empty-preview {
  color: #a8b1c2;
  padding: 24px;
  text-align: center;
}

.result-sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.result-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfdff;
  padding: 14px 16px;
  overflow: auto;
}

.platform-pill {
  display: inline-block;
  margin-bottom: 10px;
  border-radius: 999px;
  background: #ecfdf5;
  color: #047857;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
}

.result-info h2 {
  font-size: clamp(17px, 2vw, 20px);
  line-height: 1.45;
  word-break: break-word;
}

.download-row {
  flex-wrap: wrap;
}

.download-row button {
  flex: 1 1 120px;
}

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 12px;
}

.preview-modal[hidden] {
  display: none !important;
}

.preview-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
  cursor: pointer;
}

.preview-modal-panel {
  position: relative;
  z-index: 1;
  width: min(calc(100vw - 24px), 1280px);
  max-height: min(calc(100vh - 24px), 920px);
  border-radius: 12px;
  background: #0b1020;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.preview-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 4;
  width: 42px;
  height: 42px;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.85);
  color: #f8fafc;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.preview-modal-close:hover {
  background: rgba(51, 65, 85, 0.95);
}

.preview-modal-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.preview-modal-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 52px 16px 20px;
  min-height: 0;
}

.preview-modal-body video,
.preview-modal-body img {
  max-width: 100%;
  max-height: min(calc(100vh - 100px), 880px);
  width: auto;
  height: auto;
  object-fit: contain;
}

@media (max-width: 900px) {
  .result-area {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(280px, 1fr) auto;
  }

  .preview-box {
    min-height: min(48vh, 420px);
  }

  .result-info {
    flex: 0 1 auto;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 8px;
  }

  .tool-card {
    padding: 14px;
  }

  .header,
  .action-row {
    flex-direction: column;
  }

  button {
    width: 100%;
  }

  .preview-expand {
    top: 8px;
    right: 8px;
    width: auto;
    font-size: 12px;
    padding: 0 10px;
  }

  textarea {
    max-height: min(35vh, 200px);
  }
}
