:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --link-color: #06c;
  --link-hover: #004f9e;
  color: #1d1d1f;
  background: #fff;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body.control-page {
  margin: 0;
  min-height: 100vh;
  background: #fff;
  color: #1d1d1f;
}

.control-page .site-header {
  width: 100%;
  border-bottom: 1px solid #e5e5ea;
  background: rgba(255, 255, 255, 0.92);
}

.control-page .site-header-inner,
.control-page .control-footer {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
}

.control-page .site-header-inner {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.control-page .home-link,
.control-page .site-nav a {
  color: #86868b;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
}

.control-page .home-link,
.control-page .site-nav a:hover,
.control-page .site-nav a[aria-current="page"] {
  color: #1d1d1f;
}

.control-page .site-nav {
  display: flex;
  align-items: center;
  gap: 22px;
}

.control-page main {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 64px;
}

.control-page input,
.control-page button {
  font: inherit;
  letter-spacing: 0;
}

.control-page button {
  appearance: none;
  min-height: 38px;
  border: 1px solid #cececa;
  border-radius: 5px;
  background: #fff;
  color: #1d1d1f;
  padding: 0 12px;
  cursor: pointer;
}

.control-page button:hover:not(:disabled) { border-color: #777774; }
.control-page button:disabled { background: #eeeeeb; color: #999995; cursor: default; }
.control-page button.primary,
.control-page button.selected { color: #fff; border-color: #222; background: #222; }

.control-page button.swatch {
  color: inherit;
  background: var(--swatch);
}

.control-page button.swatch.selected {
  color: inherit;
  border-color: #1d1d1f;
  background: var(--swatch);
  box-shadow: 0 0 0 2px #1d1d1f, inset 0 0 0 1px rgba(255, 255, 255, 0.42);
}

.app-header {
  padding: 0 0 28px;
}

.app-identity {
  min-width: 0;
}

.app-identity strong {
  display: block;
  font-size: 32px;
  font-weight: 600;
  line-height: 1.15;
}

.app-subtitle {
  margin: 10px 0 0;
  color: #86868b;
  font-size: 15px;
  line-height: 1.45;
}

.device-stage {
  padding: 16px 0 12px;
}

.device-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.device-heading h2 {
  margin: 0;
  color: #555558;
  font-size: 13px;
  font-weight: 600;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #6e6e6b;
  font-size: 13px;
  white-space: nowrap;
}

.connection::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: #aaa9a5;
}

.connection.online { color: #187443; }
.connection.online::before { background: #199247; }
.connection.error { color: #a9362e; }
.connection.error::before { background: #c0342b; }

.pair-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.pair-form input {
  width: 100%;
  height: 42px;
  min-width: 0;
  border: 1px solid #cececa;
  border-radius: 5px;
  background: #fff;
  padding: 0 12px;
  outline: none;
  text-transform: uppercase;
}

.pair-form input:focus { border-color: #666663; }

.paired-device {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 42px;
  padding: 3px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.paired-summary { min-width: 0; }

.paired-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.paired-name {
  display: block;
  overflow: hidden;
  color: #1d1d1f;
  font-size: 15px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-inline-message {
  overflow: hidden;
  color: #777773;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.paired-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
}

.control-page button.unpair {
  min-height: 32px;
  border-color: transparent;
  background: transparent;
  color: #777773;
  font-size: 13px;
  padding: 0 4px;
}

.control-page button.unpair:hover:not(:disabled) { color: #a9362e; border-color: transparent; }

.pair-message {
  min-height: 18px;
  margin: 9px 0 0;
  color: #777773;
  font-size: 13px;
  line-height: 1.45;
}

.paired-device:not([hidden]) ~ .pair-message { display: none; }

.global-backlight {
  display: flex;
  align-items: center;
  gap: 22px;
  margin-top: 4px;
  padding: 16px 18px;
  border-top: 1px solid #deded9;
  border-bottom: 1px solid #deded9;
  background: #fbfbfd;
}

.global-backlight .section-heading { flex: 0 0 auto; margin: 0; }
.global-backlight .section-heading h2 { font-size: 14px; }

.backlight-toolbar {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  gap: 11px;
  min-width: 0;
  white-space: nowrap;
}

.backlight-toolbar .swatches { flex: 0 0 auto; }
.backlight-toolbar .backlight-brightness {
  display: flex;
  align-items: center;
  flex: 0 0 190px;
  gap: 8px;
  min-width: 0;
}

.backlight-calibration-toggle {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 5px;
  color: #5c5c58;
  cursor: pointer;
  font-size: 12px;
}

.backlight-calibration-toggle input,
.pet-toggle input,
.screenshot-backlight-toggle input {
  appearance: none;
  position: relative;
  width: 34px;
  height: 20px;
  flex: 0 0 34px;
  margin: 0;
  border: 0;
  border-radius: 999px;
  background: #c7c7cc;
  cursor: pointer;
  transition: background-color 140ms ease;
}

.backlight-calibration-toggle input::after,
.pet-toggle input::after,
.screenshot-backlight-toggle input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.22);
  transition: transform 140ms ease;
}

.backlight-calibration-toggle input:checked,
.pet-toggle input:checked,
.screenshot-backlight-toggle input:checked { background: #34c759; }

.backlight-calibration-toggle input:checked::after,
.pet-toggle input:checked::after,
.screenshot-backlight-toggle input:checked::after { transform: translateX(14px); }

.backlight-calibration-toggle input:disabled,
.pet-toggle input:disabled,
.screenshot-backlight-toggle input:disabled { cursor: default; opacity: 0.48; }

.backlight-toolbar #restore-backlight { margin-left: auto; }

.backlight-brightness .brightness-label,
.backlight-brightness .brightness-value {
  color: #6e6e6b;
  font-size: 12px;
}

.backlight-brightness .brightness-value {
  width: 24px;
  text-align: right;
}

.backlight-brightness input[type="range"] { flex: 1 1 auto; min-width: 0; }

.screenshot-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.screenshot-format { display: inline-flex; gap: 6px; }
.screenshot-format button { min-height: 32px; font-size: 12px; padding: 0 10px; }

.screenshot-backlight-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #5c5c58;
  cursor: pointer;
  font-size: 13px;
}

.section-status { color: #777773; font-size: 13px; }

.text-action {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  color: var(--link-color);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.text-action:hover { color: var(--link-hover); }

.screenshot-preview {
  width: min(100%, 460px);
  margin-top: 18px;
  padding: 10px;
  border: 1px solid #d6d6d1;
  background: #101116;
}

.screenshot-preview img { display: block; width: 100%; height: auto; image-rendering: pixelated; }

.pet-toggle {
  display: inline-flex;
  align-items: center;
  width: auto;
  min-height: 28px;
  gap: 8px;
  color: #3f3f3c;
  cursor: pointer;
  font-size: 14px;
}

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

.setting-label {
  display: block;
  margin-bottom: 9px;
  color: #6e6e6b;
  font-size: 13px;
}

.weather-location-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

.weather-location-row input {
  min-width: 0;
  height: 38px;
  border: 1px solid #cececa;
  border-radius: 5px;
  background: #fff;
  padding: 0 10px;
  outline: none;
}

.weather-location-row input:focus { border-color: #777774; }

.train-sign-grid {
  display: grid;
  grid-template-columns: 1fr 72px 1fr 1fr auto;
  gap: 8px;
  align-items: end;
}

.train-sign-grid label {
  display: grid;
  gap: 7px;
  color: #6e6e6b;
  font-size: 13px;
}

.train-sign-grid input {
  min-width: 0;
  height: 38px;
  border: 1px solid #cececa;
  border-radius: 5px;
  background: #fff;
  padding: 0 10px;
  outline: none;
}

.train-sign-grid input:focus { border-color: #777774; }

.city-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.app-tabs {
  display: flex;
  gap: 26px;
  height: 53px;
  margin-top: 22px;
  border-bottom: 1px solid #deded9;
}

.control-page button.app-tab {
  position: relative;
  min-height: 53px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #777773;
  padding: 0;
  font-size: 14px;
  font-weight: 600;
}

.control-page button.app-tab:hover:not(:disabled) { border: 0; color: #1d1d1f; }

.control-page button.app-tab.selected {
  border: 0;
  background: transparent;
  color: #1d1d1f;
}

.control-page button.app-tab.selected::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: #1d1d1f;
}

.view-panel { padding-top: 34px; }

.view-intro {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.canvas-view { padding-top: 18px; }

.view-intro h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
}

.view-intro p {
  margin: 0;
  color: #777773;
  font-size: 13px;
}

.feature-section {
  padding: 20px 0 24px;
  border-top: 1px solid #deded9;
}

.feature-section:first-of-type { border-top: 0; padding-top: 0; }

.section-heading { margin-bottom: 14px; }

.section-heading h2,
.controls section h2 {
  margin: 0;
  color: #4f4f4c;
  font-size: 14px;
  font-weight: 650;
}

.section-heading p,
.section-help {
  margin: 5px 0 0;
  color: #858581;
  font-size: 12px;
  line-height: 1.5;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.control-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 36px;
  border-top: 1px solid #deded9;
}

.control-columns .feature-section { border-top: 0; padding-top: 22px; }

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.control-footer {
  padding: 40px 0 60px;
  text-align: center;
  border-top: 1px solid #e5e5ea;
}

.control-footer .footer-links {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.control-footer .footer-links a {
  color: #515154;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}

.control-footer .footer-links a:hover { color: var(--link-color); }

.control-footer p {
  margin: 0;
  color: #86868b;
  font-size: 12px;
}

@media (max-width: 720px) {
  .control-page main { width: min(100% - 32px, 560px); padding-top: 30px; }
  .app-header { padding-bottom: 24px; }
  .app-identity strong { font-size: 28px; }
  .app-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .control-columns { grid-template-columns: 1fr; gap: 0; }
  .control-columns .feature-section + .feature-section { border-top: 1px solid #deded9; }
  .view-panel { padding-top: 28px; }
  .view-intro { display: block; }
  .view-intro p { margin-top: 6px; }
  .global-backlight { display: block; padding: 14px; }
  .global-backlight .section-heading { margin-bottom: 12px; }
  .backlight-toolbar { flex-wrap: wrap; gap: 10px; white-space: normal; }
  .backlight-toolbar .swatches { flex-basis: 100%; }
  .backlight-toolbar .backlight-brightness { flex: 1 1 190px; }
  .backlight-toolbar #restore-backlight { margin-left: 0; }
  .settings-columns { grid-template-columns: 1fr; gap: 18px; }
  .train-sign-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .train-sign-grid button { grid-column: 1 / -1; justify-self: start; }
  .city-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 420px) {
  .app-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pair-form { grid-template-columns: minmax(0, 1fr) auto; }
  .pair-form button { padding: 0 10px; }
  .paired-actions { gap: 9px; }
  .paired-actions .connection { display: none; }
  .weather-location-row { grid-template-columns: minmax(0, 1fr) auto; }
  .weather-location-row button:last-child { grid-column: 1 / -1; }
  .train-sign-grid { grid-template-columns: 1fr; }
}
