:root {
  --bg-body: #f5f7fa;
  --bg-secondary: #ffffff;
  --bg-subtle: #edf6fb;
  --bg-field: #ffffff;
  --text-main: #102a43;
  --text-muted: #486581;
  --accent-primary: #0096c7;
  --accent-secondary: #7209b7;
  --accent-pop: #f72585;
  --border-color: #dceefb;
  --card-bg: #ffffff;
  --shadow: 0 18px 45px rgba(16, 42, 67, 0.1);
  --focus: 0 0 0 3px rgba(0, 150, 199, 0.2);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg-body: #0b0f29;
  --bg-secondary: #151934;
  --bg-subtle: #101a3d;
  --bg-field: #0f1530;
  --text-main: #e0ffff;
  --text-muted: #a8d0e6;
  --accent-primary: #4cc9f0;
  --accent-secondary: #7209b7;
  --accent-pop: #f72585;
  --border-color: rgba(255, 255, 255, 0.12);
  --card-bg: #151934;
  --shadow: 0 22px 55px rgba(0, 0, 0, 0.28);
  --focus: 0 0 0 3px rgba(76, 201, 240, 0.24);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg-body);
  color: var(--text-main);
  font-family: Roboto, Arial, Helvetica, sans-serif;
}

button,
textarea,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.workspace {
  min-height: calc(100vh - 44px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  min-height: 78px;
  padding: 14px 18px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-secondary);
  box-shadow: var(--shadow);
}

.brand-lockup {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 16px;
}

.brand-logo {
  width: 78px;
  height: auto;
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-primary);
  font-family: "Roboto Condensed", "Arial Narrow", Arial, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  color: var(--text-main);
  font-family: "Roboto Condensed", "Arial Narrow", Arial, sans-serif;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(2rem, 3.6vw, 3.7rem);
  line-height: 0.92;
}

h2 {
  font-size: 1rem;
  line-height: 1.2;
}

.topbar-actions {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.topbar-prefs {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  transition: color 160ms ease, background 160ms ease;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  color: var(--accent-primary);
}

.icon-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.icon-btn .icon-sun,
.icon-btn .icon-moon {
  display: none;
}

:root[data-theme="light"] .icon-btn .icon-moon,
:root[data-theme="dark"] .icon-btn .icon-sun {
  display: block;
}

.topbar-divider {
  width: 1px;
  height: 24px;
  margin: 0 4px;
  background: var(--border-color);
}

.lang-pill {
  min-height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  transition:
    background 160ms ease,
    color 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.lang-pill:hover {
  background: var(--accent-secondary);
  border-color: var(--accent-secondary);
  color: #ffffff;
}

.lang-pill.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.lang-pill.active:hover {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.platform-switch {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(86px, 1fr));
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-field);
}

.segmented,
.text-btn,
.primary-btn,
.tool-btn {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 4px;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease,
    box-shadow 160ms ease;
}

.segmented {
  padding: 0 12px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.segmented.active {
  background: var(--accent-primary);
  color: #061122;
}

:root[data-theme="light"] .segmented.active {
  color: #ffffff;
}

.editor-grid {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(310px, 1.08fr) minmax(280px, 0.72fr) minmax(310px, 1.08fr) minmax(300px, 0.92fr);
  gap: 16px;
  align-items: stretch;
}

.panel,
.preview-card {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--card-bg);
  box-shadow: var(--shadow);
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 16px;
  gap: 14px;
}

.panel-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading.compact {
  align-items: center;
}

.counter,
.local-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.local-badge {
  color: var(--accent-primary);
}

textarea {
  width: 100%;
  min-height: 320px;
  flex: 1;
  resize: none;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 14px;
  background: var(--bg-field);
  color: var(--text-main);
  line-height: 1.55;
  outline: none;
}

textarea::placeholder,
input::placeholder {
  color: var(--text-muted);
  opacity: 0.78;
}

textarea:focus,
select:focus,
input:focus {
  border-color: var(--accent-primary);
  box-shadow: var(--focus);
}

.toolbar,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tool-btn {
  width: 42px;
  padding: 0;
  background: var(--bg-subtle);
  color: var(--text-main);
  font-family: "Roboto Condensed", "Arial Narrow", Arial, sans-serif;
  font-weight: 700;
}

.tool-btn:hover,
.text-btn:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  transform: translateY(-1px);
}

