:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #999999);
  --link: var(--tg-theme-link-color, #2678b6);
  --btn: var(--tg-theme-button-color, #3390ec);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
  --section-bg: var(--tg-theme-section-bg-color, var(--secondary-bg));
  --section-header: var(--tg-theme-section-header-text-color, var(--hint));
  --subtitle: var(--tg-theme-subtitle-text-color, var(--hint));
  --destructive: var(--tg-theme-destructive-text-color, #e53935);

  --radius: 12px;
  --input-bg: var(--secondary-bg);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 0 16px 100px;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  font-size: 13px;
  color: var(--hint);
}
.header span {
  color: var(--text);
  font-weight: 600;
}

.app-title {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  padding: 8px 0 16px;
}

/* Section */
.section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--section-header);
  letter-spacing: 0.5px;
  margin: 20px 0 8px;
}

/* Card */
.card {
  background: var(--section-bg);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  min-height: 44px;
}

.card-row + .card-row {
  border-top: 0.5px solid var(--hint);
  border-top-color: rgba(128, 128, 128, 0.15);
}

.card-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
}

.card-row .subtitle {
  font-size: 13px;
  color: var(--subtitle);
}

/* Help icon */
.help-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--hint);
  color: var(--bg);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.5;
  flex-shrink: 0;
}

/* Select */
.select-wrapper {
  position: relative;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  padding: 0 20px 0 0;
  cursor: pointer;
  text-align: right;
  min-width: 120px;
}

.select-wrapper::after {
  content: '▼';
  font-size: 8px;
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  color: var(--hint);
  pointer-events: none;
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(128, 128, 128, 0.3);
  border-radius: 31px;
  cursor: pointer;
  transition: background 0.3s;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  width: 27px;
  height: 27px;
  left: 2px;
  top: 2px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle input:checked + .toggle-slider {
  background: var(--btn);
}

.toggle input:checked + .toggle-slider::after {
  transform: translateX(20px);
}

/* Text inputs */
.input-group {
  margin: 12px 0;
}

.input-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.input-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--section-header);
}

.input-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 13px;
}

.clear-btn {
  color: var(--destructive);
  cursor: pointer;
  background: none;
  border: none;
  font-size: 13px;
}

.char-count {
  color: var(--hint);
}

textarea, input[type="text"] {
  width: 100%;
  background: var(--input-bg);
  border: none;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 15px;
  color: var(--text);
  resize: vertical;
  font-family: inherit;
  line-height: 1.4;
}

textarea::placeholder, input::placeholder {
  color: var(--hint);
}

textarea:focus, input:focus {
  outline: none;
}

.textarea-small {
  min-height: 80px;
}

.textarea-large {
  min-height: 120px;
}

/* Slider */
.slider-row {
  padding: 12px 16px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.slider-value {
  color: var(--link);
  font-weight: 600;
}

input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  height: 4px;
  background: rgba(128, 128, 128, 0.3);
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--btn);
  cursor: pointer;
}

/* Submit button */
.submit-btn {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
}

.submit-btn button {
  width: 100%;
  padding: 14px;
  background: var(--btn);
  color: var(--btn-text);
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.submit-btn button:active {
  opacity: 0.8;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  z-index: 100;
  animation: fadeIn 0.2s;
}

.modal {
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-height: 80vh;
  padding: 20px 16px 40px;
  animation: slideUp 0.3s;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--secondary-bg);
  border: none;
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-item {
  padding: 12px 0;
  border-bottom: 0.5px solid rgba(128, 128, 128, 0.15);
}

.modal-item:last-child {
  border-bottom: none;
}

.modal-item-title {
  color: var(--link);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}

.modal-item-desc {
  font-size: 13px;
  color: var(--subtitle);
  margin-top: 4px;
}

.modal-item-warn {
  font-size: 12px;
  color: #ff9800;
  margin-top: 4px;
}

.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
