:root {
  color-scheme: dark;
  --bg-page: #070e1d;
  --bg-surface: #0e1a33;
  --bg-elevated: #142342;
  --bg-input: #0a1428;
  --border: rgba(225, 181, 121, 0.18);
  --border-strong: rgba(225, 181, 121, 0.38);
  --accent: #e1b579;
  --accent-strong: #ecc68f;
  --accent-ink: #0a1326;
  --text-primary: #e8edf5;
  --text-secondary: #9aa7bd;
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.12);
  --success: #4ade80;
  --success-bg: rgba(74, 222, 128, 0.14);
  --radius-lg: 16px;
  --radius-md: 11px;
  --radius-sm: 8px;
  --font-ui: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at 18% 12%, #112142 0%, var(--bg-page) 58%);
  color: var(--text-primary);
  font-family: var(--font-ui);
  line-height: 1.5;
  accent-color: var(--accent);
  -webkit-font-smoothing: antialiased;
}

.app-header {
  max-width: 1240px;
  margin-inline: auto;
  padding: 18px 24px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-dot {
  inline-size: 12px;
  block-size: 12px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(225, 181, 121, 0.16);
  flex: none;
}

.brand-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.brand-subtitle {
  margin: 2px 0 0;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(14, 26, 51, 0.75);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.workspace {
  max-width: 1240px;
  margin-inline: auto;
  padding: 10px 24px 28px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

@media (min-width: 960px) {
  .workspace {
    grid-template-columns: minmax(360px, 460px) minmax(0, 1fr);
    gap: 32px;
  }
}

.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: 0 18px 40px rgba(3, 8, 18, 0.42);
}

.field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.field-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent-strong);
}

.ghost-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 11px;
  min-inline-size: 44px;
  min-block-size: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.ghost-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.04);
}

.ghost-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.post-textarea {
  width: 100%;
  min-height: 190px;
  max-height: 360px;
  resize: vertical;
  padding: 13px 14px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.11);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.5;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.post-textarea::placeholder {
  color: rgba(154, 167, 189, 0.6);
}

.post-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(225, 181, 121, 0.16);
}

.stats-row {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.text-stats {
  margin: 0;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.overflow-warning {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: var(--danger-bg);
  color: #fecaca;
  font-size: 0.8rem;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.overflow-warning[hidden] {
  display: none;
}

.overflow-warning .icon {
  inline-size: 18px;
  block-size: 18px;
  color: var(--danger);
  flex: none;
  margin-top: 1px;
}

.controls-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.control-row--toggle {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  inline-size: 18px;
  block-size: 18px;
  margin: 0;
  cursor: pointer;
}

.value-badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(225, 181, 121, 0.14);
  border: 1px solid rgba(225, 181, 121, 0.28);
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.control-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.control-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.control-value {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  margin: 0;
  cursor: pointer;
}

/* Fallback for browsers without accent-color support */
@supports not (accent-color: #e1b579) {
  .checkbox-label {
    position: relative;
    padding-left: 26px;
  }

  .checkbox-label input[type="checkbox"].visually-hidden-fallback {
    position: absolute;
    clip-path: inset(50%);
    overflow: hidden;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
  }

  .checkbox-label input[type="checkbox"] + span::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 2px solid var(--border-strong);
    background: var(--bg-input);
  }

  .checkbox-label input[type="checkbox"]:checked + span::before {
    background: var(--accent);
    border-color: var(--accent);
  }

  .checkbox-label input[type="checkbox"]:checked + span::after {
    content: "✓";
    position: absolute;
    left: 3px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--accent-ink);
    font-size: 0.8rem;
    font-weight: 700;
  }

  input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
  }

  input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 999px;
    background: linear-gradient(to right, var(--accent) var(--progress, 50%), #1e2f52 var(--progress, 50%));
  }

  input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    margin-top: -5px;
  }
}

.align-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.segmented-fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.segmented-fieldset legend {
  padding: 0;
  margin-bottom: 7px;
}

.segmented-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 3px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid rgba(255, 255, 255, 0.08);
  gap: 3px;
}

