:root {
  --bg: #fafafa;
  --bg-alt: #f4f4f5;
  --bg-elevated: #ffffff;
  --bg-hover: #f4f4f5;
  --border: #e4e4e7;
  --text: #18181b;
  --text-dim: #71717a;
  --text-muted: #a1a1aa;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-ring: rgba(59, 130, 246, 0.25);
  --preview-bg: #f4f4f5;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --radius: 6px;
}

.dark {
  --bg: #18181b;
  --bg-alt: #27272a;
  --bg-elevated: #27272a;
  --bg-hover: #3f3f46;
  --border: #3f3f46;
  --text: #fafafa;
  --text-dim: #a1a1aa;
  --text-muted: #71717a;
  --preview-bg: #18181b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

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

html {
  height: 100%;
}

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, color 0.3s ease;
}

[x-cloak] {
  display: none !important;
}

#header {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.header-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#logo {
  font-family: system-ui, sans-serif;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 20px;
  color: var(--text);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

#dark-toggle {
  cursor: pointer;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 2px;
  transition: background-color 0.2s ease, border-color 0.2s ease;
  flex-shrink: 0;
}

.toggle-circle {
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.25s ease, background-color 0.2s ease;
}

.dark .toggle-circle {
  transform: translateX(18px);
}

#toggle-message {
  position: fixed;
  top: 48px;
  right: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-dim);
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

#toggle-message.visible {
  opacity: 1;
  transform: scale(1);
}

#main {
  flex: 1;
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px;
  width: 100%;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.form-group {
  margin-bottom: 12px;
}

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.form-label-with-tooltip {
  display: flex;
  align-items: center;
  gap: 4px;
}

.form-input,
.form-select {
  width: 100%;
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.3s ease;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23999'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  cursor: pointer;
}

.form-input::placeholder {
  color: var(--text-muted);
}

textarea.form-input {
  resize: vertical;
  min-height: 80px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

@media (min-width: 480px) {
  .form-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.color-input {
  height: 34px;
  padding: 2px 4px;
  cursor: pointer;
}

.color-input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.input-row .color-input {
  flex: 1;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  width: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  cursor: pointer;
  color: var(--text-dim);
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  flex-shrink: 0;
}

.btn-icon:hover {
  background: var(--bg-hover);
}

.btn-icon:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.btn-icon.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tooltip-trigger {
  position: relative;
  display: inline-flex;
}

.tooltip-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  width: 14px;
  height: 14px;
}

.tooltip-btn:hover {
  color: var(--text-dim);
}

.tooltip-body {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 240px;
  background: var(--text);
  color: var(--bg);
  font-size: 11px;
  padding: 8px 10px;
  border-radius: 4px;
  line-height: 1.5;
  z-index: 30;
  pointer-events: none;
}

.preview {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.preview-box {
  background: var(--preview-bg);
  border-radius: var(--radius);
  padding: 12px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80px;
}

.preview-box svg {
  max-width: 160px;
  height: auto;
}

.button-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: center;
}

@media (min-width: 480px) {
  .button-row {
    flex-direction: row;
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: background-color 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

@media (max-width: 479px) {
  .btn {
    width: 100%;
  }
}

.btn:hover {
  background: var(--accent-hover);
}

.btn:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}