.mark-tool {
  display: none;
}

body.allow-marks .mark-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.text-btn,
.primary-btn {
  padding: 0 14px;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.text-btn {
  background: transparent;
  color: var(--text-main);
  border-color: var(--border-color);
}

.text-btn.ghost {
  color: var(--text-muted);
}

.primary-btn {
  background: var(--accent-pop);
  color: #ffffff;
  border-color: var(--accent-pop);
}

.primary-btn:hover {
  box-shadow: 0 10px 24px rgba(247, 37, 133, 0.24);
  transform: translateY(-1px);
}

.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-field);
}

.switch-row span {
  display: grid;
  gap: 2px;
}

.switch-row strong {
  color: var(--text-main);
  font-size: 0.9rem;
  text-transform: uppercase;
}

input[type="checkbox"] {
  width: 44px;
  height: 24px;
  appearance: none;
  flex: 0 0 auto;
  border-radius: 999px;
  background: rgba(127, 147, 167, 0.38);
  position: relative;
  outline: none;
  transition: background 160ms ease;
}

input[type="checkbox"]::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(3, 9, 19, 0.28);
  transition: transform 160ms ease;
}

input[type="checkbox"]:checked {
  background: var(--accent-primary);
}

input[type="checkbox"]:checked::after {
  transform: translateX(20px);
}

.field {
  display: grid;
  gap: 7px;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

select,
input[type="url"] {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-field);
  color: var(--text-main);
  padding: 0 12px;
  outline: none;
}

.readability {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}

.meter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.86rem;
}

.meter-row strong {
  color: var(--text-main);
}

.meter-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(127, 147, 167, 0.28);
}

.meter-track span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary), var(--accent-pop));
  transition: width 180ms ease;
}

#checksList {
  display: grid;
  gap: 6px;
  min-height: 70px;
  margin: 0;
  padding-left: 18px;
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

#checksList li {
  list-style: disc;
}

.preview-column {
  display: grid;
  grid-template-rows: minmax(320px, 1fr);
  min-height: 0;
}

.preview-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 18px;
}

.preview-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
}

.avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-pop), var(--accent-primary));
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 700;
}

.preview-header p {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 0.86rem;
}

#previewText {
  flex: 1;
  min-height: 0;
  overflow: auto;
  margin: 0;
  padding: 16px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.98rem;
  line-height: 1.58;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(340px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 4px;
  background: var(--accent-pop);
  color: #ffffff;
  box-shadow: 0 18px 36px rgba(3, 9, 19, 0.25);
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 180ms ease,
    opacity 180ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1240px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .editor-grid {
    grid-template-columns: minmax(320px, 1fr) minmax(280px, 0.8fr);
  }

  .output-panel {
    order: 3;
  }

  .preview-column {
    order: 4;
  }
}

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

  .workspace {
    min-height: calc(100vh - 24px);
  }

  .topbar {
    padding: 14px;
  }

  .brand-lockup {
    align-items: flex-start;
  }

  .brand-logo {
    width: 58px;
  }

  h1 {
    font-size: 2rem;
  }

  .topbar-actions,
  .platform-switch,
  .editor-grid {
    width: 100%;
  }

  .topbar-prefs {
    justify-content: flex-end;
    flex-wrap: wrap;
  }

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

  .segmented {
    padding: 0 8px;
    font-size: 0.76rem;
  }

  .editor-grid {
    grid-template-columns: 1fr;
  }

  textarea {
    min-height: 280px;
  }

  .switch-row {
    align-items: start;
  }

  .preview-column {
    grid-template-rows: auto auto;
  }
}