.segmented-option {
  position: relative;
  display: flex;
  cursor: pointer;
}

.segmented-option input {
  position: absolute;
  opacity: 0;
  inline-size: 1px;
  block-size: 1px;
}

.segmented-option > span {
  width: 100%;
  text-align: center;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.segmented-option input:checked + span {
  background: var(--bg-elevated);
  color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px rgba(225, 181, 121, 0.28);
}

.segmented-option input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.format-group {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.format-option > span {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 4px;
  font-size: 0.74rem;
}

.ratio-icon {
  display: block;
  padding: 0;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  opacity: 0.85;
  flex: none;
}

.ratio-16-9 {
  inline-size: 20px;
  block-size: 11px;
}

.ratio-9-16 {
  inline-size: 11px;
  block-size: 20px;
}

.ratio-5-4 {
  inline-size: 18px;
  block-size: 14px;
}

.ratio-4-5 {
  inline-size: 14px;
  block-size: 18px;
}

.ratio-1-1 {
  inline-size: 15px;
  block-size: 15px;
}

.actions-bar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-inline-size: 44px;
  min-block-size: 46px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.12s ease, background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.btn .icon {
  inline-size: 18px;
  block-size: 18px;
  flex: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 8px 22px rgba(225, 181, 121, 0.22);
}

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

.copy-wrap {
  position: relative;
  display: flex;
}

.copy-wrap .btn-secondary {
  width: 100%;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.copy-wrap .btn-secondary:hover {
  background: #1a2d52;
  border-color: var(--accent);
}

/* Copy icon state switching (not color alone) */
.btn-secondary .icon-check,
.btn-secondary .icon-error {
  display: none;
}

.btn-secondary[data-copied] {
  border-color: rgba(74, 222, 128, 0.55);
  background: var(--success-bg);
  color: #bbf7d0;
}

.btn-secondary[data-copied] .icon-copy {
  display: none;
}

.btn-secondary[data-copied] .icon-check {
  display: block;
  color: var(--success);
}

.btn-secondary[data-failed] {
  border-color: rgba(248, 113, 113, 0.55);
  background: var(--danger-bg);
  color: #fecaca;
}

.btn-secondary[data-failed] .icon-copy {
  display: none;
}

.btn-secondary[data-failed] .icon-error {
  display: block;
  color: var(--danger);
}

/* Status tip: always in accessibility tree, toggled via opacity */
.status-tip {
  position: absolute;
  inset-block-end: calc(100% + 8px);
  inset-inline-start: 50%;
  transform: translateX(-50%) translateY(4px);
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  background: #0b162d;
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 10;
}

.btn-secondary[data-copied] + .status-tip,
.btn-secondary[data-failed] + .status-tip {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.btn-secondary[data-copied] + .status-tip {
  border-color: rgba(74, 222, 128, 0.5);
  color: #bbf7d0;
}

.btn-secondary[data-failed] + .status-tip {
  border-color: rgba(248, 113, 113, 0.5);
  color: #fecaca;
}

.action-hint {
  margin: -4px 2px 0;
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.action-hint kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-primary);
}

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

.canvas-frame {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 12px;
  border-radius: 20px;
  background: linear-gradient(160deg, rgba(225, 181, 121, 0.12), rgba(14, 26, 51, 0.65));
  border: 1px solid var(--border);
  box-shadow: 0 28px 60px rgba(2, 6, 16, 0.6);
}

#post-canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(760px, calc(100dvh - 150px));
  border-radius: 10px;
  background: #0d1933;
}

.preview-footer {
  display: flex;
  justify-content: center;
}

@media (max-width: 959px) {
  .app-header {
    padding: 14px 16px 8px;
  }

  .workspace {
    padding: 8px 16px 24px;
  }

  .preview-panel {
    order: -1;
  }

  #post-canvas {
    max-height: 62dvh;
  }
}

@media (max-width: 480px) {
  .actions-bar,
  .align-grid {
    grid-template-columns: 1fr;
  }

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }

  .btn:active {
    transform: none;
  }

  .status-tip {
    transform: translateX(-50%);
  }
}
