:root {
  --primary: #3498db;
  --primary-dark: #2980b9;
  --primary-light: #e3f2fd;
  --gray: #95a5a6;
  --dark: #2c3e50;
  --text-light: #666;
  --light-bg: #f8f9fa;
  --border-radius: 8px;
  --shadow: 0 4px 12px rgba(0,0,0,0.1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(135deg, #f0f7ff, #e3f2fd);
  color: var(--dark);
  line-height: 1.6;
  padding: 20px;
  min-height: 100vh;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 24px;
}

header h1 {
  font-size: 2.2rem;
  color: var(--primary);
  margin-bottom: 8px;
}

header p {
  color: var(--gray);
  font-size: 1rem;
}

/* 双栏布局 */
.main-layout {
  display: flex;
  gap: 24px;
  margin-bottom: 24px;
}

.panel {
  flex: 1;
  background: white;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

/* ===== 优化 1：Panel 标题带背景色 ===== */
.panel h2 {
  font-size: 1.3rem;
  color: white;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--primary);
  padding: 12px 20px;
  border-radius: var(--border-radius) var(--border-radius) 0 0;
  margin: -24px -24px 20px -24px; /* 向外扩展抵消 padding */
}

.upload-area {
  background: white;
  border-radius: var(--border-radius);
  padding: 20px;
  text-align: center;
  margin-bottom: 20px;
  border: 2px dashed #cbd5e0;
  transition: all 0.3s;
}

.upload-area.drag-over {
  background: #e3f2fd;
  border-color: var(--primary);
  transform: scale(1.02);
}

.upload-inner {
  max-width: 400px;
  margin: 0 auto;
}

.upload-btn {
  display: inline-block;
  background: var(--primary);
  color: white;
  padding: 10px 24px;
  font-size: 1.05rem;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  font-weight: 600;
}

.upload-btn:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(52, 152, 219, 0.3);
}

.upload-btn input {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.hint {
  margin-top: 10px;
  font-size: 0.9rem;
  color: var(--gray);
}

/* ===== 优化 2：解码区自适应高度 ===== */
.decode-panel {
  display: flex;
  flex-direction: column;
}

.result-area {
  display: flex;
  flex-direction: column;
  flex: 1;
  margin-top: 16px;
}

.result-label {
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--dark);
}

.result-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #f8f9fa;
  border-radius: var(--border-radius);
  padding: 16px;
}

#resultText {
  flex: 1;
  min-height: 0; /* 🔑 关键：允许 flex 收缩 */
  width: 100%;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-family: monospace;
  resize: vertical;
  background: white;
  margin-bottom: 12px;
  font-size: 1rem;
  line-height: 1.4;
}

.result-content .btn-group {
  margin-top: auto; /* 按钮组压底 */
  margin-bottom: 0;
}

/* 编码区 */
.input-area {
  margin-bottom: 20px;
}

.input-area label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}

#inputText {
  width: 100%;
  min-height: 80px;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 1rem;
  resize: vertical;
}

.options {
  margin-bottom: 24px;
  padding: 16px;
  background: #f8f9fa;
  border-radius: var(--border-radius);
}

.option-group {
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.option-group label {
  width: 90px;
  font-weight: 600;
}

.radio-group {
  display: flex;
  gap: 16px;
  flex-wrap: nowrap;
  white-space: nowrap;
  overflow-x: auto;
  padding: 4px 0;
}

.radio-group label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-size: 0.95rem;
  white-space: nowrap;
}

#sizeSlider {
  width: 150px;
  margin: 0 12px;
}

#sizeValue {
  min-width: 80px;
  text-align: center;
  font-weight: bold;
  color: var(--primary);
}

.preview-area {
  margin-top: 16px;
}

.preview-label {
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--dark);
}

.preview-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#previewCanvas {
  background: white;
  border: 1px solid #eee;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  max-width: 100%;
  height: auto;
}

/* ===== 优化 3：按钮文字严格居中 ===== */
.btn-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center; /* 水平居中 */
  gap: 6px;
  font-size: 0.95rem;
  min-width: 130px;
  line-height: 1; /* 防 emoji 引起基线偏移 */
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn.primary {
  background: var(--primary);
  color: white;
}

.btn.primary:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.btn.secondary {
  background: white;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.btn.secondary:hover:not(:disabled) {
  background: var(--primary-light);
}

.btn.outline {
  background: transparent;
  border: 1px solid var(--gray);
  color: var(--gray);
}

.btn.outline:hover:not(:disabled) {
  background: #f1f3f5;
}

.instructions {
  background: white;
  border-radius: var(--border-radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.instructions h3 {
  color: var(--primary);
  margin-bottom: 12px;
}

.instructions ul {
  padding-left: 20px;
}

.instructions li {
  margin-bottom: 8px;
}

footer {
  text-align: center;
  margin-top: 20px;
  color: var(--text-light);
  font-size: 0.9rem;
}

footer a,
footer a:visited,
footer a:hover,
footer a:active {
  color: var(--text-light);
  text-decoration: none;
}

/* 响应式 */
@media (max-width: 768px) {
  .main-layout {
    flex-direction: column;
  }

  .btn {
    min-width: 110px;
    padding: 8px 16px;
    font-size: 0.9rem;
  }

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

  .radio-group {
    flex-direction: column;
    gap: 10px;
  }

  #previewCanvas {
    width: 100%;
    max-width: 300px;
  }

  /* 移动端解码区适配 */
  .decode-panel,
  .result-area,
  .result-content {
    flex: none; /* 移动端不强制撑满，避免干扰 */
  }

  #resultText {
    min-height: 100px;
  }
}